From 5ce86704099f64e37627914c6fcaf72ac786fc88 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 Jan 2009 05:08:17 +0000 Subject: [PATCH] * If the user has not selected a time format, make a guess about 12 hour or 24 hour format based on the locale. If strftime('%X') contains the letter 'M' then we go with 12 hour format; otherwise 24 hour. --- webcit/fmt_date.c | 26 +++++++++++++++++++++++++- webcit/webcit.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 50afb5808..ff895f20e 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -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 diff --git a/webcit/webcit.h b/webcit/webcit.h index 66456fe42..ea9ed2a3a 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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); -- 2.30.2