Merge lp:~charlesk/indicator-datetime/fiz-tz-offset into lp:indicator-datetime/0.4

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 169
Merged at revision: 170
Proposed branch: lp:~charlesk/indicator-datetime/fiz-tz-offset
Merge into: lp:indicator-datetime/0.4
Diff against target: 74 lines (+11/-8)
1 file modified
src/datetime-service.c (+11/-8)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/fiz-tz-offset
Reviewer Review Type Date Requested Status
Allison Karlitskaya (community) Approve
Review via email: mp+100460@code.launchpad.net

Description of the change

Fix a timezone sorting issue reported by seb128 and diagnosed by desrt

To post a comment you must log in.
Revision history for this message
Allison Karlitskaya (desrt) wrote :

This looks better indeed.

review: Approve
Revision history for this message
Allison Karlitskaya (desrt) wrote :

The 'const' on the time_t on argument list is odd. I'd tweak that before committing.

Revision history for this message
Charles Kerr (charlesk) wrote :

Done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/datetime-service.c'
2--- src/datetime-service.c 2012-03-27 18:31:20 +0000
3+++ src/datetime-service.c 2012-04-02 16:02:33 +0000
4@@ -108,7 +108,7 @@
5 };
6
7 /**
8- * A temp struct used by update_location_menu_items() for pruning duplicates.
9+ * A temp struct used by update_location_menu_items() for pruning duplicates and sorting.
10 */
11 struct TimeLocation
12 {
13@@ -124,14 +124,16 @@
14 g_free (loc);
15 }
16 static struct TimeLocation*
17-time_location_new (const char * zone, const char * name)
18+time_location_new (const char * zone, const char * name, const time_t now)
19 {
20 struct TimeLocation * loc = g_new (struct TimeLocation, 1);
21 GTimeZone * tz = g_time_zone_new (zone);
22- loc->offset = g_time_zone_get_offset (tz, 0);
23+ gint interval = g_time_zone_find_interval (tz, G_TIME_TYPE_UNIVERSAL, now);
24+ loc->offset = g_time_zone_get_offset (tz, interval);
25 loc->zone = g_strdup (zone);
26 loc->name = g_strdup (name);
27 g_time_zone_unref (tz);
28+ g_debug ("%s zone '%s' name '%s' offset is %d", G_STRLOC, zone, name, (int)loc->offset);
29 return loc;
30 }
31 static int
32@@ -146,9 +148,9 @@
33 return ret;
34 }
35 static GSList*
36-locations_add (GSList * locations, const char * zone, const char * name)
37+locations_add (GSList * locations, const char * zone, const char * name, time_t now)
38 {
39- struct TimeLocation * loc = time_location_new (zone, name);
40+ struct TimeLocation * loc = time_location_new (zone, name, now);
41
42 if (g_slist_find_custom (locations, loc, (GCompareFunc)time_location_compare) == NULL) {
43 g_debug ("%s Adding zone '%s', name '%s'", G_STRLOC, zone, name);
44@@ -182,18 +184,19 @@
45 ***/
46
47 GSList * locations = NULL;
48+ const time_t now = time(NULL);
49
50 /* maybe add geo_timezone */
51 if (geo_timezone != NULL) {
52 gchar * name = get_current_zone_name (geo_timezone);
53- locations = locations_add (locations, geo_timezone, name);
54+ locations = locations_add (locations, geo_timezone, name, now);
55 g_free (name);
56 }
57
58 /* maybe add current_timezone */
59 if (current_timezone != NULL) {
60 gchar * name = get_current_zone_name (current_timezone);
61- locations = locations_add (locations, current_timezone, name);
62+ locations = locations_add (locations, current_timezone, name, now);
63 g_free (name);
64 }
65
66@@ -207,7 +210,7 @@
67 gchar * zone;
68 gchar * name;
69 split_settings_location (user_locations[i], &zone, &name);
70- locations = locations_add (locations, zone, name);
71+ locations = locations_add (locations, zone, name, now);
72 g_free (name);
73 g_free (zone);
74 }

Subscribers

People subscribed via source and target branches