-
Notifications
You must be signed in to change notification settings - Fork 58
Date <-> ZonedDateTime #231
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
Conversation
src/conversions.jl
Outdated
| Returns an equivalent `Date` without any `TimeZone`, or time information. | ||
| """ | ||
| Dates.Date(zdt::ZonedDateTime) = Date(DateTime(zdt)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been intending on dropping DateTime(::ZonedDateTime) in favor of localtime(::Type{DateTime}, ::ZonedDateTime) or something similar. This is definitely a lossy operation and it's important to communicate the implicit time zone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really dislike that.
Often I just have a collection of DateTime,
one per day.
and I want to plot them (cf #184),
or I want to display them in a table,
and I just want to get rid of extra information.
I don't actually care about the time or even the exact date often.
I think it pretty clear to the user that it is losing information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at that issue again Date(zdt, UTC) / Date(zdt, Local) isn't bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to see this change when we resolve #125 for DateTimes.
Til then this match the API we have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't want to take on the change yourself I can make the remainder of the changes. I don't think I would merge this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do want to merge as is, because the status quo of matching how DateTime works is known.
All other things are not known and we might want to do a little design and thinking.
OTOH:
Date(zdt, Local)andDate(zdt, UTC)//DateTime(zdt, Local)andDateTime(zdt, UTC)do sound right to me though.- A bunch of places that do
DateTime(ztd)will need to be changed due to deprecation. and any places that doDate(DateTime(ztd))will be a subset of those. So doing both at once would mean we can go staight toDate(ztd, Local).
I think I am convinced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am convinced
Convinced enough to do the work? ;). As I said I can do the leg work if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how deep I would have to go,
so if you know exactly what you have to change be my guest.
Otherwise this might sit til after neurips
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting til after NeurIPS might be fine though.
We've lived this long
Codecov Report
@@ Coverage Diff @@
## master #231 +/- ##
==========================================
+ Coverage 93.97% 93.99% +0.02%
==========================================
Files 29 29
Lines 1112 1116 +4
==========================================
+ Hits 1045 1049 +4
Misses 67 67
Continue to review full report at Codecov.
|
|
Alright, I've made the updates and bumped the version to 1.0.0 (it's time) |
|
|
||
| function zdt2unix(::Type{T}, zdt::ZonedDateTime) where T<:Integer | ||
| floor(T, datetime2unix(utc(zdt))) | ||
| floor(T, datetime2unix(DateTime(zdt, UTC))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| floor(T, datetime2unix(DateTime(zdt, UTC))) | |
| return floor(T, datetime2unix(DateTime(zdt, UTC))) |
|
|
||
| function zdt2unix(zdt::ZonedDateTime) | ||
| datetime2unix(utc(zdt)) | ||
| datetime2unix(DateTime(zdt, UTC)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| datetime2unix(DateTime(zdt, UTC)) | |
| return datetime2unix(DateTime(zdt, UTC)) |
| end | ||
|
|
||
| function julian2zdt(jd::Real) | ||
| ZonedDateTime(julian2datetime(jd), utc_tz, from_utc=true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ZonedDateTime(julian2datetime(jd), utc_tz, from_utc=true) | |
| return ZonedDateTime(julian2datetime(jd), utc_tz, from_utc=true) |
|
|
||
| function zdt2julian(::Type{T}, zdt::ZonedDateTime) where T<:Real | ||
| convert(T, datetime2julian(utc(zdt))) | ||
| convert(T, datetime2julian(DateTime(zdt, UTC))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| convert(T, datetime2julian(DateTime(zdt, UTC))) | |
| return convert(T, datetime2julian(DateTime(zdt, UTC))) |
|
|
||
| function zdt2julian(::Type{T}, zdt::ZonedDateTime) where T<:Integer | ||
| floor(T, datetime2julian(utc(zdt))) | ||
| floor(T, datetime2julian(DateTime(zdt, UTC))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| floor(T, datetime2julian(DateTime(zdt, UTC))) | |
| return floor(T, datetime2julian(DateTime(zdt, UTC))) |
|
|
||
| function zdt2julian(zdt::ZonedDateTime) | ||
| datetime2julian(utc(zdt)) | ||
| datetime2julian(DateTime(zdt, UTC)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| datetime2julian(DateTime(zdt, UTC)) | |
| return datetime2julian(DateTime(zdt, UTC)) |
|
I squashed some commits in preparation for merging. A couple of things to note:
|
src/conversions.jl
Outdated
| """ | ||
| Time(zdt::ZonedDateTime, ::Union{Type{Local}, Type{UTC}}) -> Time | ||
| Create an implicit local/UTC `Time` from the given `ZonedDateTime`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couild we add a bit more text?
| Create an implicit local/UTC `Time` from the given `ZonedDateTime`. | |
| Create an implicit local/UTC `Time` from the given `ZonedDateTime`. | |
| - `Local` means a time local to the timezone in the `ZonedDateTime`, i.e. just discarding the timezone information. (**Not** local to the system time of the user invoking the code). | |
| - `UTC` means to shift to the `UTC` timezone and then discard all timezone information. |
Maybe also this particular text should be put in to a string constant and interpolatred in at a few places?
Like in Date and DateTime as well?
Probably could be written better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote the docstrings to be more sensible
oxinabox
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than a bit of documentation this LGTM.
|
Quick note: I'm still planning on doing the 1.0 version change as part of this but since this adds a deprecation I'll be doing a 0.11 release first so I can drop the deprecation as part of 1.0 |
|
|
||
| export TimeZone, @tz_str, istimezone, FixedTimeZone, VariableTimeZone, ZonedDateTime, | ||
| DateTime, TimeError, AmbiguousTimeError, NonExistentTimeError, UnhandledTimeError, | ||
| DateTime, Date, Time, UTC, Local, TimeError, AmbiguousTimeError, NonExistentTimeError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these be broken down into logical groupings (macros, errors, etc.) or alphabetically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do some organization. What do you think of grouping by the file in which these are defined (and having a comment indicating the file)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be too granular, but:
export @tz_str
export AmbiguousTimeError, NonExistentTimeError, TimeError
export Date, DateTime, Local, Time, TimeZone, UTC, VariableTimeZone, ZonedDateTime
export isdatetime
I think it's less about what the groupings are but more that there is some order to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that there is an ordering to this but it's not as obvious as I'd like. A couple of key things I would like to communicate as part of the exports:
- Quite a few of these are re-exports from
Dateswhich are just here in case someone only doesusing TimeZones - There are some types that are closely related like
UTCandLocalwhich I think should be sequential
I'll post an revised version in a sec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm currently thinking:
export
TimeZone, FixedTimeZone, VariableTimeZone, @tz_str, istimezone, localzone
UTC, Local,
ZonedDateTime, timezone,
# Exceptions
TimeError, AmbiguousTimeError, NonExistentTimeError, UnhandledTimeError,
# Discovery tools
timezone_names, all_timezones, timezones_from_abbr, timezone_abbrs,
next_transition_instant, show_next_transition,
# Extended functionality from Dates. Note: Some of these exports have already been done
# but are listed here for completeness.
TimeZone, UTC,
DateTime, Date, Time,
now, today,
year, month, week, day, dayofmonth, hour, minute, second, millisecond
yearmonthday, yearmonth, monthday,
firstdayofyear, firstdayofquarter, firstdayofmonth, firstdayofweek,
lastdayofyear, lastdayofquarter, lastdayofmonth, lastdayofweekI'm unsure on what is better at this point and possibly this kind of logical grouping should just be in the documentation? In any case I think this could be made into an issue and not hold up this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this isn't a dealbreaker for the PR going through and can be discussed afterwards.
Side-note; does exporting functionality multiple times have any consequences to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does exporting functionality multiple times have any consequences to it?
No it shouldn't
I got really tired of writing
Date(DateTime(zdt))andZonedDateTime(DateTime(date))Fixes #222 and #209