JuliaTime / TimeZones.jl

IANA time zone database access for the Julia programming language
Other
86 stars 52 forks source link

Proof of concept for isbits (PR 2) #323

Open oxinabox opened 3 years ago

oxinabox commented 3 years ago

This is a rebased version of #287 (and thus also would close #271 )

I am experimenting with it again.

codecov-io commented 3 years ago

Codecov Report

Merging #323 (1a64338) into master (906cea0) will decrease coverage by 0.04%. The diff coverage is 98.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #323      +/-   ##
==========================================
- Coverage   93.80%   93.75%   -0.05%     
==========================================
  Files          32       33       +1     
  Lines        1534     1586      +52     
==========================================
+ Hits         1439     1487      +48     
- Misses         95       99       +4     
Impacted Files Coverage Δ
src/TimeZones.jl 100.00% <ø> (ø)
src/types/timezone.jl 88.00% <ø> (ø)
src/external.jl 80.00% <80.00%> (ø)
src/types/fixedtimezone.jl 100.00% <100.00%> (ø)
src/types/variabletimezone.jl 100.00% <100.00%> (ø)
src/types/zoneddatetime.jl 96.70% <100.00%> (+0.65%) :arrow_up:
src/compat.jl 0.00% <0.00%> (-100.00%) :arrow_down:
src/parse.jl 94.44% <0.00%> (-0.02%) :arrow_down:
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 906cea0...1a64338. Read the comment docs.

oxinabox commented 3 years ago

When I used this, I get:

BoundsError(TimeZone[tz"Z", tz"UTC", TimeZones.FixedTimeZone("LMT", -21036), TimeZones.FixedTimeZone("CST", -21600), TimeZones.FixedTimeZone("CDT", -21600, 3600), tz"EST", TimeZones.FixedTimeZone("CWT", -21600, 3600), TimeZones.FixedTimeZone("CPT", -21600, 3600), tz"America/Chicago"],
(16,)), Any[(getindex at array.jl:809 [inlined], 1),
(getindex at external.jl:15 [inlined], 1),

Which suggests that it is not serializing properly.

I recall @JeffBezanson saying something about overloading serialize actually doesn't work, because serializing Vector{T} doesn't call serialize(T).

Which seems to be true:

Setup:

julia> using Serialization, TimeZones

julia> zdt = ZonedDateTime(Date(2011, 6, 1), tz"America/Winnipeg")
2011-06-01T00:00:00-05:00

To check if it is serializing properly we expect that the name of the timezone would occur in the serialized stream.

We can see it does for if just serializing a ZonedDateTime

julia> iob = IOBuffer(); serialize(Serializer(iob), zdt); occursin("Winnipeg", String(take!(iob)))
true

But that it does not if serializing an array of ZonedDateTimes:

julia> iob = IOBuffer(); serialize(Serializer(iob), [zdt]); occursin("Winnipeg", String(take!(iob)))
false
oxinabox commented 3 years ago

I think the answer is we should be overloading write not serialize both serialize_any and serialize_array_values fall back to write>

Edit: no that isn't quite write. serializing array values calls serialize on the elements. except of those elements are bitstypes. And in that case it does call something that falls back to write https://github.com/JuliaLang/julia/blob/4996445df37e526dac2772e333caf82f1ea987f0/stdlib/Serialization/src/Serialization.jl#L272