Format Time#inspect with Internet Extended Date/Time Format#16039
Format Time#inspect with Internet Extended Date/Time Format#16039straight-shoota merged 13 commits intocrystal-lang:masterfrom
Time#inspect with Internet Extended Date/Time Format#16039Conversation
ysbaddaden
left a comment
There was a problem hiding this comment.
Do we have support for parsing the format?
|
Not yet. But that's the follow-up. |
| it "#inspect" do | ||
| Time.utc(2014, 1, 2, 3, 4, 5).inspect.should eq "2014-01-02 03:04:05.0 UTC" | ||
| Time.utc(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789).inspect.should eq "2014-01-02 03:04:05.123456789 UTC" | ||
| Time.utc(2014, 1, 2, 3, 4, 5).inspect.should eq "2014-01-02 03:04:05Z" |
There was a problem hiding this comment.
thought: Dropping the second fractions entirely when nanoseconds are zero might be debatable. I think it's more readable that way.
But that makes it ambiguous whether nanoseconds were entirely cut off (with_nanoseconds: false) or are just omitted because the subsection fraction is zero. Shortening the fraction to just .0 was more explicit. But I don't think it's that important.
with_nanoseconds: false is a rather odd feature. I'm not aware of any actual use case. It was introduced in #5794 but I don't recall what was the reason for it.
There was a problem hiding this comment.
We should probably deprecate with_nanoseconds.
|
Sorry for the continued editing but I realized that essential parts were missing (documentation) and the exact format could use some polishing for better readability. I have now replaced the implementation with the existing |
There was a problem hiding this comment.
Moving to a RFC or ISO standard format made sense, but not using T for readability reasons makes me wonder about the change because the most readable is the current format (SP TZ > [TZ] and SP UTC > Z).
I guess the question is: is #inspect meant for humans, in which case it must be the best readable, or for machines, in which case a standard format is better.
|
Yes, Anyways, using a space instead of |
Co-authored-by: Julien Portalier <julien@portalier.com>
The Internet Extended Date/Time Format (IXDTF) as described in RFC 9557 is a standard for representing a timestamp together with zone information.
Changes to the format:
UTClocation byZoffsetwith_nanosecondsis true (see FormatTime#inspectwith Internet Extended Date/Time Format #16039 (comment))Resolves #15810