Restrictions on std::time::SystemTime


#1

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?


#2

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.


#3

@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.


#4

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.


#5

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