-
Notifications
You must be signed in to change notification settings - Fork 58
add isless method for FixedTimeZone #491
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
Conversation
| Defines a true chronological ordering for FixedTimeZone objects, answering | ||
| the question: "which time zone represents an earlier moment in absolute time?" | ||
| The core principle is that a time zone is "chronologically earlier" (less than) | ||
| if its numerical UTC offset is "mathematically greater". |
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 ordering of a FixedTimeZone vs. a FixedTimeZone could definitely work either way and I don't think it should be relied upon for performing chronological sorting of time instants.
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.
Without this definition the comparison would define "UTC-5" as less than "UTC-4" since it is numerically smaller.
julia> FixedTimeZone("UTC-5").offset.std
-18000 seconds
julia> FixedTimeZone("UTC-4").offset.std
-14400 secondsThere 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 there should be an ordering but I'm not sure on what the ordering should be. I would expect most users would expect the most negative offset to be first in the list. However, that is chronologically backwards:
julia> using TimeZones
julia> tzs = [tz"UTC-4", tz"UTC+1", tz"UTC-5"]
3-element Vector{FixedTimeZone}:
UTC-04:00
UTC+01:00
UTC-05:00
julia> sort!(ZonedDateTime.(2025,6,17,tzs))
3-element Vector{ZonedDateTime}:
2025-06-17T00:00:00+01:00
2025-06-17T00:00:00-04:00
2025-06-17T00:00:00-05:00
julia> Base.isless(a::FixedTimeZone, b::FixedTimeZone) = isless(a.offset, b.offset)
julia> sort!(tzs)
3-element Vector{FixedTimeZone}:
UTC-05:00
UTC-04:00
UTC+01:00
julia> Base.isless(a::FixedTimeZone, b::FixedTimeZone) = isless(b.offset, a.offset)
julia> sort!(tzs)
3-element Vector{FixedTimeZone}:
UTC+01:00
UTC-04:00
UTC-05:00Maybe the compromise is to define a is_chrono_less(::FixedTimeZone, ::FixedTimeZone)? That way downstream dependents can have a guaranteed ordering
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.
Yeah, I agree this can break downstream, I don't think this PR is needed anymore, I'll do the comparison on the offset isless(y.offset, x.offset)
add suggestions Co-authored-by: Curtis Vogt <[email protected]>
|
Closing as this PR is not longer needed. |
Description
This PR adds support to sort FixedTimeZones by adding a comparison method isless.