Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,18 @@ describe Time do
end

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.

Time.utc(2014, 1, 2, 3, 4, 5, nanosecond: 123_456_789).inspect.should eq "2014-01-02 03:04:05.123456789Z"

with_zoneinfo do
location = Time::Location.load("Europe/Berlin")
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05.0 +01:00 Europe/Berlin"
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"
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05+01:00[Europe/Berlin]"
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]"
end

location = Time::Location.fixed(3601)
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05.0 +01:00:01"
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"
Time.local(2014, 1, 2, 3, 4, 5, location: location).inspect.should eq "2014-01-02 03:04:05+01:00:01"
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"
end

it "at methods" do
Expand Down
4 changes: 2 additions & 2 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require "crystal/system/file"
# tempfile = File.tempfile("foo")
#
# File.size(tempfile.path) # => 6
# File.info(tempfile.path).modification_time # => 2015-10-20 13:11:12 UTC
# File.info(tempfile.path).modification_time # => 2015-10-20 13:11:12Z
# File.exists?(tempfile.path) # => true
# File.read_lines(tempfile.path) # => ["foobar"]
# ```
Expand Down Expand Up @@ -202,7 +202,7 @@ class File < IO::FileDescriptor
# ```
# File.write("foo", "foo")
# File.info("foo").size # => 3
# File.info("foo").modification_time # => 2015-09-23 06:24:19 UTC
# File.info("foo").modification_time # => 2015-09-23 06:24:19Z
#
# File.symlink("foo", "bar")
# File.info("bar", follow_symlinks: false).type.symlink? # => true
Expand Down
6 changes: 3 additions & 3 deletions src/http/common.cr
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ module HTTP
# ```
# require "http"
#
# HTTP.parse_time("Sun, 14 Feb 2016 21:00:00 GMT") # => "2016-02-14 21:00:00 UTC"
# HTTP.parse_time("Sunday, 14-Feb-16 21:00:00 GMT") # => "2016-02-14 21:00:00 UTC"
# HTTP.parse_time("Sun Feb 14 21:00:00 2016") # => "2016-02-14 21:00:00 UTC"
# HTTP.parse_time("Sun, 14 Feb 2016 21:00:00 GMT") # => "2016-02-14 21:00:00Z"
# HTTP.parse_time("Sunday, 14-Feb-16 21:00:00 GMT") # => "2016-02-14 21:00:00Z"
# HTTP.parse_time("Sun Feb 14 21:00:00 2016") # => "2016-02-14 21:00:00Z"
# ```
#
# Uses `Time::Format::HTTP_DATE` as parser.
Expand Down
12 changes: 6 additions & 6 deletions src/json/to_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ end
# end
#
# timestamp = TimestampArray.from_json(%({"dates":[1459859781,1567628762]}))
# timestamp.dates # => [2016-04-05 12:36:21 UTC, 2019-09-04 20:26:02 UTC]
# timestamp.dates # => [2016-04-05 12:36:21Z, 2019-09-04 20:26:02Z]
# timestamp.to_json # => %({"dates":[1459859781,1567628762]})
# ```
#
Expand All @@ -328,7 +328,7 @@ end
# end
#
# timestamp = TimestampArray.from_json(%({"dates":["Apr 5, 2016","Sep 4, 2019"]}))
# timestamp.dates # => [2016-04-05 00:00:00 UTC, 2019-09-04 00:00:00 UTC]
# timestamp.dates # => [2016-04-05 00:00:00Z, 2019-09-04 00:00:00Z]
# timestamp.to_json # => %({"dates":["Apr 5, 2016","Sep 4, 2019"]})
# ```
#
Expand Down Expand Up @@ -371,7 +371,7 @@ end
# end
#
# timestamp = TimestampHash.from_json(%({"birthdays":{"foo":1459859781,"bar":1567628762}}))
# timestamp.birthdays # => {"foo" => 2016-04-05 12:36:21 UTC, "bar" => 2019-09-04 20:26:02 UTC}
# timestamp.birthdays # => {"foo" => 2016-04-05 12:36:21Z, "bar" => 2019-09-04 20:26:02Z}
# timestamp.to_json # => %({"birthdays":{"foo":1459859781,"bar":1567628762}})
# ```
#
Expand All @@ -389,7 +389,7 @@ end
# end
#
# timestamp = TimestampHash.from_json(%({"birthdays":{"foo":"Apr 5, 2016","bar":"Sep 4, 2019"}}))
# timestamp.birthdays # => {"foo" => 2016-04-05 00:00:00 UTC, "bar" => 2019-09-04 00:00:00 UTC}
# timestamp.birthdays # => {"foo" => 2016-04-05 00:00:00Z, "bar" => 2019-09-04 00:00:00Z}
# timestamp.to_json # => %({"birthdays":{"foo":"Apr 5, 2016","bar":"Sep 4, 2019"}})
# ```
#
Expand Down Expand Up @@ -435,7 +435,7 @@ end
# end
#
# person = Person.from_json(%({"birth_date": 1459859781}))
# person.birth_date # => 2016-04-05 12:36:21 UTC
# person.birth_date # => 2016-04-05 12:36:21Z
# person.to_json # => %({"birth_date":1459859781})
# ```
module Time::EpochConverter
Expand All @@ -459,7 +459,7 @@ end
# end
#
# timestamp = Timestamp.from_json(%({"value": 1459860483856}))
# timestamp.value # => 2016-04-05 12:48:03.856 UTC
# timestamp.value # => 2016-04-05 12:48:03.856Z
# timestamp.to_json # => %({"value":1459860483856})
# ```
module Time::EpochMillisConverter
Expand Down
6 changes: 3 additions & 3 deletions src/log/format.cr
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ end
#
# It writes log entries with the following format:
# ```
# 2020-05-07T17:40:07.994508000Z INFO - my.source: Initializing everything
# 2020-05-07 17:40:07.994508000Z INFO - my.source: Initializing everything
# ```
#
# When the entries have context data it's also written to the output:
# ```
# 2020-05-07T17:40:07.994508000Z INFO - my.source: Initializing everything -- {"data" => 123}
# 2020-05-07 17:40:07.994508000Z INFO - my.source: Initializing everything -- {"data" => 123}
# ```
#
# Exceptions are written in a separate line:
# ```
# 2020-05-07T17:40:07.994508000Z ERROR - my.source: Something failed
# 2020-05-07 17:40:07.994508000Z ERROR - my.source: Something failed
# Oh, no (Exception)
# from ...
# ```
Expand Down
Loading