After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 791066 - Add UTC location
Add UTC location
Status: RESOLVED FIXED
Product: libgweather
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: future
Assigned To: libgweather-maint
libgweather-maint
Depends on:
Blocks: 692243
 
 
Reported: 2017-12-01 10:37 UTC by Bastien Nocera
Modified: 2017-12-06 00:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
location: Fix gir-scanner compile time error (967 bytes, patch)
2017-12-01 10:37 UTC, Bastien Nocera
committed Details | Review
GWeatherLocationEntry: Simplify tree store insertions (3.06 KB, patch)
2017-12-01 10:37 UTC, Bastien Nocera
committed Details | Review
GWeatherLocationEntry: Make single words match (1.24 KB, patch)
2017-12-01 10:37 UTC, Bastien Nocera
committed Details | Review
location: Add helper to create GWeatherLocation struct (1.59 KB, patch)
2017-12-01 10:37 UTC, Bastien Nocera
committed Details | Review
location: Add gweather_location_new_utc() (2.31 KB, patch)
2017-12-01 10:37 UTC, Bastien Nocera
accepted-commit_now Details | Review
location: Add support for deserialising UTC (910 bytes, patch)
2017-12-01 10:37 UTC, Bastien Nocera
accepted-commit_now Details | Review
GWeatherLocationEntry: Build model after object is constructed (4.31 KB, patch)
2017-12-01 10:37 UTC, Bastien Nocera
committed Details | Review
GWeatherLocationEntry: Add show-utc property (3.87 KB, patch)
2017-12-01 10:38 UTC, Bastien Nocera
accepted-commit_now Details | Review
lib: Add test for show-utc property (2.94 KB, patch)
2017-12-01 10:38 UTC, Bastien Nocera
accepted-commit_now Details | Review
Add UTC Clock (3.48 KB, patch)
2017-12-01 10:44 UTC, Bastien Nocera
none Details | Review
location: Add gweather_location_new_virtual() (3.36 KB, patch)
2017-12-04 11:17 UTC, Bastien Nocera
none Details | Review
location: Add support for deserialising virtual locations (1.97 KB, patch)
2017-12-04 11:17 UTC, Bastien Nocera
none Details | Review
GWeatherLocationEntry: Add show-virtual property (3.90 KB, patch)
2017-12-04 11:17 UTC, Bastien Nocera
none Details | Review
lib: Add test for show-virtual property (7.24 KB, patch)
2017-12-04 11:17 UTC, Bastien Nocera
none Details | Review
build: Bump version for new API (561 bytes, patch)
2017-12-04 11:29 UTC, Bastien Nocera
committed Details | Review
GWeatherLocation: add named timezones (5.93 KB, patch)
2017-12-05 17:27 UTC, Giovanni Campagna
committed Details | Review
GWeatherLocationEntry: Add show-named-timezone property (5.54 KB, patch)
2017-12-05 17:27 UTC, Giovanni Campagna
committed Details | Review
lib: Add test for show-virtual property (2.95 KB, patch)
2017-12-05 17:27 UTC, Giovanni Campagna
committed Details | Review
GWeatherLocationEntry: fix matching with parenthesis (1.53 KB, patch)
2017-12-05 17:27 UTC, Giovanni Campagna
committed Details | Review

Description Bastien Nocera 2017-12-01 10:37:07 UTC
.
Comment 1 Bastien Nocera 2017-12-01 10:37:25 UTC
Created attachment 364727 [details] [review]
location: Fix gir-scanner compile time error

libgweather/gweather-location.c:804: Warning: GWeather: gweather_location_detect_nearest_city: invalid return annotation

There's nothing returned from the function, so no need to document
"Returns".
Comment 2 Bastien Nocera 2017-12-01 10:37:30 UTC
Created attachment 364728 [details] [review]
GWeatherLocationEntry: Simplify tree store insertions

There's no need to append to then insert, when we could insert new
values directly.
Comment 3 Bastien Nocera 2017-12-01 10:37:34 UTC
Created attachment 364729 [details] [review]
GWeatherLocationEntry: Make single words match

