diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-04-02 10:51:06 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2012-04-02 10:51:06 -0500 |
commit | d89b4e7c18f83eb37e9605d677f7f8d0e3500d3c (patch) | |
tree | e5293296b110b13fbae0022571cd1698e5d7ddbe | |
parent | 249fa0ac6c1394d314cb4e48ed8f12fb0144f00a (diff) | |
download | ayatana-indicator-datetime-d89b4e7c18f83eb37e9605d677f7f8d0e3500d3c.tar.gz ayatana-indicator-datetime-d89b4e7c18f83eb37e9605d677f7f8d0e3500d3c.tar.bz2 ayatana-indicator-datetime-d89b4e7c18f83eb37e9605d677f7f8d0e3500d3c.zip |
fix timezone sorting issue reported by seb128 and diagnosed by desrt
-rw-r--r-- | src/datetime-service.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c index fb95928..57f6f52 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -108,7 +108,7 @@ struct comp_instance { }; /** - * A temp struct used by update_location_menu_items() for pruning duplicates. + * A temp struct used by update_location_menu_items() for pruning duplicates and sorting. */ struct TimeLocation { @@ -124,14 +124,16 @@ time_location_free (struct TimeLocation * loc) g_free (loc); } static struct TimeLocation* -time_location_new (const char * zone, const char * name) +time_location_new (const char * zone, const char * name, const time_t now) { struct TimeLocation * loc = g_new (struct TimeLocation, 1); GTimeZone * tz = g_time_zone_new (zone); - loc->offset = g_time_zone_get_offset (tz, 0); + gint interval = g_time_zone_find_interval (tz, G_TIME_TYPE_UNIVERSAL, now); + loc->offset = g_time_zone_get_offset (tz, interval); loc->zone = g_strdup (zone); loc->name = g_strdup (name); g_time_zone_unref (tz); + g_debug ("%s zone '%s' name '%s' offset is %d", G_STRLOC, zone, name, (int)loc->offset); return loc; } static int @@ -146,9 +148,9 @@ time_location_compare (const struct TimeLocation * a, const struct TimeLocation return ret; } static GSList* -locations_add (GSList * locations, const char * zone, const char * name) +locations_add (GSList * locations, const char * zone, const char * name, time_t now) { - struct TimeLocation * loc = time_location_new (zone, name); + struct TimeLocation * loc = time_location_new (zone, name, now); if (g_slist_find_custom (locations, loc, (GCompareFunc)time_location_compare) == NULL) { g_debug ("%s Adding zone '%s', name '%s'", G_STRLOC, zone, name); @@ -182,18 +184,19 @@ update_location_menu_items (void) ***/ GSList * locations = NULL; + const time_t now = time(NULL); /* maybe add geo_timezone */ if (geo_timezone != NULL) { gchar * name = get_current_zone_name (geo_timezone); - locations = locations_add (locations, geo_timezone, name); + locations = locations_add (locations, geo_timezone, name, now); g_free (name); } /* maybe add current_timezone */ if (current_timezone != NULL) { gchar * name = get_current_zone_name (current_timezone); - locations = locations_add (locations, current_timezone, name); + locations = locations_add (locations, current_timezone, name, now); g_free (name); } @@ -207,7 +210,7 @@ update_location_menu_items (void) gchar * zone; gchar * name; split_settings_location (user_locations[i], &zone, &name); - locations = locations_add (locations, zone, name); + locations = locations_add (locations, zone, name, now); g_free (name); g_free (zone); } |