aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2025-03-11 13:53:58 +0100
committerMarvin W <git@larma.de>2025-04-04 20:14:45 +0200
commit4b1be6f88f9043f6d7829c397bcba88639b8491f (patch)
treeb0d5cc163c25f89a683ed68322225f07f816a6db /main/src/ui
parentb979436069f83c7e722354fe244da698dce0d40e (diff)
Improve 24h time format detection
Diffstat (limited to 'main/src/ui')
-rw-r--r--main/src/ui/util/helper.vala12
1 files changed, 8 insertions, 4 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 578e313a..60e0e81c 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -134,12 +134,16 @@ public static bool is_dark_theme(Gtk.Widget widget) {
return (bg.red > 0.5 && bg.green > 0.5 && bg.blue > 0.5);
}
-private static uint8 is24h = 0;
+private static int8 is24h = 0;
public static bool is_24h_format() {
if (is24h == 0) {
- string p_format = " "; // Leaving room to be filled by strftime
- Time.local(0).strftime((char[]) p_format.data, "%p");
- is24h = p_format.strip() == "" ? 1 : -1;
+ Regex has_ampm = /(^|[^%])%[pP]/;
+ Regex has_t_fmt_ampm = /(^|[^%])%r/;
+ unowned string t_fmt = Posix.nl_langinfo(Posix.NLItem.T_FMT);
+ unowned string t_fmt_ampm = Posix.nl_langinfo(Posix.NLItem.T_FMT_AMPM);
+ bool has_am_str = Posix.nl_langinfo(Posix.NLItem.AM_STR).strip() != "";
+ bool has_pm_str = Posix.nl_langinfo(Posix.NLItem.PM_STR).strip() != "";
+ is24h = ((has_ampm.match(t_fmt) || has_t_fmt_ampm.match(t_fmt) && has_ampm.match(t_fmt_ampm)) && (has_am_str || has_pm_str)) ? -1 : 1;
}
return is24h == 1;
}