Different behavior on different platforms for Duration::from_nanos

Using MacOS If I were to do:

SystemTime::UNIX_EPOCH + Duration::from_nanos(134807553)

I get 134807553.

On Windows if I do the same I get 134807500.

Having trouble figuring out why.

Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

It's because Windows native time point type doesn't support sub-100ns precision.

2 Likes

Documented behavior.

The precision of SystemTime can depend on the underlying OS-specific time format. For example, on Windows the time is represented in 100 nanosecond intervals whereas Linux can represent nanosecond intervals.

3 Likes

thanks

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.