They’re also a problem for adding seconds to system times, since one second duration could mean two seconds wall clock time. As mentioned in discussions, we accept this for seconds, but not daylight savings, which is odd IMO because leap seconds are more “real” than daylight savings.
Ideally, Duration should always represent multiples of logical seconds, and they only make sense in the context of a clock, either monotonic or system. There should be specialized functions for translating between the two (e.g. SystemTime::add_monotonic(Duration) and SystemTime.sub_monotonic(SystemTime)), which would account for leap seconds and daylight savings.
But all of that can live in an external crate like “chrono”. I just want a way to clearly communicate intent. In my case, I’m writing a ping test tool to find out how often my internet drops and I want to print logs hourly (make sure it’s still running) and daily (longer term logging purposes). This use case doesn’t need exact precision, it just needs to print roughly on a schedule (I’m running for a week or two, not multiple years). If I do actual time math, I’d use a specialized crate with clear documentation, but for something quick and dirty, I’d prefer to use the stdlib.
Leap seconds are already a problem for minutes and hours, which is probably why they weren’t added until now.
They’re also a problem for adding seconds to system times, since one second duration could mean two seconds wall clock time. As mentioned in discussions, we accept this for seconds, but not daylight savings, which is odd IMO because leap seconds are more “real” than daylight savings.
Ideally,
Durationshould always represent multiples of logical seconds, and they only make sense in the context of a clock, either monotonic or system. There should be specialized functions for translating between the two (e.g.SystemTime::add_monotonic(Duration)andSystemTime.sub_monotonic(SystemTime)), which would account for leap seconds and daylight savings.But all of that can live in an external crate like “chrono”. I just want a way to clearly communicate intent. In my case, I’m writing a ping test tool to find out how often my internet drops and I want to print logs hourly (make sure it’s still running) and daily (longer term logging purposes). This use case doesn’t need exact precision, it just needs to print roughly on a schedule (I’m running for a week or two, not multiple years). If I do actual time math, I’d use a specialized crate with clear documentation, but for something quick and dirty, I’d prefer to use the stdlib.