Skip to content

Conversation

@straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Jul 31, 2025

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:

Resolves #15810

Copy link
Contributor

@ysbaddaden ysbaddaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have support for parsing the format?

@straight-shoota
Copy link
Member Author

Not yet. But that's the follow-up.

ysbaddaden
ysbaddaden previously approved these changes Aug 1, 2025
@straight-shoota straight-shoota added this to the 1.18.0 milestone Aug 1, 2025
@straight-shoota straight-shoota marked this pull request as draft August 4, 2025 08:24
@straight-shoota straight-shoota removed this from the 1.18.0 milestone Aug 4, 2025
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably deprecate with_nanoseconds.

@straight-shoota
Copy link
Member Author

straight-shoota commented Aug 4, 2025

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 Format::RFC3339 formatter, but keeping space as separator instead of T which is harder to make out. RFC3339 explicitly allows that to improve human readability, which is the main purpose of this method.

Copy link
Contributor

@ysbaddaden ysbaddaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@straight-shoota
Copy link
Member Author

Yes, Object#inspect is primarily meant for human consumption. It doesn't hurt to have it machine readable as much as possible, of course. But that's not a strict goal.

Anyways, using a space instead of T between date and time is covered by the specification as far as I understand. It's not the canonical format, but applications are allowed to choose it for readability purposes. I believe the rationale here is that RFC 3339 and IXDTF primarily focus on defining a formal standard format for machine consumption and don't worry too much about readability.
But some allowances are possible when the format is intended for a human audience.

@straight-shoota straight-shoota marked this pull request as ready for review August 5, 2025 20:42
@straight-shoota straight-shoota added this to the 1.18.0 milestone Sep 27, 2025
@straight-shoota straight-shoota merged commit b820665 into crystal-lang:master Sep 29, 2025
39 checks passed
@straight-shoota straight-shoota deleted the feat/time.inspect-location branch September 29, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve format for Time#inspect

2 participants