this post was submitted on 30 Oct 2025
62 points (100.0% liked)
Rust
7466 readers
20 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.