[gnome-panel] clock: fix timezone usage
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] clock: fix timezone usage
- Date: Wed, 2 Mar 2022 18:31:57 +0000 (UTC)
commit 76f892ce2baf32e922dead9ce517bfcf11ae9d65
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Mar 2 14:12:23 2022 +0200
clock: fix timezone usage
Before commit cd1a0db671b6 clock_location_get_timezone returned
timezone identifier and clock_location_get_tzname returned timezone
abbreviation.
This commit replaces timezone identifier with timezone abbreviation
in calendar popup window and restores timezone identifier in
preferences dialog.
modules/clock/clock-applet.c | 2 +-
modules/clock/clock-location-tile.c | 23 +++++---------
modules/clock/clock-location.c | 62 +++++++++++++++++++++++--------------
modules/clock/clock-location.h | 5 +--
4 files changed, 49 insertions(+), 43 deletions(-)
---
diff --git a/modules/clock/clock-applet.c b/modules/clock/clock-applet.c
index 51ab62d79..99a1daa11 100644
--- a/modules/clock/clock-applet.c
+++ b/modules/clock/clock-applet.c
@@ -445,7 +445,7 @@ create_cities_store (ClockApplet *cd)
gtk_list_store_set (cd->cities_store, &iter,
COL_CITY_NAME, clock_location_get_name (loc),
/* FIXME: translate the timezone */
- COL_CITY_TZ, clock_location_get_timezone (loc),
+ COL_CITY_TZ, clock_location_get_timezone_identifier (loc),
COL_CITY_LOC, loc,
-1);
diff --git a/modules/clock/clock-location-tile.c b/modules/clock/clock-location-tile.c
index e4de503bd..dff2c6100 100644
--- a/modules/clock/clock-location-tile.c
+++ b/modules/clock/clock-location-tile.c
@@ -483,10 +483,11 @@ format_time (GDateTime *now,
}
static char *
-convert_time_to_str (time_t now, GDesktopClockFormat clock_format, const char *timezone)
+convert_time_to_str (time_t now,
+ GDesktopClockFormat clock_format,
+ GTimeZone *timezone)
{
const gchar *format;
- GTimeZone *tz;
GDateTime *utc, *local;
char *ret;
@@ -505,23 +506,13 @@ convert_time_to_str (time_t now, GDesktopClockFormat clock_format, const char *t
format = _("%H:%M");
}
- tz = g_time_zone_new_identifier (timezone);
-
- if (tz == NULL) {
- g_warning ("Invalid timezone identifier - %s, falling back to UTC!",
- timezone);
-
- tz = g_time_zone_new_utc ();
- }
-
utc = g_date_time_new_from_unix_utc (now);
- local = g_date_time_to_timezone (utc, tz);
+ local = g_date_time_to_timezone (utc, timezone);
ret = g_date_time_format (local, format);
g_date_time_unref (utc);
g_date_time_unref (local);
- g_time_zone_unref (tz);
return ret;
}
@@ -562,7 +553,7 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
}
now = clock_location_localtime (priv->location);
- tzname = clock_location_get_tzname (priv->location);
+ tzname = clock_location_get_timezone_abbreviation (priv->location);
if (priv->last_refresh)
g_date_time_unref (priv->last_refresh);
@@ -597,7 +588,7 @@ weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTool
const gchar *icon_name;
time_t sunrise_time, sunset_time;
gchar *sunrise_str, *sunset_str;
- const char *timezone;
+ GTimeZone *timezone;
gdouble unused;
GWeatherWindDirection unused2;
@@ -636,7 +627,7 @@ weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTool
else
line3 = g_strdup ("");
- timezone = clock_location_get_tzname (location);
+ timezone = clock_location_get_timezone (location);
if (gweather_info_get_value_sunrise (info, &sunrise_time))
sunrise_str = convert_time_to_str (sunrise_time, clock_format, timezone);
else
diff --git a/modules/clock/clock-location.c b/modules/clock/clock-location.c
index 7496f16a2..99ffd7af7 100644
--- a/modules/clock/clock-location.c
+++ b/modules/clock/clock-location.c
@@ -28,6 +28,7 @@ struct _ClockLocationPrivate {
GWeatherLocation *loc;
GWeatherTimezone *wtz;
+ GTimeZone *tz;
gdouble latitude;
gdouble longitude;
@@ -116,6 +117,7 @@ clock_location_new (GnomeWallClock *wall_clock,
{
ClockLocation *this;
ClockLocationPrivate *priv;
+ const char *tzid;
this = g_object_new (CLOCK_LOCATION_TYPE, NULL);
priv = this->priv;
@@ -140,6 +142,16 @@ clock_location_new (GnomeWallClock *wall_clock,
priv->wtz = get_gweather_timezone (this);
+ tzid = gweather_timezone_get_tzid (priv->wtz);
+ priv->tz = g_time_zone_new_identifier (tzid);
+
+ if (priv->tz == NULL) {
+ g_warning ("Invalid timezone identifier - %s, falling back to UTC!",
+ tzid);
+
+ priv->tz = g_time_zone_new_utc ();
+ }
+
setup_weather_updates (this);
return this;
@@ -223,6 +235,7 @@ clock_location_finalize (GObject *g_obj)
gweather_location_unref (priv->loc);
gweather_timezone_unref (priv->wtz);
+ g_time_zone_unref (priv->tz);
if (priv->weather_timeout)
g_source_remove (priv->weather_timeout);
@@ -262,16 +275,34 @@ clock_location_get_city (ClockLocation *loc)
return gweather_location_get_city_name (loc->priv->loc);
}
-const gchar *
-clock_location_get_timezone (ClockLocation *loc)
+GTimeZone *
+clock_location_get_timezone (ClockLocation *self)
{
- return gweather_timezone_get_name (loc->priv->wtz);
+ return self->priv->tz;
}
-const gchar *
-clock_location_get_tzname (ClockLocation *loc)
+const char *
+clock_location_get_timezone_identifier (ClockLocation *self)
{
- return gweather_timezone_get_tzid (loc->priv->wtz);
+ return g_time_zone_get_identifier (self->priv->tz);
+}
+
+const char *
+clock_location_get_timezone_abbreviation (ClockLocation *self)
+{
+ GDateTime *dt;
+ gint64 now;
+ int interval;
+
+ dt = g_date_time_new_now_local ();
+ now = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
+
+ interval = g_time_zone_find_interval (self->priv->tz,
+ G_TIME_TYPE_STANDARD,
+ now);
+
+ return g_time_zone_get_abbreviation (self->priv->tz, interval);
}
void
@@ -286,24 +317,7 @@ clock_location_get_coords (ClockLocation *loc,
GDateTime *
clock_location_localtime (ClockLocation *loc)
{
- const char *tzid;
- GTimeZone *tz;
- GDateTime *dt;
-
- tzid = gweather_timezone_get_tzid (loc->priv->wtz);
- tz = g_time_zone_new_identifier (tzid);
-
- if (tz == NULL) {
- g_warning ("Invalid timezone identifier - %s, falling back to UTC!",
- tzid);
-
- tz = g_time_zone_new_utc ();
- }
-
- dt = g_date_time_new_now (tz);
- g_time_zone_unref (tz);
-
- return dt;
+ return g_date_time_new_now (loc->priv->tz);
}
gboolean
diff --git a/modules/clock/clock-location.h b/modules/clock/clock-location.h
index b632beda3..678169164 100644
--- a/modules/clock/clock-location.h
+++ b/modules/clock/clock-location.h
@@ -44,13 +44,14 @@ ClockLocation *clock_location_new (GnomeWallClock *wall_clock,
gdouble latitude,
gdouble longitude);
-const gchar *clock_location_get_tzname (ClockLocation *loc);
+GTimeZone *clock_location_get_timezone (ClockLocation *self);
+const char *clock_location_get_timezone_identifier (ClockLocation *self);
+const char *clock_location_get_timezone_abbreviation (ClockLocation *self);
const char *clock_location_get_name (ClockLocation *loc);
void clock_location_set_name (ClockLocation *loc, const gchar *name);
gchar *clock_location_get_city (ClockLocation *loc);
-const gchar *clock_location_get_timezone (ClockLocation *loc);
void clock_location_get_coords (ClockLocation *loc, gdouble *latitude, gdouble *longitude);
GDateTime *clock_location_localtime (ClockLocation *loc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]