diff options
author | Tobias Markmann <tm@ayena.de> | 2016-07-29 20:59:54 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-08-09 20:15:12 (GMT) |
commit | 42defb3516a8b7f06c7b0fbc832332a4e60c0f86 (patch) | |
tree | b833bc3cf0166947da16345be511b71dcb04baca /Swift/QtUI/QtTranslator.h | |
parent | 3c7b2b3dc884f347771f6e3036779193e7e45627 (diff) | |
download | swift-42defb3516a8b7f06c7b0fbc832332a4e60c0f86.zip swift-42defb3516a8b7f06c7b0fbc832332a4e60c0f86.tar.bz2 |
Enable better date formatting in the UI
This adds the ability to provide more specific date formatting
via the Translator interface. The default translator will use
Boost's formatting capabilities. The QtTranslator use more
localized and better readable formatting.
Test-Information:
Tested with Qt 5.5.1 on OS X 10.11.6. Checked that tooltips
and presence text in new chat views show the new formatting.
Change-Id: I90ff5ab8b31fb41f2dcbea2c40b8846c534c355f
Diffstat (limited to 'Swift/QtUI/QtTranslator.h')
-rw-r--r-- | Swift/QtUI/QtTranslator.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Swift/QtUI/QtTranslator.h b/Swift/QtUI/QtTranslator.h index cdb259f..92abf77 100644 --- a/Swift/QtUI/QtTranslator.h +++ b/Swift/QtUI/QtTranslator.h @@ -7,9 +7,12 @@ #pragma once #include <QCoreApplication> +#include <QDateTime> #include <Swift/Controllers/Translator.h> +#include <Swift/QtUI/QtSwiftUtil.h> + class QtTranslator : public Swift::Translator { public: QtTranslator() { @@ -22,4 +25,13 @@ class QtTranslator : public Swift::Translator { return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0, QCoreApplication::UnicodeUTF8).toUtf8()); #endif } + + virtual std::string ptimeToHumanReadableString(const boost::posix_time::ptime& time) { + return Q2PSTRING(QDateTime::fromTime_t(posixTimeToTimeT(time)).toString(Qt::SystemLocaleLongDate)); + } + + private: + static std::time_t posixTimeToTimeT(boost::posix_time::ptime pt) { + return std::time_t((pt - boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_seconds()); + } }; |