Restrictions on std::time::SystemTime

Are there any restrictions on what values are allowed for SystemTime? There are various platform implementations in std that are unable to represent a SystemTime before SystemTime::UNIX_EPOCH, although there’s a test in std that creates a SystemTime of one second before UNIX_EPOCH. Is an application allowed to create arbitrary SystemTime values?

No, SystemTime is an opaque type and the only way to create it is via now method. I think you may want to look into chrono crate instead of using std::time.

@newpavlov That’s not what I meant. You can always create SystemTime values by taking a current reference and adding/substracting any Duration. The question is whether there is, or should be, a limit to the range of values that’s supposed to be supported that way.

The docs for functions like checked_add and add state that there are (unspecified) bounds on “the underlying data structure” and describe their behavior if values go outside those bounds.

2 Likes

See https://github.com/rust-lang/rust/pull/55527#issuecomment-472203033

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.