aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-27 12:04:54 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-27 12:07:47 -0700
commita8a9deb262dfe9af158e0faefabc4166d310d1b9 (patch)
tree075dc6536257747289a83253ef95462d9c761b22
parente88f37d3278c74052e122457498de244b1c73d60 (diff)
downloadsubsurface-a8a9deb262dfe9af158e0faefabc4166d310d1b9.tar.gz
Better date localization
Instead on relying on the translators to correctly format date and time we should be able to get all we need from QLocale. Sadly this takes a bit of hacky post-processing, but in my limited testing the results look good. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-gui.cpp35
1 files changed, 17 insertions, 18 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index 52b26febd..eeb43b899 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -29,7 +29,6 @@
#include <QSettings>
#include <QDesktopWidget>
#include <QStyle>
-#include <QDebug>
#include <QMap>
#include <QMultiMap>
#include <QNetworkProxy>
@@ -48,6 +47,9 @@ static MainWindow *window = NULL;
int error_count;
const char *existing_filename;
+static QString shortDateFormat;
+static QString dateFormat;
+static QString timeFormat;
#if defined(Q_OS_WIN) && QT_VERSION < 0x050000
static QByteArray encodeUtf8(const QString &fname)
@@ -88,6 +90,14 @@ QString uiLanguage(QLocale *callerLoc)
if (callerLoc)
*callerLoc = loc;
+ // the short format is fine
+ // the long format uses long weekday and month names, so replace those with the short ones
+ // for time we don't want the time zone designator and don't want leading zeroes on the hours
+ shortDateFormat = loc.dateFormat(QLocale::ShortFormat);
+ dateFormat = loc.dateFormat(QLocale::LongFormat);
+ dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM");
+ timeFormat = loc.timeFormat();
+ timeFormat.replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H");
return uiLang;
}
@@ -380,27 +390,16 @@ int parseTemperatureToMkelvin(const QString &text)
QString get_dive_date_string(timestamp_t when)
{
- struct tm tm;
- utc_mkdate(when, &tm);
- return translate("gettextFromC", "%1, %2 %3, %4 %5:%6")
- .arg(weekday(tm.tm_wday))
- .arg(monthname(tm.tm_mon))
- .arg(tm.tm_mday)
- .arg(tm.tm_year + 1900)
- .arg(tm.tm_hour, 2, 10, QChar('0'))
- .arg(tm.tm_min, 2, 10, QChar('0'));
+ QDateTime ts;
+ ts.setMSecsSinceEpoch(when * 1000);
+ return ts.toUTC().toString(dateFormat + " " + timeFormat);
}
QString get_short_dive_date_string(timestamp_t when)
{
- struct tm tm;
- utc_mkdate(when, &tm);
- return translate("gettextFromC", "%1 %2, %3\n%4:%5")
- .arg(monthname(tm.tm_mon))
- .arg(tm.tm_mday)
- .arg(tm.tm_year + 1900)
- .arg(tm.tm_hour, 2, 10, QChar('0'))
- .arg(tm.tm_min, 2, 10, QChar('0'));
+ QDateTime ts;
+ ts.setMSecsSinceEpoch(when * 1000);
+ return ts.toUTC().toString(shortDateFormat + " " + timeFormat);
}
QString get_trip_date_string(timestamp_t when, int nr)