[RFC PATCH]: honor LC_TIME variable (somewhat)

Dirk Hohndel dirk at hohndel.org
Mon Oct 26 18:58:17 PDT 2015


So we had a feature request for a while that stated "allow me to use 24h
time even if I'm using US English" - and I always shied away from it
becuase I didn't want to add more and more preferences, but it occured to
me that there actually is a well defined mechanism to allow people to get
the time format they want. LC_TIME

Currently the way we generate the locale in qthelper.cpp is ignoring
LC_TIME but how about this simple patch:


diff --git a/qthelper.cpp b/qthelper.cpp
index 7e4d64ec8c3b..62e7477040d2 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -744,7 +744,9 @@ QString uiLanguage(QLocale *callerLoc)
 	// special hack for Swedish as our switching from long weekday names to short weekday names
 	// messes things up there
 	dateFormat.replace("'en' 'den' d:'e'", " d");
-	timeFormat = loc.timeFormat();
+	// make sure we get the users preferred time format, independent of the language choice
+	// but then massage it a bit for consistency...
+	timeFormat = QLocale().timeFormat();
 	timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", "");
 	timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", "");
 	return uiLang;


In my limited testing this seems to do exactly what I want. If the user
hasn't set LC_TIME they get their system default time format (which most
likely is what they expect - so for the typical user this is the "low
surprise" solution). But if they (like me) prefer 24h time, they can just
set LC_TIME=de_DE (or some other 24h locale) and still run with LANG=en_US
and get exactly what they want.

I'm sure I'm overlooking unintended consequences of this approach - which
is why this is an RFC and not something I just committed to master :-)

/D


More information about the subsurface mailing list