if (wc_locales[WC->selected_language] == NULL) {
return strftime(s, max, format, tm);
}
- else { /* TODO: this gives empty strings on debian. */
+ else {
return strftime_l(s, max, format, tm, wc_locales[WC->selected_language]);
}
#else
}
+/*
+ * Try to guess whether the user will prefer 12 hour or 24 hour time based on the locale.
+ */
+long guess_calhourformat(void) {
+ char buf[32];
+ struct tm tm;
+ memset(&tm, 0, sizeof tm);
+ wc_strftime(buf, 32, "%X", &tm);
+ if (buf[strlen(buf)-1] == 'M') {
+ return 12;
+ }
+ return 24;
+}
+
+
/*
* learn the users timeformat preference.
*/
time_format_cache = &(WC->time_format_cache);
if (*time_format_cache == WC_TIMEFORMAT_NONE)
{
- get_pref_long("calhourformat", &calhourformat, 24);
+ get_pref_long("calhourformat", &calhourformat, 99);
+
+ /* If we don't know the user's time format preference yet,
+ * make a guess based on the locale.
+ */
+ if (calhourformat == 99) {
+ calhourformat = guess_calhourformat();
+ }
+
+ /* Now set the preference */
if (calhourformat == 24)
*time_format_cache = WC_TIMEFORMAT_24;
else
hour = hour - 12;
if (time_format == WC_TIMEFORMAT_24) {
- sprintf(buf, "%2d:%02d",
+ sprintf(buf, "%d:%02d",
tm->tm_hour, tm->tm_min
);
}
InitModule_DATETIME
(void)
{
- RegisterPreference(HKEY("calhourformat"), _("Time format"), PRF_INT, LoadTimeformatSettingsCache);
+ RegisterPreference("calhourformat", _("Time format"), PRF_INT, LoadTimeformatSettingsCache);
}