You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implementation of StdClock is not monotonic. #4330
This type is guaranteed to be monotonic, i.e. if two instants are compared, the later one will always be greater than the earlier one. It is also always guaranteed to be greater than
or equal to the Unix epoch.
Distinct from the Instant type, this time measurement is not monotonic. This means that you can save a file to the file system, then save another file to the file system, and the second file has a SystemTime measurement earlier than the first. In other words, an operation that happens after another operation in real time may have an earlier SystemTime!
This makes it possible to break the invariants of JsInstant.
Heyy @jedel1043
Good catch, you’re right about the mismatch here. JsInstant promises monotonicity, but StdClock currently uses SystemTime, which doesn’t guarantee that.
I’m planning to look into this and see what the best fix would be, likely involving a monotonic time source. I’ll follow up with a PR once I’ve had a chance to investigate.
While working on this (PR #4652 ), I ran into a failing test locally:
builtins::date::tests::date_proto_set_utc_hours
The failure is a mismatch between two numeric timestamps:
left: 1594208775779.0
right: 1594206975779.0
The difference is exactly 30 minutes (1800000 ms), which suggests a local time‑zone / offset issue.
As far as I can tell, this test uses helpers like timestamp_from_utc and from_local from the time crate to compute expected values. Those helpers do not go through the engine Clock / StdClock, so this seems independent of the monotonic StdClock change.
Activity
abhinavs1920 commentedon Feb 21, 2026
Heyy @jedel1043
Good catch, you’re right about the mismatch here. JsInstant promises monotonicity, but StdClock currently uses SystemTime, which doesn’t guarantee that.
I’m planning to look into this and see what the best fix would be, likely involving a monotonic time source. I’ll follow up with a PR once I’ve had a chance to investigate.
Thanks for flagging this.
abhinavs1920 commentedon Feb 21, 2026
While working on this (PR #4652 ), I ran into a failing test locally:
The failure is a mismatch between two numeric timestamps:
The difference is exactly 30 minutes (1800000 ms), which suggests a local time‑zone / offset issue.
As far as I can tell, this test uses helpers like timestamp_from_utc and from_local from the
timecrate to compute expected values. Those helpers do not go through the engine Clock / StdClock, so this seems independent of the monotonic StdClock change.abhinavs1920 commentedon Mar 3, 2026
Heyy @jedel1043 ..
I have a clarification question: Would you prefer JsInstant to be purely monotonic and independent from system time?
jedel1043 commentedon Mar 3, 2026
Yes, to mirror what
Instantisabhinavs1920 commentedon Mar 3, 2026
Got it, that makes sense. I’ll update the implementation to mirror Instant semantics and remove any system-time dependency.
fix: Make StdClock monotonic using std::time::Instant (#4841)