std-method
SystemTime::checked_add and checked_sub
Shift a wall-clock timestamp while handling platform range limits. Unlike constructing an Instant deadline, a wall-clock expiry is suited to stored or communicated timestamps; its evaluation is affected by clock adjustments. Expected stdout (not executed): true Common mistake: Assuming every representable Duration can be added to a SystemTime.
Formal Syntax & Structure
rust syntaxrust
t.checked_add(Duration) -> Option<SystemTime>; t.checked_sub(Duration) -> Option<SystemTime>Working Example
Example Snippetrust
fn main() { use std::time::{Duration, UNIX_EPOCH}; let t = UNIX_EPOCH.checked_add(Duration::from_secs(60)).unwrap(); println!("{}", t.checked_sub(Duration::from_secs(60)) == Some(UNIX_EPOCH));}