-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend documentation of Time and Time::Location APIs #5819
Conversation
src/time.cr
Outdated
# Measures the execution time of *block*. | ||
# | ||
# The measurement relies on the monotonic clock and is not | ||
# affected by fluctuations o the system clock (see `#monotonic`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o
=> of
src/time.cr
Outdated
end | ||
|
||
# Returns a copy of `self` with time-of-day components (hour, minute, ...) set to zero. | ||
# Returns a copy of `self` with time-of-day components set to zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you re-add the hint about what time-of-day components
are? (the (hour, minute, ...)
)
src/time.cr
Outdated
# time_ar = Time.new(2018, 3, 8, 18, 5, 13, location: Time::Location.load("America/Buenos_Aires")) | ||
# time_de == time_ar # => true | ||
# | ||
# both times represent the same instant: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this line in comment?
# # both ...
src/time.cr
Outdated
# Parses a Time in the given *time* string, using the given *pattern* (see | ||
# `Time::Format`). | ||
# Parses a `Time` from *time* string using the given *pattern* (see | ||
# `Time::Format` for details). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: For the 2 methods above you have the See `Time::Format` for details
on a new line, here it is in parentheses on the same line as the description. I think we should keep consistency and put this on a new line.
@@ -561,7 +903,10 @@ struct Time | |||
) | |||
end | |||
|
|||
# Returns a copy of this `Time` converted to UTC. | |||
# Returns a copy of this `Time` representing the same instant in UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in UTC time zone
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unneccessary. UTC implies it is a time zone and is never written that explicitly in other places.
src/time.cr
Outdated
@@ -606,7 +954,9 @@ struct Time | |||
def_at_beginning(hour) { Time.new(year, month, day, hour, location: location) } | |||
def_at_beginning(minute) { Time.new(year, month, day, hour, minute, location: location) } | |||
|
|||
# Returns the time when the week that includes `self` starts. | |||
# Returns a copy of this `Time` representing the begin of the week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
begin
=> beginning
?
src/time/location.cr
Outdated
def initialize(@name : String, @offset : Int32, @dst : Bool) | ||
# Maximium offets of IANA timezone database are -12:00 and +14:00. | ||
# Maximium offets of IANA time zone database are -12:00 and +14:00. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offets
=> offsets
?
src/time/location.cr
Outdated
def lookup(time : Time) : Zone | ||
lookup(time.epoch) | ||
end | ||
|
||
# Returns the time zone in use at `epoch` (time in seconds since UNIX epoch). | ||
# Returns the time zone offset observed at *epoch*. | ||
# *epoch* expresses the number of seconds since UNIX epoch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line before this line?
Thanks @bew! |
68f31cf
to
f4107d0
Compare
I intentionally used additional indent for comments in the code examples to align them across different lines and code blocks. Unfortunately, the formatter doesn't allow that and I had to adjust to comply with the formatter rules (second commit). There should be a way to keep the intended formatting to improve readability. |
src/time/location/loader.cr
Outdated
file.seek -ZIP_TAIL_SIZE, IO::Seek::End | ||
|
||
if file.read_bytes(Int32, IO::ByteFormat::LittleEndian) != END_OF_CENTRAL_DIRECTORY_HEADER_SIGNATURE | ||
raise InvalidTZDataError.new("corrupt zip file") | ||
raise InvalidTZDataError.new("corrupt zip file #{file.path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use "Sentence case" here. ditto all below.
adc012e
to
89c868c
Compare
src/time.cr
Outdated
@@ -1,66 +1,206 @@ | |||
require "crystal/system/time" | |||
|
|||
# `Time` represents an instance in incremental time. Here are some examples: | |||
# `Time` represents a date-time instant in incremental time observed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not incremental time, that guarantee is reserved for Time.monotonic
. I'd prefer the wording "an instant in time observed in a specific time zone".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time
has an incremental time-line, which does not necessarily mean a monotonic clock. In fact, it has little to do with that.
"Incremental" means each instance represent a specific moment on the time-line, as opposed to "floating time" which has no time-line at all, or a local date-time which can be ambiguous.
Maybe I should add some reference, for example this link: https://www.w3.org/International/articles/definitions-time/#incremental_time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That link should be in the type docs. I think most of us have no idea what incremental time is.
src/time.cr
Outdated
# nanosecond-of-second with value range `0..999_999_999`. | ||
# | ||
# The supported date range is `0001-01-01 00:00:00.0` to | ||
# 999-12-31 23:59:59.999_999_999` in any local time zone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it's not, since we're already outside that date range!
# and *nanoseconds* elapsed from epoch (`0001-01-01 00:00:00.0 UTC`) | ||
# observed in *location*. | ||
# | ||
# Valid range for *seconds* is `0..315_537_897_599`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a constant for the maximum number of seconds? There should be and it should be quoted instead of a bare number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Time::MAX_SECONDS
. But it is not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it should be documented. And there should probably be Time::MIN_SECONDS = 0
as well.
src/time.cr
Outdated
# Valid range for *seconds* is `0..315_537_897_599`. | ||
# For *nanoseconds* it is `0..999_999_999`. | ||
def initialize(*, @seconds : Int64, @nanoseconds : Int32, @location : Location) | ||
unless 0 <= @nanoseconds < NANOSECONDS_PER_SECOND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW does this method not range check @seconds
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. But #5786 is just waiting for a second review =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice pun ;-)
src/time.cr
Outdated
# The duration amounts to the actual time elapsed between both instances, on | ||
# the instant time-line. | ||
# The difference between local date-time representations may equal to a | ||
# differnt duration, depending on time zone transitions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And leap seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
differnt
=> different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which are ignored - or, more exactly, are not even recognized - so they shouldn't have any influence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more clear: Neither the instance time-line nor the date-time representations - which are both just models used by Time
- take leap seconds into account. Thus leap seconds have no impact on the difference between both.
Leap seconds can only lead to a difference (of one second) to the actual time elapsed.
src/time.cr
Outdated
Format.new(pattern, location).parse(time) | ||
end | ||
|
||
# Returns the number of seconds since the Epoch for this time. | ||
# Returns the number of seconds since Unix epoch (`1970-01-01 00:00:00 UTC`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the unix epoch and ditto throughout.
9cdb463
to
bfc1ed3
Compare
Thank you for all the docs. |
bfc1ed3
to
700e8ee
Compare
@RX14 Care for another review? |
This has conflicts, and there's no fixup commit with just the changes :( |
700e8ee
to
6fab9e4
Compare
Well, you're responsible for the conflict by merging #5794 😁 It seems like I already merged in the fixups, but I basically applied the changes you requested in the last review or answered to your comments. Rebased. |
fd2f5a7
to
5bd1129
Compare
GTG? |
5bd1129
to
e66f207
Compare
Rebased |
This PR adds extended documentation for most public types and methods of the
Time
andTime::Location
API.There are no code changes except from adding a few type restrictions. The constructors of
Time
have been aligned in a more logical order (although this is only relevant in the source code, not the API docs), but there are no changes to the actual implementation.I'm pretty sure the documentation is generally correct. But it's a lot of content and I expect there to be semantic mistakes, abstruse descriptions as well as grammatical, stylistic and typographical errors. Please review thoroughly and point me to where I need to improve.