[libgweather] GWeatherLocation: Add API to get timezone as string



commit f84ea7617b5fd778e9b4956cad35798e77764b34
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 6 14:41:56 2017 +0100

    GWeatherLocation: Add API to get timezone as string
    
    Make it possible to get the timezone of a location as a string. This
    will be used to verify the timezone's validity, as _get_timezone() would
    return NULL, whether the location had no timezone, or if it had an
    invalid timezone.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791307

 libgweather/gweather-location.c |   28 ++++++++++++++++++++++++++++
 libgweather/gweather-location.h |    2 ++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index f6addeb..0543729 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -961,6 +961,34 @@ gweather_location_get_timezone (GWeatherLocation *loc)
     return NULL;
 }
 
+/**
+ * gweather_location_get_timezone_str:
+ * @loc: a #GWeatherLocation
+ *
+ * Gets the timezone associated with @loc, if known, as a string.
+ *
+ * The timezone string is owned either by @loc or by one of its
+ * parents, do not free it.
+ *
+ * Return value: (transfer none) (allow-none): @loc's timezone as
+ * a string, or %NULL
+ **/
+const char *
+gweather_location_get_timezone_str (GWeatherLocation *loc)
+{
+    const char *tz_hint;
+
+    g_return_val_if_fail (loc != NULL, NULL);
+
+    while (loc && !loc->tz_hint)
+       loc = loc->parent;
+    if (!loc)
+       return NULL;
+    tz_hint = loc->tz_hint;
+
+    return tz_hint;
+}
+
 static void
 add_timezones (GWeatherLocation *loc, GPtrArray *zones)
 {
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index a5ddb6e..84a3dae 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -113,6 +113,8 @@ const char            *gweather_location_get_country    (GWeatherLocation  *loc)
 GWEATHER_EXTERN
 GWeatherTimezone      *gweather_location_get_timezone   (GWeatherLocation  *loc);
 GWEATHER_EXTERN
+const char            *gweather_location_get_timezone_str (GWeatherLocation *loc);
+GWEATHER_EXTERN
 GWeatherTimezone     **gweather_location_get_timezones  (GWeatherLocation  *loc);
 GWEATHER_EXTERN
 void                   gweather_location_free_timezones (GWeatherLocation  *loc,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]