Skip to content

Timestamp::from_nanosecond panics instead of returning an error when the result is outside of a Timestamp #645

Description

@sorairolake

According to the documentation for jiff 0.2.35, Timestamp::from_nanosecond returns an error if the given nanosecond corresponds to a timestamp outside of the Timestamp::MIN and Timestamp::MAX boundaries, but in reality, it panics.


https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=c02ff9f67dcd030ca1b2e3181b1b24c6

let min = Timestamp::MIN.as_nanosecond();
let _ = Timestamp::from_nanosecond(min - 1);
thread 'main' (61) panicked at /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-core-0.1.0/src/timestamp.rs:103:9:
assertion failed: secs != b::UnixEpochSeconds::MIN || nanos >= 0

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=05bb30d0c763a64980bbc5040e22a5f5

let max = Timestamp::MAX.as_nanosecond();
let _ = Timestamp::from_nanosecond(max + 1);
thread 'main' (14) panicked at /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/jiff-core-0.1.0/src/timestamp.rs:101:9:
assertion failed: b::UnixEpochSeconds::checkc(secs).is_ok()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions