aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/CMakeLists.txt1
-rw-r--r--main/meson.build1
-rw-r--r--main/src/ui/util/helper.vala12
3 files changed, 10 insertions, 4 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 5cc1a8bf..a4cd0465 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -115,6 +115,7 @@ compile_gresources(
unset(MAIN_EXTRA_OPTIONS)
unset(MAIN_EXTRA_PACKAGES)
set(MAIN_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi)
+set(MAIN_EXTRA_PACKAGES posix)
set(MAIN_DEFINITIONS)
if(GTK4_VERSION VERSION_GREATER_EQUAL "4.6")
diff --git a/main/meson.build b/main/meson.build
index 8096551f..11aecf32 100644
--- a/main/meson.build
+++ b/main/meson.build
@@ -10,6 +10,7 @@ dependencies = [
dep_m,
dep_qlite,
dep_xmpp_vala,
+ meson.get_compiler('vala').find_library('posix'),
]
sources = files(
'src/main.vala',
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;
}