TimesDates.jl dev for v2

The fact that durations have time units is not an implementation detail but a part of the interface. It’s nice for the code to track what the units are. You can check whether the magnitude is zero with iszero though:

julia> iszero(Millisecond(0))
true

julia> iszero(Millisecond(1))
false

That statement itself is correct. But, the following two statements are totally different:

  1. Durations have time units.

  2. The smallest duration is 1 millisecond.

You are saying 1. The current implementation appears to expose 2. If you change the internal implementation to include microseconds, what would the output of (t2 - t1) % Dates.Hour(1) be?

That means, perhaps, we would get

julia> (t2 - t1) % Dates.Hour(1)
123.456 milliseconds

if DateTime started to resolve microseconds?

If that’s what you mean by that milliseconds is just an interface, not an implementation detail, then I agree with you.

Okay, that makes perfect sense! Then, I guess this documentation

https://docs.julialang.org/en/v1/stdlib/Dates/#Durations/Comparisons

should include iszero() in the “Comparisons” section. . . . (I’m not at all familiar with github and am still struggling to set it up for my account, so it would take a lot of time, which I don’t currently have, for me to be able to create a pull request. Sorry.)

My original issue was probably documentation problem or perhaps cultural. When I asked a question about DateTime arithmetic here in this forum when I was a total newbie, some people recommended solutions which assumed that the minimal duration step is one millisecond, using the .value attribute, if I remember correctly.

In hindsight, they should have recommended dividing by Millisecond(1) instead of referring to .value. Then nothing would have depended on the implementation detail.

The significance of milliseconds for the DateTime API has been debated recently on here and GitHub.

1 Like

By the way,

during the writing of my initial posting, I thought that even a unitful duration should be able to be compared with zero. We all understand that

1 minute ≠ 1 second

but zero is special. All zeros are equal, aren’t they? 0 minutes = 0 seconds = 0 milliseconds.

Even worse

julia> m = (t2 - t1) % Dates.Hour(1)
0 milliseconds
julia> m == 0
false

At least, shouldn’t m == 0 result in error? This can be a source of silent bugs.

Complex numbers do the right thing:

julia> a = 3 + 4.2im
3.0 + 4.2im

julia> a < 0
ERROR: MethodError: no method matching isless(::ComplexF64, ::Int64)

Are these unit-ed durations part of the Dates package? or does the package utilize unit-ed numbers defined elsewhere?

Yes