* If the user has not selected a time format, make a guess about 12 hour or 24 hour...
authorArt Cancro <ajc@citadel.org>
Wed, 21 Jan 2009 05:08:17 +0000 (05:08 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 21 Jan 2009 05:08:17 +0000 (05:08 +0000)
webcit/fmt_date.c
webcit/webcit.h

index 50afb580885b2ad106cc174ce4788fd71da4c542..ff895f20ec6cdaba4b8d0a0228215506a3021c91 100644 (file)
@@ -92,6 +92,21 @@ void webcit_fmt_date(char *buf, time_t thetime, int brief)
 }
 
 
+/* 
+ * 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.
  */
@@ -102,7 +117,16 @@ int get_time_format_cached (void)
        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
index 66456fe42daa98d9c7ce3065d31115f6714d949c..ea9ed2a3aa8397d4bc62e64f3c8e478ea7288c56 100644 (file)
@@ -689,6 +689,7 @@ void tabbed_dialog(int num_tabs, char *tabnames[]);
 void begin_tab(int tabnum, int num_tabs);
 void end_tab(int tabnum, int num_tabs);
 void str_wiki_index(char *s);
+long guess_calhourformat(void);
 int get_time_format_cached (void);
 int xtoi(const char *in, size_t len);
 const char *get_selected_language(void);