Skip to content

switch impl From<Timestamp> for std::time::SystemTime to TryFrom #467

@BurntSushi

Description

@BurntSushi

Specifically, here is the current impl:

jiff/src/timestamp.rs

Lines 2815 to 2831 in 42d83ff

#[cfg(feature = "std")]
impl From<Timestamp> for std::time::SystemTime {
#[inline]
fn from(time: Timestamp) -> std::time::SystemTime {
let unix_epoch = std::time::SystemTime::UNIX_EPOCH;
let sdur = time.as_duration();
let dur = sdur.unsigned_abs();
// These are guaranteed to succeed because we assume that SystemTime
// uses at least 64 bits for the time, and our durations are capped via
// the range on UnixSeconds.
if sdur.is_negative() {
unix_epoch.checked_sub(dur).expect("duration too big (negative)")
} else {
unix_epoch.checked_add(dur).expect("duration too big (positive)")
}
}
}

It specifically notes that we assume a SystemTime always uses 64 bits. But this is not a documented guarantee. And indeed, it turns out it's not always true: rust-lang/rust#150505

This is a breaking change, so it will need to be part of the Jiff 1.0 release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeIssues that require a breaking change for resolution.bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions