TimeZones.jl icon indicating copy to clipboard operation
TimeZones.jl copied to clipboard

Make ZonedDateTime parametric on timezone type

Open oxinabox opened this issue 4 years ago • 6 comments

This is just the parametric type bit from https://github.com/JuliaTime/TimeZones.jl/pull/324#pullrequestreview-635205760

Contirbutes to #271 once we sort out the timezone types

oxinabox avatar Apr 14 '21 12:04 oxinabox

Wow @omus was right, adding a type parameters really does break a lot of things. It is generally easy enough to be compatible with both but a log ot Vector{ZonedDateTime} need to become Vector{<:ZonedDateTime} (which works with both).

The other thing we should maybe do is add a format versions to the compiled dir file path. This wouldn't matter for the end user since they would only ever see 1 version since the DEPS_DIR is per version of TimeZones.jl, but for anyone working on it and changing branches. It is a bit annoying

oxinabox avatar Apr 16 '21 17:04 oxinabox

We need a promotion rule for different ZonedDateTime{T}s. . The natural one is to go to the unionall ZonedDateTime, it is what owuld be returned if we were not overriding it in: https://github.com/JuliaTime/TimeZones.jl/blob/906cea08c2ca4a5c76b12e14fb60d5df7990fbf7/src/types/zoneddatetime.jl#L163-L165

Though an alternative might be to all astimezone on all of them, so they all become Variable, or they all become Fixed. I am not sure on implictaions of that.

but if we don't have a proimotion rule the following happens:

julia> [ZonedDateTime(Date(2000), tz"America/Winnipeg"), ZonedDateTime(Date(2001), tz"UTC")]
ERROR: no promotion exists for ZonedDateTime{VariableTimeZone} and ZonedDateTime{FixedTimeZone}
Stacktrace:
 [1] error(::String, ::Type, ::String, ::Type)
   @ Base ./error.jl:42
 [2] promote_rule(#unused#::Type{ZonedDateTime{VariableTimeZone}}, #unused#::Type{ZonedDateTime{FixedTimeZone}})
   @ TimeZones ~/JuliaEnvs/BidDatabase.jl/dev/TimeZones/src/types/zoneddatetime.jl:162
 [3] promote_type
   @ ./promotion.jl:233 [inlined]
 [4] promote_typeof(x::ZonedDateTime{VariableTimeZone}, xs::ZonedDateTime{FixedTimeZone})
   @ Base ./promotion.jl:272
 [5] vect(::ZonedDateTime{VariableTimeZone}, ::Vararg{Any, N} where N)
   @ Base ./array.jl:126
 [6] top-level scope
   @ REPL[18]:1

oxinabox avatar Apr 16 '21 18:04 oxinabox

Though an alternative might be to all astimezone on all of them, so they all become Variable, or they all become Fixed.

I'm definitely against converting the time zones automatically through promotion. I can see having heterogeneous ZonedDateTime types in the same Vector being useful even if it isn't super efficient. I think promoting to ZonedDateTime{TimeZone} seems reasonable.

A similar issue would also exist for: https://github.com/JuliaTime/TimeZones.jl/issues/318

omus avatar Apr 30 '21 03:04 omus

Just a thought: what if we introduced a new alternative type to ZonedDateTime? That should allow us to experiment with more breaking changes in a more opt-in manner.

omus avatar Apr 30 '21 03:04 omus

My current preferred solution is to introduce UTCZonedDateTime. It would make the most common case super-lightweight no need to reference timezone at all. and it's the case we can optimise interaction with ZonedDateTimes really well.

oxinabox avatar May 10 '21 22:05 oxinabox

My current preferred solution is to introduce UTCZonedDateTime.

Relevant: https://github.com/invenia/Intervals.jl/issues/178#issuecomment-901347323

omus avatar Aug 18 '21 19:08 omus