ISO8601DateFormatter does not allow for decimal fractions of smallest time component.

Originator:oliver.foggin
Number:rdar://34430629 Date Originated:14/09/17
Status:Open Resolved:
Product:iOS SDK - Foundation Product Version:iOS 10+
Classification:Suggestion Reproducible:Always
 
As per this website... https://www.cl.cam.ac.uk/~mgk25/iso-time.html ... and Wiki and various other references for the ISO8601 date format...

"It is also possible to add fractions of a second after a decimal dot or comma, for instance the time 5.8 ms before midnight can be written as 23:59:59.9942 or 235959.9942"

The actual standard is that a fraction can be added to the smallest of the time component included in the format. So three and a half minutes past 1 pm can be indicated with a time format of `13:03.5` (using a comma or full stop for the decimal point).

The ISO8601DateFormatter added in iOS10 does not include an option to customise the decimal part of the format and so for many commonly used web formats... `yyyyMMddTHH:mm:ss.SSSSZ` cannot be converted into a Date using the ISO8601DateFormatter and instead returns `nil`.

In order to conform to the ISO8601 standard this should be added.

The standard says that the number of decimals is not set as part of the standard and should be agreed between the writers and consumers of the API.

So, not only should the fraction of the smallest time component be part of the `ISO8601DateFormatter.Options` (with a name something like `withFractionalTime`) but it should also allow for the configuration of the number of decimal places required.

Thanks

Comments

Jon, mine was also closed as a dupe of the same ticket. There is now an Option withFractionalSeconds in the docs. But it has no comments against it.

I wonder how you can select the number of decimal places?

By oliver.foggin at Oct. 23, 2017, 8:50 a.m. (reply...)

Added comment to original radar...

Just wanted to add an additional note. The docs for withInternetDateTime say "The format used for internet date times, according to the RFC 3339 standard.". This is also not true. The RFC 3339 standard section 5.1 mentions the use of fractional second digits and so allows the use of the ISO8601 fractional digits mentioned earlier.

By oliver.foggin at Oct. 23, 2017, 8:48 a.m. (reply...)

I reported this as 27689420 and it was closed as a dupe of 24532185.

Very stupid this still isn't fixed.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!