Skip to content
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

Merged
merged 6 commits into from Jun 7, 2018

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Mar 13, 2018

This PR adds extended documentation for most public types and methods of the Time and Time::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.

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`).
Copy link
Contributor

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.
Copy link
Contributor

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:
Copy link
Contributor

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).
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

in UTC time zone ?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

begin => beginning ?

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

offets => offsets ?

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
Copy link
Contributor

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?

@straight-shoota
Copy link
Member Author

Thanks @bew!

@straight-shoota straight-shoota force-pushed the jm/docs/time branch 2 times, most recently from 68f31cf to f4107d0 Compare March 13, 2018 12:17
@straight-shoota
Copy link
Member Author

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.

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}")
Copy link
Contributor

@Sija Sija Mar 13, 2018

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.

@straight-shoota straight-shoota force-pushed the jm/docs/time branch 2 times, most recently from adc012e to 89c868c Compare March 13, 2018 15:25
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
Copy link
Contributor

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".

Copy link
Member Author

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

Copy link
Member

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.
Copy link
Contributor

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`.
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Contributor

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???

Copy link
Member Author

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 =)

Copy link
Member

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

And leap seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

differnt => different

Copy link
Member Author

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.

Copy link
Member Author

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`).
Copy link
Contributor

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.

@straight-shoota straight-shoota force-pushed the jm/docs/time branch 2 times, most recently from 9cdb463 to bfc1ed3 Compare March 13, 2018 20:32
@jkthorne
Copy link
Contributor

Thank you for all the docs.

@straight-shoota
Copy link
Member Author

@RX14 Care for another review?

@RX14
Copy link
Contributor

RX14 commented Apr 26, 2018

This has conflicts, and there's no fixup commit with just the changes :(

@straight-shoota
Copy link
Member Author

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.

@bew
Copy link
Contributor

bew commented Jun 4, 2018

GTG?

@straight-shoota
Copy link
Member Author

Rebased

@RX14 RX14 requested a review from bcardiff June 4, 2018 21:55
@bcardiff bcardiff merged commit 75f4a61 into crystal-lang:master Jun 7, 2018
@bcardiff bcardiff added this to the 0.25.0 milestone Jun 7, 2018
@straight-shoota straight-shoota deleted the jm/docs/time branch June 7, 2018 15:35
@RX14 RX14 mentioned this pull request Jun 12, 2018
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.

None yet

7 participants