Julia: Inconsistent resulting types for zero and one for Dates

Created on 1 Jun 2020  Â·  3Comments  Â·  Source: JuliaLang/julia

julia> using Dates

julia> x = Date(2020):Week(1):Date(2021)
2020-01-01:1 week:2020-12-30

julia> dx = step(x)
1 week

julia> zero(dx)
0 weeks

julia> one(dx)
1

CC @mcabbott

Most helpful comment

It's on purpose the one doesn't have units. That's why there is oneunit

julia> oneunit(dx)
1 week

All 3 comments

I presume the reasoning is this:

julia> one(dx) * Week(3)
3 weeks

julia> zero(dx) + Week(3)
3 weeks

It's on purpose the one doesn't have units. That's why there is oneunit

julia> oneunit(dx)
1 week

That makes sense.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yurivish picture yurivish  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

m-j-w picture m-j-w  Â·  3Comments

omus picture omus  Â·  3Comments

manor picture manor  Â·  3Comments