Clock that ticks at the beginning of each minute
⚓ Rust 📅 2026-03-07 👤 surdeus 👁️ 1I'm writing a status bar, and i want to have a clock widget, displaying the current time with minute precision.
In order to integrate well with the rest of the widgets, i wanted to manage the clock update using a stream that yields "please update the time" each minute.
However, if i just use a timer that yields events every minute (like tokio::time::interval), if that timer happens to start at 12:00:59, it will almost always be one minute behind the true clock (displaying 12:00 from 12:00:59 to 12:01:58, etc...)
I looked for a way to round the time up to a minute, and found time::UtcDateTime, which does allow truncation. However, it seems that it is impossible to construct an Instant from a UtcDateTime, so i can't use that either.
What is the way to go for implementing a clock that ticks at the beginning of each minute ?
2 posts - 2 participants
🏷️ Rust_feed