Skip to content

Add basic TimeZone support to Dates stdlib #51341

@simonbyrne

Description

@simonbyrne

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 local DateTime by default, whereas TOML.jl treats all DateTimes as UTC.

Even packages which aren't in the stdlib are reluctant to use TimeZones.jl, resulting in bugs or less-than-useful information:

What 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

struct DateTimeZoned{TZ<:TimeZone} <: AbstractDateTime
    instant::UTInstant{Millisecond}
    zone::TZ
end

We already have UTC <: TimeZone defined, so we could also define

struct UTCOffset <: TimeZone
    offset::Millisecond # or could use Minute?
end

Similarly we could expand the datetime"" macro to support the Z (which would return a DateTimeZoned{UTC} and +00:00 suffixes (which would return a DateTimeZoned{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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    datesDates, times, and the Dates stdlib module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions