summaryrefslogtreecommitdiff
path: root/src/nautilus-ui-utilities.c
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2020-09-18 00:21:06 +0100
committerAntónio Fernandes <antoniof@gnome.org>2020-09-19 21:26:38 +0100
commit455faecb9172803056583bb9ad8e9d6d7c9897e7 (patch)
tree2d50fd44b8a1320ce7219be0cb6deea02ced27ab /src/nautilus-ui-utilities.c
parent3cdc56c44bf497a7ba91251b26c4685469e7dbba (diff)
downloadnautilus-wip/antoniof/nobody-changes-timezone-that-fast.tar.gz
general: Rate limit local time zone readswip/antoniof/nobody-changes-timezone-that-fast
Diffstat (limited to 'src/nautilus-ui-utilities.c')
-rw-r--r--src/nautilus-ui-utilities.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 195f765f9..670ebc33a 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -268,6 +268,36 @@ get_text_for_date_range (GPtrArray *date_range,
return label;
}
+#define TIME_ZONE_RATE_LIMIT 2000000
+
+GTimeZone *
+nautilus_get_time_zone (void)
+{
+ static GTimeZone *cached_time_zone = NULL;
+ static gint64 last_read_time = 0;
+ gint64 current_time;
+
+ current_time = g_get_monotonic_time ();
+
+ if (g_once_init_enter (&last_read_time))
+ {
+ cached_time_zone = g_time_zone_new_local ();
+ g_once_init_leave (&last_read_time, current_time);
+ }
+
+ if (current_time - last_read_time > TIME_ZONE_RATE_LIMIT)
+ {
+ GTimeZone *old_time_zone = cached_time_zone;
+
+ last_read_time = current_time;
+ cached_time_zone = g_time_zone_new_local ();
+
+ g_time_zone_unref (old_time_zone);
+ }
+
+ return g_time_zone_ref (cached_time_zone);
+}
+
GtkDialog *
show_dialog (const gchar *primary_text,
const gchar *secondary_text,