JuliaTime / TimeZones.jl

IANA time zone database access for the Julia programming language
Other
86 stars 52 forks source link

FixedTimeZone("", 3600) != tz"UTC+01:00" #233

Open scls19fr opened 4 years ago

scls19fr commented 4 years ago

Hello,

I'm wondering why

julia> FixedTimeZone("", 3600) != tz"UTC+01:00"
true

julia> FixedTimeZone("", 3600)
UTC+01:00

julia> tz"UTC+01:00"
UTC+01:00

julia> FixedTimeZone("", 3600) != FixedTimeZone("0100")
true

julia> FixedTimeZone("0100")
UTC+01:00

I'm looking for a way to get a time zone offset from a number of second

Any idea?

omus commented 4 years ago

At the moment equality between FixedTimeZones compares the name, standard time offset, and daylight saving time offset.

julia> x = FixedTimeZone("", 3600)
UTC+01:00

julia> y = tz"UTC+01:00"
UTC+01:00

julia> x == y
false

julia> x.offset == y.offset
true

I'll need to look further into why we use the name as part of the comparison but there is an argument to be made for just comparing the offsets only.

As for creating a time zone from a number of seconds I would just do FixedTimeZone("", secs) like you were doing. If you really want equality to work to some degree you could do:

julia> secs = 3600
3600

julia> x = FixedTimeZone("UTC" * TimeZones.offset_string(Second(secs), true), Second(secs))
UTC+01:00

julia> x == tz"UTC+01"
true

We could even add this as an additional constructor to FixedTimeZone.

scls19fr commented 4 years ago

I'm wondering if building FixedTimeZone from Minute shouldn't be considered. Anyway additional constructor to FixedTimeZone should be considered.