[libgweather] timezone: Add a method to get a timezone by ID
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] timezone: Add a method to get a timezone by ID
- Date: Wed, 23 Oct 2013 15:18:02 +0000 (UTC)
commit 6445973c7e8020717651c189913b07f4e3972bd5
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Oct 22 16:59:57 2013 -0400
timezone: Add a method to get a timezone by ID
libgweather/gweather-timezone.c | 37 +++++++++++++++++++++++++++++++++----
libgweather/gweather-timezone.h | 1 +
2 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/libgweather/gweather-timezone.c b/libgweather/gweather-timezone.c
index cb09009..c6c8b33 100644
--- a/libgweather/gweather-timezone.c
+++ b/libgweather/gweather-timezone.c
@@ -35,10 +35,9 @@
*
* A timezone.
*
- * There are no public methods for creating timezones; they can only
- * be created by calling gweather_location_new_world() to parse
- * Locations.xml, and then calling various #GWeatherLocation methods
- * to extract relevant timezones from the location hierarchy.
+ * Timezones are global to the #GWeatherWorld; they can be gotten
+ * by passing gweather_timezone_get_by_tzid() with a tzid like
+ * "America/New_York" or "Europe/London".
*/
struct _GWeatherTimezone {
@@ -150,6 +149,29 @@ parse_tzdata (const char *tzname, time_t start, time_t end,
return TRUE;
}
+static GHashTable *timezones = NULL;
+
+/**
+ * gweather_timezone_get_by_tzid:
+ * @tzid: A timezone identifier, like "America/New_York" or "Europe/London"
+ *
+ * Get the #GWeatherTimezone for @tzid.
+ *
+ * Returns: (transfer none): A #GWeatherTimezone. This object
+ * belongs to GWeather, do not unref it.
+ */
+GWeatherTimezone *
+gweather_timezone_get_by_tzid (const char *tzid)
+{
+ /* ensure that the database has been loaded and parsed */
+ gweather_location_get_world ();
+
+ if (timezones == NULL)
+ return NULL;
+
+ return g_hash_table_lookup (timezones, tzid);
+}
+
static GWeatherTimezone *
parse_timezone (GWeatherParser *parser)
{
@@ -197,6 +219,13 @@ parse_timezone (GWeatherParser *parser)
zone->has_dst = has_dst;
zone->dst_offset = dst_offset;
+ if (timezones == NULL)
+ timezones = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, /* key owned by zone */
+ (GDestroyNotify) gweather_timezone_unref);
+
+ g_hash_table_insert (timezones, zone->id, zone);
+
name = NULL;
}
diff --git a/libgweather/gweather-timezone.h b/libgweather/gweather-timezone.h
index 220223a..42f9c4b 100644
--- a/libgweather/gweather-timezone.h
+++ b/libgweather/gweather-timezone.h
@@ -44,6 +44,7 @@ GWeatherTimezone *gweather_timezone_ref (GWeatherTimezone *zone);
void gweather_timezone_unref (GWeatherTimezone *zone);
GWeatherTimezone *gweather_timezone_get_utc (void);
+GWeatherTimezone *gweather_timezone_get_by_tzid (const char *tzid);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]