Line 0
Link Here
|
|
|
1 |
--- glib/gtimezone.c.orig 2018-09-21 12:29:23.000000000 +0300 |
2 |
+++ glib/gtimezone.c 2019-09-12 00:53:42.760936000 +0300 |
3 |
@@ -37,6 +37,7 @@ |
4 |
#include "gslice.h" |
5 |
#include "gdatetime.h" |
6 |
#include "gdate.h" |
7 |
+#include "genviron.h" |
8 |
|
9 |
#ifdef G_OS_WIN32 |
10 |
#define STRICT |
11 |
@@ -187,6 +188,8 @@ struct _GTimeZone |
12 |
|
13 |
G_LOCK_DEFINE_STATIC (time_zones); |
14 |
static GHashTable/*<string?, GTimeZone>*/ *time_zones; |
15 |
+G_LOCK_DEFINE_STATIC (tz_local); |
16 |
+static GTimeZone *tz_local = NULL; |
17 |
|
18 |
#define MIN_TZYEAR 1916 /* Daylight Savings started in WWI */ |
19 |
#define MAX_TZYEAR 2999 /* And it's not likely ever to go away, but |
20 |
@@ -1457,10 +1460,20 @@ g_time_zone_new (const gchar *identifier) |
21 |
* |
22 |
* Since: 2.26 |
23 |
**/ |
24 |
+static gpointer |
25 |
+g_time_zone_utc_init (gpointer data) |
26 |
+{ |
27 |
+ return g_time_zone_new ("UTC"); |
28 |
+} |
29 |
+ |
30 |
GTimeZone * |
31 |
g_time_zone_new_utc (void) |
32 |
{ |
33 |
- return g_time_zone_new ("UTC"); |
34 |
+ static GOnce utc_once = G_ONCE_INIT; |
35 |
+ |
36 |
+ g_once (&utc_once, g_time_zone_utc_init, NULL); |
37 |
+ |
38 |
+ return g_time_zone_ref ((GTimeZone *)utc_once.retval); |
39 |
} |
40 |
|
41 |
/** |
42 |
@@ -1483,7 +1496,23 @@ g_time_zone_new_utc (void) |
43 |
GTimeZone * |
44 |
g_time_zone_new_local (void) |
45 |
{ |
46 |
- return g_time_zone_new (getenv ("TZ")); |
47 |
+ const gchar *tzenv = g_getenv ("TZ"); |
48 |
+ GTimeZone *tz; |
49 |
+ |
50 |
+ G_LOCK (tz_local); |
51 |
+ |
52 |
+ /* Is time zone changed and must be flushed? */ |
53 |
+ if (tz_local && g_strcmp0 (tz_local->name, tzenv)) |
54 |
+ g_clear_pointer (&tz_local, g_time_zone_unref); |
55 |
+ |
56 |
+ if (tz_local == NULL) |
57 |
+ tz_local = g_time_zone_new (tzenv); |
58 |
+ |
59 |
+ tz = g_time_zone_ref (tz_local); |
60 |
+ |
61 |
+ G_UNLOCK (tz_local); |
62 |
+ |
63 |
+ return tz; |
64 |
} |
65 |
|
66 |
#define TRANSITION(n) g_array_index (tz->transitions, Transition, n) |