chrono
chrono copied to clipboard
Consider adding a "Default" implementation to Duration
Would you consider having chrono::Duration
implement Default
, which would produce a zero-duration Duration
?
This would be consistent with std::time::Duration
Right now the implementation of the Duration
type depends on the Cargo features: it can be from time 0.1 or the internal version. The external version is enabled by default, so if we implement this only for the internal version, so this would make the oldtime
Cargo feature non-additive. On the other hand... I guess it already is?
Ah, I had forgotten about oldtime
. chrono::Duration
already had a slightly different API from time::Duration
. For example chrono::Duration
implements Hash
but time::Duration
does not. (Though otherwise their APIs are nearly identical).
Maybe chrono 0.5 could add a impl Default for Duration
?
I'd be happy to add that once we straighten out the compatibility situation.
What's the current state of this issue?
As far as I understood from @djc, the reason for not implementing Default was because std::time::Duration
didn't implement it in 0.1.x
.
As of 0.3.17
default is implemented, does that mean this is no longer "API-Incompatible" and could be implemented?
On the main branch (which will eventually become 0.5) we can add a Default
implementation to what's now called TimeDelta
. On the 0.4.x branch due to compatibility concerns that will not be viable.
You seem to be confusing the std::time::Duration
type with the Duration
type from the time crate. Due to compatibility, chrono 0.4.x will always (conditionally) depend on time 0.1, while chrono 0.5 does not depend on time at all.
You're right, I mistook std::time
with the time crate.
But if this time I checked right, as of 0.1.3
for std::time::Duration
, default is also implemented
Yes, but the Duration
we expose in chrono is actually the one from the time crate, so std::time::Duration
has no bearing on this issue.
@delightfulagony - if this https://github.com/chronotope/chrono/pull/860 or a linked PR gets merged, then you will be able to use std::time::Duration
directly, including its Default
implementation, would that satisfy your use case?
Yes, but the
Duration
we expose in chrono is actually the one from the time crate, sostd::time::Duration
has no bearing on this issue.
Oh ok, so I misunderstood you, alright, thank you
@delightfulagony - if this #860 or a linked PR gets merged, then you will be able to use
std::time::Duration
directly, including itsDefault
implementation, would that satisfy your use case?
I suppose it would, in any case I changed to using the time crate that also works for my needs, and since you folks are working on 5.x.x
don't worry about it, thank you for taking the time to answer and explain :smile:
You're both the best! :tada: :+1:
Added in https://github.com/chronotope/chrono/pull/1327.