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

diff on ranges ZonesDateTimes errors #349

Open
oxinabox opened this issue Jun 23, 2021 · 0 comments
Open

diff on ranges ZonesDateTimes errors #349

oxinabox opened this issue Jun 23, 2021 · 0 comments

Comments

@oxinabox
Copy link
Contributor

Consider

julia> using Dates

julia> using TimeZones

julia> diff(ZonedDateTime(DateTime(2021,1,1), tz"UTC"):Hour(1):ZonedDateTime(DateTime(2021,1,2), tz"UTC"))
ERROR: MethodError: Cannot `convert` an object of type Millisecond to an object of type ZonedDateTime
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
  ZonedDateTime(::Union{Period, TimeZone}...) at /home/oxinabox/.julia/packages/TimeZones/y3gf6/src/types/zoneddatetime.jl:136
Stacktrace:
 [1] setindex!(A::Vector{ZonedDateTime}, x::Millisecond, i1::Int64)
   @ Base ./array.jl:839
 [2] diff(r::StepRange{ZonedDateTime, Hour}; dims::Int64)
   @ Base ./multidimensional.jl:966
 [3] diff(r::StepRange{ZonedDateTime, Hour})
   @ Base ./multidimensional.jl:965
 [4] top-level scope
   @ REPL[32]:1

Interesting Julia gets this wrong, but doesn't error JuliaLang/julia#41336

If we collect it we get the right answer

julia> diff(collect(ZonedDateTime(DateTime(2021,1,1), tz"UTC"):Hour(1):ZonedDateTime(DateTime(2021,1,2), tz"UTC")))

24-element Vector{Millisecond}:
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
 3600000 milliseconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant