Skip to content
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

Allow constructing a FixedTimeZone from Dates.UTC and allow passing it to ZonedDateTime #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Compat.Dates: now, julian2datetime, unix2datetime
# UTC is an abstract type defined in Dates, for some reason
const utc_tz = FixedTimeZone("UTC")

FixedTimeZone(::UTC) = utc_tz

"""
DateTime(::ZonedDateTime) -> DateTime

Expand Down
4 changes: 4 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ function ZonedDateTime(dt::DateTime, tz::FixedTimeZone; from_utc::Bool=false)
return ZonedDateTime(utc_dt, tz, tz)
end

function ZonedDateTime(dt::DateTime, tz::UTC; from_utc::Bool=false)
return ZonedDateTime(dt, FixedTimeZone(tz); from_utc=from_utc)
end

"""
ZonedDateTime(dt::DateTime, tz::VariableTimeZone, occurrence::Integer) -> ZonedDateTime

Expand Down
5 changes: 5 additions & 0 deletions test/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import Compat.Dates
utc = FixedTimeZone("UTC")
warsaw = resolve("Europe/Warsaw", tzdata["europe"]...)

# Converting from the stdlib UTC
@test FixedTimeZone(UTC()) == utc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I want to support using an instance of UTC as this is never actually utilized in Base. In fact they only ever seem to use the type so maybe the type should be redefined as abstract or rethought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your interface currently says it accepts any TimeZone :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. This happens to be the only TimeZone I don't like 😆

dt = DateTime(2015, 1, 1, 0)
@test ZonedDateTime(dt, FixedTimeZone(UTC())) == ZonedDateTime(dt, utc)

# Converting a ZonedDateTime into a DateTime
dt = DateTime(2015, 1, 1, 0)
zdt = ZonedDateTime(dt, warsaw)
Expand Down