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 537637 - Extended API for g_time_val_from_iso8601()/g_time_val_to_iso8601()
Extended API for g_time_val_from_iso8601()/g_time_val_to_iso8601()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.16.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-06-10 17:37 UTC by Peter Kjellerstedt
Modified: 2011-11-18 04:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Document exactly what g_time_val_to_iso8601() produces (1.89 KB, patch)
2011-10-18 10:14 UTC, Simon McVittie
accepted-commit_now Details | Review
Document exactly what g_time_val_to_iso8601() produces (1.89 KB, patch)
2011-11-18 04:11 UTC, Matthias Clasen
committed Details | Review

Description Peter Kjellerstedt 2008-06-10 17:37:16 UTC
The API for g_time_val_from_iso8601() and g_time_val_to_iso8601() is a bit limited. The former always supports both yyyy-mm-ddThh:mm:ss.ffffff+hh:mm and yyyymmddThhmmss.ffffff+hhmm, whereas the latter only supports yyyy-mm-ddThh:mm:ss.ffffffZ. In our application I would like to only support yyyymmddThhmmss.ffffffZ in both cases. And I can easily envision situations where one does not want to support fractions of a second. 

Thus I would like to suggest an extended API which takes an additional flag field to determine what is allowed, e.g., G_ISO8601_BASIC_FORMAT, G_ISO8601_EXTENDED_FORMAT, G_ISO8601_FRACTIONS, G_ISO8601_ZULU_ONLY. It might also be of interest to be able to get/set the time zone with an additional argument.
Comment 1 Dan Winship 2008-06-10 23:43:44 UTC
The problem is, there are like 17,000 variant ISO 8601 timestamp formats, and for the most part, everyone who doesn't like the default g_time_val_to_iso8601() output is going to want a *different* variant. So you'd need a ridiculous number of flags. (Eg, XML-RPC specifies that there should be punctuation in the time part, but not the date part, which doesn't match any of your flags.)

Also, if you have a struct tm or equivalent, it's trivial to generate exactly the ISO 8610 format you want with just a g_strdup_printf, since you don't need to do any sort of string lookups or anything.
Comment 2 Matthias Clasen 2008-06-16 14:00:23 UTC
In any case, the docs for these functions needs to go into much more detail about the exact format they are dealing with.
Comment 3 Simon McVittie 2011-10-18 10:13:08 UTC
(In reply to comment #0)
> g_time_val_from_iso8601() [...]
> supports both yyyy-mm-ddThh:mm:ss.ffffff+hh:mm and
> yyyymmddThhmmss.ffffff+hhmm

This is quite a small subset of ISO 8601, which allows truncation at any position, week numbers, day numbers (2011-02-01 = 2011-032 (32nd day of 2011)), and all sorts of other oddities.

I briefly thought this was actually W3C NOTE-datetime <http://www.w3.org/TR/1998/NOTE-datetime-19980827>, but in fact they're different subsets of ISO 8601 (and neither is a subset of the other, even).

> g_time_val_to_iso8601() [...] only supports
> yyyy-mm-ddThh:mm:ss.ffffffZ.

This is RFC 3339 format with optional fractional seconds, and the UTC timezone represented as Z. If we're going to pick one format and say "use this if you don't have a reason not to", I think this should be it.

Even RFC 3339 has a few options, though (see Bug #662060).
Comment 4 Simon McVittie 2011-10-18 10:14:52 UTC
Created attachment 199316 [details] [review]
Document exactly what g_time_val_to_iso8601() produces

---

How's this?
Comment 5 Peter Kjellerstedt 2011-11-02 17:36:04 UTC
I find the suggested update to the documentation a good improvement. That way you at least know what to expect.
Comment 6 Dan Winship 2011-11-02 19:09:47 UTC
Comment on attachment 199316 [details] [review]
Document exactly what g_time_val_to_iso8601() produces

yeah
Comment 7 Matthias Clasen 2011-11-18 04:11:31 UTC
The following fix has been pushed:
a0c7557 Document exactly what g_time_val_to_iso8601() produces
Comment 8 Matthias Clasen 2011-11-18 04:11:35 UTC
Created attachment 201641 [details] [review]
Document exactly what g_time_val_to_iso8601() produces

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=537637
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>