Skip to content

Commit b820665

Browse files
Format Time#inspect with Internet Extended Date/Time Format (#16039)
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: * Replace `UTC` location by `Z` offset * Skip zero nanoseconds entirely even when `with_nanoseconds` is true (see #16039 (comment)) * Remove whitespace between time and offset * Wrap location in square brackets to indicate an IXDTF time-zone suffix [RFC 9557]: https://datatracker.ietf.org/doc/html/rfc9557 Co-authored-by: Julien Portalier <[email protected]>
1 parent 63ac902 commit b820665

File tree

11 files changed

+97
-97
lines changed

11 files changed

+97
-97
lines changed

spec/std/time/time_spec.cr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,18 @@ describe Time do
651651
end
652652

653653
it "#inspect" do
654-
Time.utc(2014, 1, 2, 3, 4, 5).inspect.should eq "2014-01-02 03:04:05.0 UTC"
655-
Time.utc(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789).inspect.should eq "2014-01-02 03:04:05.123456789 UTC"
654+
Time.utc(2014, 1, 2, 3, 4, 5).inspect.should eq "2014-01-02 03:04:05Z"
655+
Time.utc(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789).inspect.should eq "2014-01-02 03:04:05.123456789Z"
656656

657657
with_zoneinfo do
658658
location = Time::Location.load("Europe/Berlin")
659-
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05.0 +01:00 Europe/Berlin"
660-
Time.local(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789, location: location).inspect.should eq "2014-01-02 03:04:05.123456789 +01:00 Europe/Berlin"
659+
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05+01:00[Europe/Berlin]"
660+
Time.local(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789, location: location).inspect.should eq "2014-01-02 03:04:05.123456789+01:00[Europe/Berlin]"
661661
end
662662

663663
location = Time::Location.fixed(3601)
664-
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05.0 +01:00:01"
665-
Time.local(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789, location: location).inspect.should eq "2014-01-02 03:04:05.123456789 +01:00:01"
664+
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05+01:00:01"
665+
Time.local(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789, location: location).inspect.should eq "2014-01-02 03:04:05.123456789+01:00:01"
666666
end
667667

668668
it "at methods" do

src/file.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ require "crystal/system/file"
4040
# tempfile = File.tempfile("foo")
4141
#
4242
# File.size(tempfile.path) # => 6
43-
# File.info(tempfile.path).modification_time # => 2015-10-20 13:11:12 UTC
43+
# File.info(tempfile.path).modification_time # => 2015-10-20 13:11:12Z
4444
# File.exists?(tempfile.path) # => true
4545
# File.read_lines(tempfile.path) # => ["foobar"]
4646
# ```
@@ -208,7 +208,7 @@ class File < IO::FileDescriptor
208208
# ```
209209
# File.write("foo", "foo")
210210
# File.info("foo").size # => 3
211-
# File.info("foo").modification_time # => 2015-09-23 06:24:19 UTC
211+
# File.info("foo").modification_time # => 2015-09-23 06:24:19Z
212212
#
213213
# File.symlink("foo", "bar")
214214
# File.info("bar", follow_symlinks: false).type.symlink? # => true

src/http/common.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ module HTTP
343343
# ```
344344
# require "http"
345345
#
346-
# HTTP.parse_time("Sun, 14 Feb 2016 21:00:00 GMT") # => "2016-02-14 21:00:00 UTC"
347-
# HTTP.parse_time("Sunday, 14-Feb-16 21:00:00 GMT") # => "2016-02-14 21:00:00 UTC"
348-
# HTTP.parse_time("Sun Feb 14 21:00:00 2016") # => "2016-02-14 21:00:00 UTC"
346+
# HTTP.parse_time("Sun, 14 Feb 2016 21:00:00 GMT") # => "2016-02-14 21:00:00Z"
347+
# HTTP.parse_time("Sunday, 14-Feb-16 21:00:00 GMT") # => "2016-02-14 21:00:00Z"
348+
# HTTP.parse_time("Sun Feb 14 21:00:00 2016") # => "2016-02-14 21:00:00Z"
349349
# ```
350350
#
351351
# Uses `Time::Format::HTTP_DATE` as parser.

src/json/to_json.cr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ end
310310
# end
311311
#
312312
# timestamp = TimestampArray.from_json(%({"dates":[1459859781,1567628762]}))
313-
# timestamp.dates # => [2016-04-05 12:36:21 UTC, 2019-09-04 20:26:02 UTC]
313+
# timestamp.dates # => [2016-04-05 12:36:21Z, 2019-09-04 20:26:02Z]
314314
# timestamp.to_json # => %({"dates":[1459859781,1567628762]})
315315
# ```
316316
#
@@ -328,7 +328,7 @@ end
328328
# end
329329
#
330330
# timestamp = TimestampArray.from_json(%({"dates":["Apr 5, 2016","Sep 4, 2019"]}))
331-
# timestamp.dates # => [2016-04-05 00:00:00 UTC, 2019-09-04 00:00:00 UTC]
331+
# timestamp.dates # => [2016-04-05 00:00:00Z, 2019-09-04 00:00:00Z]
332332
# timestamp.to_json # => %({"dates":["Apr 5, 2016","Sep 4, 2019"]})
333333
# ```
334334
#
@@ -371,7 +371,7 @@ end
371371
# end
372372
#
373373
# timestamp = TimestampHash.from_json(%({"birthdays":{"foo":1459859781,"bar":1567628762}}))
374-
# timestamp.birthdays # => {"foo" => 2016-04-05 12:36:21 UTC, "bar" => 2019-09-04 20:26:02 UTC}
374+
# timestamp.birthdays # => {"foo" => 2016-04-05 12:36:21Z, "bar" => 2019-09-04 20:26:02Z}
375375
# timestamp.to_json # => %({"birthdays":{"foo":1459859781,"bar":1567628762}})
376376
# ```
377377
#
@@ -389,7 +389,7 @@ end
389389
# end
390390
#
391391
# timestamp = TimestampHash.from_json(%({"birthdays":{"foo":"Apr 5, 2016","bar":"Sep 4, 2019"}}))
392-
# timestamp.birthdays # => {"foo" => 2016-04-05 00:00:00 UTC, "bar" => 2019-09-04 00:00:00 UTC}
392+
# timestamp.birthdays # => {"foo" => 2016-04-05 00:00:00Z, "bar" => 2019-09-04 00:00:00Z}
393393
# timestamp.to_json # => %({"birthdays":{"foo":"Apr 5, 2016","bar":"Sep 4, 2019"}})
394394
# ```
395395
#
@@ -435,7 +435,7 @@ end
435435
# end
436436
#
437437
# person = Person.from_json(%({"birth_date": 1459859781}))
438-
# person.birth_date # => 2016-04-05 12:36:21 UTC
438+
# person.birth_date # => 2016-04-05 12:36:21Z
439439
# person.to_json # => %({"birth_date":1459859781})
440440
# ```
441441
module Time::EpochConverter
@@ -459,7 +459,7 @@ end
459459
# end
460460
#
461461
# timestamp = Timestamp.from_json(%({"value": 1459860483856}))
462-
# timestamp.value # => 2016-04-05 12:48:03.856 UTC
462+
# timestamp.value # => 2016-04-05 12:48:03.856Z
463463
# timestamp.to_json # => %({"value":1459860483856})
464464
# ```
465465
module Time::EpochMillisConverter

0 commit comments

Comments
 (0)