-
Notifications
You must be signed in to change notification settings - Fork 55
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
ZonedDateTime can parse its own string representation #483
Conversation
The previous commit makes it unnecessary
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #483 +/- ##
==========================================
- Coverage 92.79% 92.72% -0.07%
==========================================
Files 39 39
Lines 1818 1843 +25
==========================================
+ Hits 1687 1709 +22
- Misses 131 134 +3 ☔ View full report in Codecov by Sentry. |
I took a quick look and I think this is a good approach to move things in the right direction. I'll do a full review this week. |
Is it possible to have a solution that removes the need for this (allow parsing variable-length fractional settings like parsing DateTime does)? Also, keep in mind years that are not four digits long will change the length of the input. |
Thank you for your feedback @iamed2 , very good point about non 4 digit years, I have fixed this so that this aspect of the ISO standard is now supported. I felt that the code looked nicer if I used I cannot see an easy solution to allow the fractional seconds to have variable length like in |
After really getting into the code I noticed a couple of things which I went ahead and changed here:
|
end | ||
|
||
Dates.default_format(::Type{ZonedDateTime}) = ISOZonedDateTimeFormat |
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.
As you said this isn't documented anywhere so it's technically not public. I think it's safest to deprecate this in the off chance anyone is using this.
@omus : It is late now, I will have a look a your changes tomorrow |
Sounds good. Feel free to review next week instead if you prefer. I plan on merging this on Monday and making a new release. |
IIRC the variable-length fractional parsing used by DateTime requires that it the variable portion occurs at the end of the string. We would need to make modifications to Dates.jl for that or roll our own solution here. I'm not opposed to doing that but it's a larger lift that what we have here. |
I am perfectly fine with these two.
I feel that this change makes the code more vulnerable to changes in
Yes, this is certainly an improvement. I felt that it would be nice to have a year where the ISO standard really applies, a millisecond value ending with a Finally, I added some docstrings for the Your decision to deprecate rather than remove |
There is a noticeable performance difference although it's not huge: julia> using TimeZones, BenchmarkTools
julia> using TimeZones: ISOZonedDateTimeFormat, ISOZonedDateTimeNoMillisecondFormat
julia> function p1(str)
return if contains(str, '.')
parse(ZonedDateTime, str, ISOZonedDateTimeFormat)
else
parse(ZonedDateTime, str, ISOZonedDateTimeNoMillisecondFormat)
end
end
p1 (generic function with 1 method)
julia> function p2(str)
res = tryparse(ZonedDateTime, str, ISOZonedDateTimeFormat)
return res !== nothing ? res : parse(ZonedDateTime, str, ISOZonedDateTimeNoMillisecondFormat)
end
p2 (generic function with 1 method)
julia> @btime p1("2000-01-02T03:04:05-07:00")
938.524 ns (26 allocations: 1.07 KiB)
2000-01-02T03:04:05-07:00
julia> @btime p1("2000-01-02T03:04:05-07:00")
932.524 ns (26 allocations: 1.07 KiB)
2000-01-02T03:04:05-07:00
julia> @btime p2("2000-01-02T03:04:05-07:00")
966.650 ns (26 allocations: 1.07 KiB)
2000-01-02T03:04:05-07:00
julia> @btime p1.(fill("2000-01-02T03:04:05-07:00",1000));
925.000 μs (26006 allocations: 1.10 MiB)
julia> @btime p2.(fill("2000-01-02T03:04:05-07:00",1000));
958.959 μs (26006 allocations: 1.10 MiB) You are correct that the No matter the approach we take to parsing this dual format the test suite that is in place should ensure reliable parsing so changes to the |
@omus Regarding |
Will merge after CI completes |
This PR solves issue #470 in a way that formally preserves backwards compatibility of
TimeZones
.The first commit is what solves the issue. The second commit is optional, but given that
Dates.default_format(::Type{ZonedDateTime})
is no longer used in theTimeZones
package, notpublic
and not documented anywhere, I feel that it would be most correct to delete it as this would still formally preserve backwards compatibility.