A single word should really be matching against another single word
string.
Comment 4 Bastien Nocera 2017-12-01 10:37:39 UTC
Created attachment 364730 [details] [review]
location: Add helper to create GWeatherLocation struct
Comment 5 Bastien Nocera 2017-12-01 10:37:44 UTC
Created attachment 364731 [details] [review]
location: Add gweather_location_new_utc()

This creates a new world with a single "UTC" country, which can be used
to search for the UTC virtual timezone using the same code as for
searching through the physical world location.
Comment 6 Bastien Nocera 2017-12-01 10:37:49 UTC
Created attachment 364732 [details] [review]
location: Add support for deserialising UTC
Comment 7 Bastien Nocera 2017-12-01 10:37:55 UTC
Created attachment 364733 [details] [review]
GWeatherLocationEntry: Build model after object is constructed

So that additional construct time properties can be used.
Comment 8 Bastien Nocera 2017-12-01 10:38:01 UTC
Created attachment 364734 [details] [review]
GWeatherLocationEntry: Add show-utc property

To show or not the "UTC" timezone as a location in the completion list.
Comment 9 Bastien Nocera 2017-12-01 10:38:06 UTC
Created attachment 364735 [details] [review]
lib: Add test for show-utc property
Comment 10 Bastien Nocera 2017-12-01 10:44:14 UTC
Created attachment 364736 [details] [review]
Add UTC Clock

Requires a newer libgweather, and some careful stepping around the fact
that there is no weather info for the UTC timezone.
Comment 11 Bastien Nocera 2017-12-01 10:45:17 UTC
Comment on attachment 364736 [details] [review]
Add UTC Clock

Removing that, it's the gnome-clocks patch
Comment 12 Bastien Nocera 2017-12-01 12:16:03 UTC
A couple of things:
- we might want to add some API to allow gnome-clocks to show this clock differently, rather than assume it's always day there.
- I'm not sure I'm creating the GWeatherLocations correctly, we might want them to be boxed objects
- I'm also not sure about the memory management
Comment 13 Emmanuele Bassi (:ebassi) 2017-12-01 12:37:27 UTC
Review of attachment 364727 [details] [review]:

ACK-by: me
Comment 14 Emmanuele Bassi (:ebassi) 2017-12-01 12:37:51 UTC
Review of attachment 364728 [details] [review]:

ACK-by: me
Comment 15 Emmanuele Bassi (:ebassi) 2017-12-01 12:39:16 UTC
Review of attachment 364729 [details] [review]:

::: libgweather/gweather-location-entry.c
@@ +646,3 @@
+    match = match_compare_name (key, local_compare_name) ||
+	    match_compare_name (key, english_compare_name) ||
+	    g_ascii_strcasecmp (key, english_compare_name) == 0;

Looks good, though for future enhancement we may want to use g_str_match_string() from GLib to do substring matches with tokenization and case folding.
Comment 16 Emmanuele Bassi (:ebassi) 2017-12-01 12:39:47 UTC
Review of attachment 364730 [details] [review]:

ACK-by: me
Comment 17 Emmanuele Bassi (:ebassi) 2017-12-01 12:41:11 UTC
Review of attachment 364731 [details] [review]:

Before landing this, there should be a commit bumping up the version of the project. There has been a 3.27.1 release already, and without a version bump it projects won't be able to bump their dependencies accurately.
Comment 18 Emmanuele Bassi (:ebassi) 2017-12-01 12:41:58 UTC
Review of attachment 364732 [details] [review]:

::: libgweather/gweather-location.c
@@ +1363,3 @@
     GWeatherLocation *found;
 
+    if (g_strcmp0 (station_code, "UTC") == 0)

Should this be case insensitive?
Comment 19 Bastien Nocera 2017-12-01 12:44:23 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #18)
> Review of attachment 364732 [details] [review] [review]:
> 
> ::: libgweather/gweather-location.c
> @@ +1363,3 @@
>      GWeatherLocation *found;
>  
> +    if (g_strcmp0 (station_code, "UTC") == 0)
> 
> Should this be case insensitive?

