GNOME Bugzilla – Bug 707151
gdatetime: Extend the '%z' timezone format
Last modified: 2013-08-31 11:46:59 UTC
Currently it's only possible to format the timezone offset in a very rigid way, g_date_time_format() only supports the +-XXXX format with %z, which for my timezone is +0200. It would be nice to be able to also get +02:00 or even just +2. date(1) from coreutils has some strftime extensions for %z which would be nice to have in glib as well.
Created attachment 253650 [details] [review] gdatetime: Extend the '%z' timezone format Implement the date(1) strftime extension for the '%z' numeric timezone format: %z +hhmm numeric time zone (e.g., -0400) %:z +hh:mm numeric time zone (e.g., -04:00) %::z +hh:mm:ss numeric time zone (e.g., -04:00:00) %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
Some more digging revealed that the extended %z format is a gnulib extension that date(1) supports.
Created attachment 253654 [details] [review] gdatetime: Extend the '%z' timezone format Implement gnulib strftime extensions for the '%z' numeric timezone format. These are also supported and documented by GNU date(1): %z +hhmm numeric time zone (e.g., -0400) %:z +hh:mm numeric time zone (e.g., -04:00) %::z +hh:mm:ss numeric time zone (e.g., -04:00:00) %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
Created attachment 253655 [details] [review] Add tests for new '%z' g_date_time_format extensions
Review of attachment 253654 [details] [review]: Would be good to add a "Since 2.38", feel free to push with that addition
Review of attachment 253655 [details] [review]: sure
Thanks for the reviews! I've added 'Since: 2.38' to the docs and an additional test for the 0 offset. The new test caught an issue with %:::z which I've fixed up as well. Attachment 253654 [details] pushed as 8fd7f58 - gdatetime: Extend the '%z' timezone format Attachment 253655 [details] pushed as 8d62c24 - Add tests for new '%z' g_date_time_format extensions