GNOME Bugzilla – Bug 676923
Create a GTimeZone from an offset
Last modified: 2018-04-13 14:26:30 UTC
It would be useful to be able to create a GTimeZone from an offset instead of having to turn the offset into "+-hh:mm" format.
Do you mean to specify an offset in +-seconds? If you know the offset in hours you can just say "8".
I know that I can just create the string myself for creating the GTimeZone, however it would be nice not having to when simply trying to create one from a known at runtime number of hours and minutes.
I second this. I am looking into migrating GMime from using a time_t & an integer tz_offset to using GDateTime. In fact, I implemented a patch to do just that last night and one of the pain points was that timezones found in Date headers tend to be of the form "+/-####" and my parer was parsing the timezone tokens as int. I modified my code to return a GTimeZone* instead and instead of using my int-parsing logic, used g_time_zone_new() instead and let that do that parsing, but it was a bit annoying because I have to clone the token into a new string buffer as opposed to my code which handled start & end offsets within an existing string (e.g. the string that my code is parsing). Not the end of the world and I normally wouldn't have even bothered filing a feature request, but since one is already ehre, I figured I'd chime in :)
So are we looking for g_time_zone_new_hh_mm_offset(gint hours, guint minutes), g_time_zone_new_sec_offset(gint seconds), both, or something else?
(In reply to John Ralls from comment #4) > So are we looking for g_time_zone_new_hh_mm_offset(gint hours, guint > minutes), > g_time_zone_new_sec_offset(gint seconds), both, or something else? Probably looking for the latter: g_time_zone_new_offset (gint32 seconds) that makes it match g_time_zone_get_offset(), and means it can use the zone_for_constant_offset() code in gtimezone.c as part of the constructor easily. I’m happy to review patches, though any new API would have to be signed off by another GLib maintainer.
Created attachment 370814 [details] [review] gtimezone: Add g_time_zone_new_offset() convenience constructor This includes tests. Signed-off-by: Philip Withnall <withnall@endlessm.com>
Review of attachment 370814 [details] [review]: Cute; okay by me.
Attachment 370814 [details] pushed as cf24867 - gtimezone: Add g_time_zone_new_offset() convenience constructor