The station code is the same one we create in gweather_location_new_utc() serialised to gsettings, then deserialised, so it should be exactly this.
Comment 20 Emmanuele Bassi (:ebassi) 2017-12-01 12:44:29 UTC
Review of attachment 364733 [details] [review]:

ACK-by: me
Comment 21 Emmanuele Bassi (:ebassi) 2017-12-01 12:45:26 UTC
Review of attachment 364734 [details] [review]:

ACK-by: me
Comment 22 Emmanuele Bassi (:ebassi) 2017-12-01 12:46:00 UTC
Review of attachment 364735 [details] [review]:

It would be nice to turn all these interactive tests into unit tests
Comment 23 Emmanuele Bassi (:ebassi) 2017-12-01 12:47:25 UTC
(In reply to Bastien Nocera from comment #19)
> (In reply to Emmanuele Bassi (:ebassi) from comment #18)
> > Review of attachment 364732 [details] [review] [review] [review]:
> > 
> > ::: libgweather/gweather-location.c
> > @@ +1363,3 @@
> >      GWeatherLocation *found;
> >  
> > +    if (g_strcmp0 (station_code, "UTC") == 0)
> > 
> > Should this be case insensitive?
> 
> The station code is the same one we create in gweather_location_new_utc()
> serialised to gsettings, then deserialised, so it should be exactly this.

Okay, so: ACK-by: me.
Comment 24 Giovanni Campagna 2017-12-01 17:16:57 UTC
I've said it before, and I'll say it again. I don't like this.

UTC is not a location. It does not have coordinates. It does not have a weather station code. It does not have a parent city or country (hence no country code). Basically none of the GWeatherLocation APIs work, except get_timezones().

UTC does not make sense to show in GWeatherLocationEntry for 2/3 of the users of GWeatherLocationEntry, hence the hack of a show-utc property.

What we need is a GWeatherTimezoneEntry, replacing GWeatherTimezoneMenu with search, and returning GWeatherTimezones. Then gnome-clocks can stop abusing the location entry, we get other timezone abbreviations for free, and this whole problem is over.
Comment 25 Giovanni Campagna 2017-12-03 18:46:57 UTC
Also, if UTC is added, then one might wonder why not Anywhere on Earth (which is just as useful), at which point one realizes that this special-case approach does not really scale.
Comment 26 Bastien Nocera 2017-12-04 01:09:00 UTC
(In reply to Giovanni Campagna from comment #25)
> Also, if UTC is added, then one might wonder why not Anywhere on Earth
> (which is just as useful), at which point one realizes that this
> special-case approach does not really scale.

A couple of reasons:
- It's a calendar day, not a time. "For this day, this is the Anywhere on Earth time for it in that timezone". It would need a very different UI in gnome-clocks.
- It's the first time I ever hear of it, and it's the first time anyone has ever mentioned it in a gnome-clocks or libgweather bug:
https://bugzilla.gnome.org/buglist.cgi?longdesc=anywhere%20on%20earth&longdesc_type=allwordssubstr&product=gnome-clocks&product=libgweather&query_format=advanced

Nobody has asked for UTC+X or UTC-X timezones either, and their naming would make it really hard to integrate (UTC+5 is UTC minus 5 hours, see "TZ=UTC+5 date", yay POSIX timezones!).

If you have better ideas about the API, please let me know, but I think we're solving the use case people care about. I could certainly try to make the GWeatherLocation changes more generic, returning a "virtual world" rather than a single location.

I'm holding off on pushing the patches because I want to try and see what test cases I can create to ensure I don't introduce more refcounting problems.
Comment 27 Giovanni Campagna 2017-12-04 02:39:21 UTC
(In reply to Bastien Nocera from comment #26)
> (In reply to Giovanni Campagna from comment #25)
> > Also, if UTC is added, then one might wonder why not Anywhere on Earth
> > (which is just as useful), at which point one realizes that this
> > special-case approach does not really scale.
> 
> A couple of reasons:
> - It's a calendar day, not a time. "For this day, this is the Anywhere on
> Earth time for it in that timezone". It would need a very different UI in
> gnome-clocks.

Isn't that the the same clocks UI?
Like, when I need AoE time (which is usually around deadlines) I want to know what time it is in AoE, and how many hours are there to midnight.
AoE is a timezone afterall.

You can also flip it and say, "when is midnight AoE in my timezone", but that pretty much applies to any timezone anyway, so it would be a UI issue in Clocks, not a libgweather problem. E.g, I've seen conference deadlines at all possible times, sometime in PDT, EST, HAST.
What's more, is that the posted deadline will use the timezone name or abbreviation, which means that you really want to search for the timezone in the entry.

> - It's the first time I ever hear of it, and it's the first time anyone has
> ever mentioned it in a gnome-clocks or libgweather bug:
> https://bugzilla.gnome.org/buglist.
> cgi?longdesc=anywhere%20on%20earth&longdesc_type=allwordssubstr&product=gnome
> -clocks&product=libgweather&query_format=advanced
> 
> Nobody has asked for UTC+X or UTC-X timezones either, and their naming would
> make it really hard to integrate (UTC+5 is UTC minus 5 hours, see "TZ=UTC+5
> date", yay POSIX timezones!).

POSIX timezones don't really matter here; we can decide that UTC-X means UTC minus X hours like it should.
OTOH I would expect people will ask for Pacific/Mountain/Central/Eastern Times, because at least in the US that's how timezones are referred to, rather than a representative city.

> 
> If you have better ideas about the API, please let me know, but I think
> we're solving the use case people care about. I could certainly try to make
> the GWeatherLocation changes more generic, returning a "virtual world"
> rather than a single location.

The better API, as I suggested two comments ago (and previously in the Clocks bug), is a GWeatherTimezoneEntry, that does not touch GWeatherLocations at all. 


It's worth also mentioning that Clocks shows the sunrise/sunset times for a city, which don't make sense for UTC or any of the timezones, which means Clocks will need to special case UTC and it gains nothing by reusing GWeatherLocation.
Comment 28 Bastien Nocera 2017-12-04 09:47:29 UTC
(In reply to Giovanni Campagna from comment #27)
> (In reply to Bastien Nocera from comment #26)
> > (In reply to Giovanni Campagna from comment #25)
> > > Also, if UTC is added, then one might wonder why not Anywhere on Earth
> > > (which is just as useful), at which point one realizes that this
> > > special-case approach does not really scale.
> > 
> > A couple of reasons:
> > - It's a calendar day, not a time. "For this day, this is the Anywhere on
> > Earth time for it in that timezone". It would need a very different UI in
> > gnome-clocks.
> 
> Isn't that the the same clocks UI?
> Like, when I need AoE time (which is usually around deadlines) I want to
> know what time it is in AoE, and how many hours are there to midnight.
> AoE is a timezone afterall.
> 
> You can also flip it and say, "when is midnight AoE in my timezone", but
> that pretty much applies to any timezone anyway, so it would be a UI issue
> in Clocks, not a libgweather problem. E.g, I've seen conference deadlines at
> all possible times, sometime in PDT, EST, HAST.
> What's more, is that the posted deadline will use the timezone name or
> abbreviation, which means that you really want to search for the timezone in
> the entry.

Fair enough. But still, nobody's ever asked for it, or even mentioned it before. I don't think it's fair to be expected to add features nobody's ever asked for.

> > - It's the first time I ever hear of it, and it's the first time anyone has
> > ever mentioned it in a gnome-clocks or libgweather bug:
> > https://bugzilla.gnome.org/buglist.
> > cgi?longdesc=anywhere%20on%20earth&longdesc_type=allwordssubstr&product=gnome
> > -clocks&product=libgweather&query_format=advanced
> > 
> > Nobody has asked for UTC+X or UTC-X timezones either, and their naming would
> > make it really hard to integrate (UTC+5 is UTC minus 5 hours, see "TZ=UTC+5
> > date", yay POSIX timezones!).
> 
> POSIX timezones don't really matter here; we can decide that UTC-X means UTC
> minus X hours like it should.
> OTOH I would expect people will ask for Pacific/Mountain/Central/Eastern
> Times, because at least in the US that's how timezones are referred to,
> rather than a representative city.

There's nothing stopping us from making the timezones something we can search for in GWeatherLocationEntry.

> > If you have better ideas about the API, please let me know, but I think
> > we're solving the use case people care about. I could certainly try to make
> > the GWeatherLocation changes more generic, returning a "virtual world"
> > rather than a single location.
> 
> The better API, as I suggested two comments ago (and previously in the
> Clocks bug), is a GWeatherTimezoneEntry, that does not touch
> GWeatherLocations at all. 

I don't think that this makes for appealing UI, having 2 separate entries. Users will expect to be able to enter UTC (or anything else) into the one entry, and have completion work as expected.

> It's worth also mentioning that Clocks shows the sunrise/sunset times for a
> city, which don't make sense for UTC or any of the timezones, which means
> Clocks will need to special case UTC and it gains nothing by reusing
> GWeatherLocation.

Already done, it's in the gnome-clocks patch.
Comment 29 Bastien Nocera 2017-12-04 10:20:30 UTC
Attachment 364727 [details] pushed as b1cb7dc - location: Fix gir-scanner compile time error
Attachment 364728 [details] pushed as 0d400ec - GWeatherLocationEntry: Simplify tree store insertions
Attachment 364730 [details] pushed as 2083210 - location: Add helper to create GWeatherLocation struct
Attachment 364733 [details] pushed as 8060e45 - GWeatherLocationEntry: Build model after object is constructed
Comment 30 Bastien Nocera 2017-12-04 10:26:58 UTC
I pushed all the cleanup patches in the set, as those shouldn't be too controversial.

(In reply to Emmanuele Bassi (:ebassi) from comment #15)
> Review of attachment 364729 [details] [review] [review]:
> 
> ::: libgweather/gweather-location-entry.c
> @@ +646,3 @@
> +    match = match_compare_name (key, local_compare_name) ||
> +	    match_compare_name (key, english_compare_name) ||
> +	    g_ascii_strcasecmp (key, english_compare_name) == 0;
> 
> Looks good, though for future enhancement we may want to use
> g_str_match_string() from GLib to do substring matches with tokenization and
> case folding.

Filed as https://bugzilla.gnome.org/show_bug.cgi?id=791198
Comment 31 Bastien Nocera 2017-12-04 11:17:09 UTC
Created attachment 364898 [details] [review]
location: Add gweather_location_new_virtual()

This creates a new world with a single "UTC" entry, which can be used
to search for the UTC virtual timezone using the same code as for
searching through the physical world location.

This can also be extended to include more virtual locations as needed in
front-ends.
Comment 32 Bastien Nocera 2017-12-04 11:17:15 UTC
Created attachment 364899 [details] [review]
location: Add support for deserialising virtual locations
Comment 33 Bastien Nocera 2017-12-04 11:17:21 UTC
Created attachment 364900 [details] [review]
GWeatherLocationEntry: Add show-virtual property

To show or not virtual locations, such as the "UTC" timezone as
a location in the completion list.
Comment 34 Bastien Nocera 2017-12-04 11:17:27 UTC
Created attachment 364901 [details] [review]
lib: Add test for show-virtual property
Comment 35 Bastien Nocera 2017-12-04 11:20:18 UTC
I turned the single "utc" location into a world of virtual locations containing a single entry. This would make it extensible if you wanted to add "Anywhere on Earth" support, or another virtual location.

For timezones, I think that making the entry autocomplete on timezone names might be the better option.
Comment 36 Bastien Nocera 2017-12-04 11:29:31 UTC
Created attachment 364903 [details] [review]
build: Bump version for new API
Comment 37 Giovanni Campagna 2017-12-05 17:27:00 UTC
Created attachment 365050 [details] [review]
GWeatherLocation: add named timezones

Named timezones represent things like UTC, which are locations
enough that some apps want them in a GWeatherLocationEntry, but not
not quite cities or weather stations.

They are stored in Locations.xml as usual, as children of the world
location.
Comment 38 Giovanni Campagna 2017-12-05 17:27:07 UTC
Created attachment 365051 [details] [review]
GWeatherLocationEntry: Add show-named-timezone property

To show or not named timezone locations, such as the "UTC" timezone as
a location in the completion list.

Based on a patch by Bastien Nocera <hadess@hadess.net>
Comment 39 Giovanni Campagna 2017-12-05 17:27:15 UTC
Created attachment 365052 [details] [review]
lib: Add test for show-virtual property
Comment 40 Giovanni Campagna 2017-12-05 17:27:20 UTC
Created attachment 365053 [details] [review]
GWeatherLocationEntry: fix matching with parenthesis

Treat ( as the start of a new "subname" for the location, like ","
does
Comment 41 Giovanni Campagna 2017-12-05 17:28:49 UTC
This is a counterproposal.
It requires less new API than yours, which is more future proof.
It is more extensible to new location (one database addition instead of code changes).
It puts the location translations in the right place.

What do you think?
Comment 42 Bastien Nocera 2017-12-05 21:46:01 UTC
Review of attachment 365050 [details] [review]:

Looks fine otherwise.

::: libgweather/gweather-location.c
@@ +1341,3 @@
     candidates = g_hash_table_lookup (world->metar_code_cache, station_code);
 
+    /* A station code beginning with @ indicates a named timezone entry, just

I don't find this very elegant, and it's not verified in the DTD.
Comment 43 Bastien Nocera 2017-12-05 21:47:23 UTC
Review of attachment 365051 [details] [review]:

>  Add show-named-timezone property

timezones

> To show or not named timezone locations

Whether to
Comment 44 Bastien Nocera 2017-12-05 21:48:03 UTC
Review of attachment 365052 [details] [review]:

Sure.
Comment 45 Bastien Nocera 2017-12-05 21:49:38 UTC
Review of attachment 365053 [details] [review]:

This really doesn't end up making it more readable :/
Comment 46 Bastien Nocera 2017-12-05 21:51:42 UTC
Apart from nits and the "@" prefix which I find weird (we could just as well have it prefixed with "TZ:" and use the POSIX name for the timezone, no?), looks good.
Comment 47 Giovanni Campagna 2017-12-05 21:54:29 UTC
(In reply to Bastien Nocera from comment #42)
> Review of attachment 365050 [details] [review] [review]:
> 
> Looks fine otherwise.
> 
> ::: libgweather/gweather-location.c
> @@ +1341,3 @@
>      candidates = g_hash_table_lookup (world->metar_code_cache,
> station_code);
>  
> +    /* A station code beginning with @ indicates a named timezone entry,
> just
> 
> I don't find this very elegant, and it's not verified in the DTD.

I agree it's not as elegant as it could be.
It's better than just using UTC as the station code though, cause at least you know that no ICAO code can start with @.
(Any other non-alphabetic character would do. TZ: would also do because of the colon, but then it's not as convenient)

As for the DTD, that's the limitation of DTDs. XMLSchema would be able to validate that, but I don't really want to write an XML Schema.
Comment 48 Bastien Nocera 2017-12-05 21:59:18 UTC
Then I'm fine with it if you're fine with it.
Comment 49 Bastien Nocera 2017-12-06 00:50:15 UTC
Attachment 364729 [details] pushed as 2d9cf10 - GWeatherLocationEntry: Make single words match
Attachment 364901 [details] pushed as 2e34a45 - lib: Add test for show-virtual property
Attachment 364903 [details] pushed as e2cb8a9 - build: Bump version for new API
Attachment 365050 [details] pushed as cd8464f - GWeatherLocation: add named timezones
Attachment 365052 [details] pushed as 2e34a45 - lib: Add test for show-virtual property
Attachment 365053 [details] pushed as 8a5d5bb - GWeatherLocationEntry: fix matching with parenthesis