-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add basic TimeZone support to Dates stdlib #51341
Comments
I'd be in favor of this. cc: @omus |
I would also be in favor of renaming (I guess POSIXInstant would not be correct either, since the epoch is in UTC, which |
There have been timezones with non-integer offsets in minutes in the past, for example: https://en.wikipedia.org/wiki/Moscow_Time#History. Milliseconds should be a safer choice |
I wonder if there's some value in mentioning https://github.com/BurntSushi/jiff, which seems to take an approach rather in line with (what I'd hope at least) Julia stdlibs aim for:
There are a number of interesting choices in the library, such of the use of nanoseconds not microseconds to represent instances, only bundling the timezone DB on windows and using |
I'm not opposed to having this but it would be nice to avoid having a
Do we know why these packages are reluctant to depend on TimeZones.jl? Since the creation of TZJData.jl we've switched to artifacts for tzdata information which eliminated processing done previously during package initialization. If there are other concerns we can possibly address those directly TimeZones.jl
The initial offsets for most time zones in the IANA tz database include a offset with seconds. I've not seen anything with a higher resolution than seconds though. |
@omus Honestly I think it's because TimeZones.jl is overkill: they don't need actual time zones, just UTC time. Thinking this through a bit more, I think simply doing something like
might be sufficient. |
I'd be more in favor of having the more limited scope of struct DateTimeUTC <: AbstractDateTime
instant::UTInstant{Millisecond} # or UTCInstant?
end Effectively we would just be defining a type to be explicit that this datetime is in UTC. We would probably want to disallow conversion between
Another solution we could consider is splitting out |
Currently
DateTime
is completely time-zone unaware: this simplicity was intentional (as described by @quinnj in #49700 (comment)), with additional functionality pushed to TimeZones.jl.The problem is that many packages skip time zone support altogether, or implement it in inconsistent ways: for example,
now()
returns a localDateTime
by default, whereas TOML.jl treats allDateTime
s as UTC.Even packages which aren't in the stdlib are reluctant to use TimeZones.jl, resulting in bugs or less-than-useful information:
chopz
to get rid of the pesky trailing ZWhat I would like to propose is to add basic UTC and UTC + offset support into stdlib (basically functionality which doesn't require looking up a timezone database). This would be sufficient to fully support the TOML datetime and many other applications.
I was thinking something like the following
We already have
UTC <: TimeZone
defined, so we could also defineSimilarly we could expand the
datetime""
macro to support theZ
(which would return aDateTimeZoned{UTC}
and+00:00
suffixes (which would return aDateTimeZoned{UTCOffset}
.Like our current
DateTime
, we would continue to ignore leap seconds (as basically every other piece of software does).This would fix the following issues:
Date
ISO-8601? #49821The text was updated successfully, but these errors were encountered: