I have a really hard time understanding this:
julia> using Dates
julia> dt1 = DateTime(1)
0001-01-01T00:00:00
julia> for timeperiod in (Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
dt2 = dt1 + oneunit(timeperiod)
@show dt1 ≠ dt2
end
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = false
dt1 ≠ dt2 = false
Why are differences smaller than milliseconds ignored…? Has this been extensively covered somewhere…?
The underlying integer simply cannot represent that kind of a precision. Cf
using Dates
d = DateTime(1)
d2 = d + oneunit(Microsecond)
d.instant.periods.value == d2.instant.periods.value
OK, so I think I understand why it doesn’t work.
help?> DateTime
search: DateTime datetime2unix datetime2rata datetime2julian ISODateTimeFormat unix2datetime
DateTime
DateTime wraps a UTInstant{Millisecond} and interprets it according to the proleptic Gregorian
calendar.
But man, I can’t help think that it’s misleading to be able to add a Nanosecond, in fact 10^6 - 1
of them without noticing any difference. Hmm…
Like, if I want to be able to do arithmetic on DateTime
and Nanosecond
I guess I should convert everything to Millisecond
s…
Tamas_Papp:
julia> 1.0 + eps()/2 1.0
That is a really good point. OK. I’ll deal. Thanks again @Tamas_Papp !!!
1 Like
You could give TimesDates.jl a shot:
julia> using TimesDates,Dates
julia> dt1 = TimeDate(1)
0001-01-01T00:00:00
julia> for timeperiod in (Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
dt2 = dt1 + oneunit(timeperiod)
@show dt1 ≠ dt2
end
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
dt1 ≠ dt2 = true
2 Likes