-
-
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
Refactor time platform specific implementation #4502
Conversation
Maybe ticks don't have to be moved? |
My main concern is that taken on their own (as they should be), I agree with @ysbaddaden that |
I prefer an explicit |
@ysbaddaden the tuple is so that we don't need to do conversions back and forth from ticks, correct? |
src/crystal/system/time.cr
Outdated
@@ -0,0 +1,22 @@ | |||
# :nodoc: |
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.
We don't want to :nodoc:
Crystal
as we loose documenting macros and Crystal::VERSION
. The :nodoc:
should be placed on Crystal::System
only.
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.
My bad. I did that on the random PR!
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.
fixed (in master as well)
src/crystal/system/unix/time.cr
Outdated
end | ||
|
||
def self.compute_second_and_tenth_microsecond | ||
{% if flag?(:darwin) %} |
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.
Should this be separated out into a file just for darwin? How about requiring this (unix) file and a darwin file which overrides compute_second_and_tenth_microsecond
or would that be too messy?
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 happens once and it's 3 lines. It seems more complicated to extract it... so I guess it's acceptable?
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'd move it to a separate file. I think inside a given System implementation there shouldn't be any if flag?
, otherwise it kind of missing the point of extracting it into a different place.
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.
Splitting darwin and unix makes this harder to understand I think. One function is shared. The other don't. I tried splitting them but I was not happy with the result. Now the responsibilities of the System::Time is more clear and the windows implementation will be in a different file.
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 believe macOS Sierra added support for clock_gettime
, so maybe the condition will go away, someday.
Functions renamed. Now the The only platform specific in |
Since the seconds in |
@RX14 , @ysbaddaden I would appreciate another pair of eyes before merging this. I fix an issue discovered by 32 bits, hopefully the only thing left is #4502 (comment) . |
I think the API will eventually change, but for the time being this is fine. Maybe replace if LibC.methods.includes?("clock_gettime".id)
# clock_gettime
else
# fallback to gettimeofday
end BTW: what may change is that we need a broken down time representation to determine the offset, using |
src/crystal/system/time.cr
Outdated
# :nodoc: | ||
module Time | ||
# Returns the number of seconds that you must add to UTC to get local time. | ||
# *seconds* are absolutes. |
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.
What do you mean by *seconds* are absolutes
?
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 means seconds elapsed from 0, not from unix epoch as it was before.
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.
When you say "from 0" it's not at all clear you're referring to the Gregorian epoch. I'd say something like *seconds* are measured from the Gregorian epoch (01 January 0001 00:00:00)
src/crystal/system/time.cr
Outdated
# *seconds* are absolutes. | ||
# def self.compute_utc_offset(seconds) | ||
|
||
# Returns the current utc time meassured in absolute `{seconds, tenth_microsecond}` |
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.
ditto
Add type some annotations to Crystal::Sytem::Time methods
Time::Span
ticks constants where moved to avoid circular dependency.