Skip to content

Commit

Permalink
refactor(state_keeper): switch from milliseconds to seconds in time u…
Browse files Browse the repository at this point in the history
…tils

Resolves SMA-1206

- Renamed millis_since_epoch() to seconds_since_epoch()
- Changed time representation from milliseconds to seconds
- Updated millis_since() to work with seconds while maintaining its interface
- Improved type safety by using u64 instead of u128
  • Loading branch information
VolodymyrBg authored Jan 11, 2025
1 parent 361243f commit 50fa51d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions core/node/state_keeper/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ pub(super) fn is_canceled(stop_receiver: &watch::Receiver<bool>) -> bool {
*stop_receiver.borrow()
}

// TODO (SMA-1206): use seconds instead of milliseconds.
pub(super) fn millis_since_epoch() -> u128 {
pub(super) fn seconds_since_epoch() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Incorrect system time")
.as_millis()
.as_secs()
}

pub(super) fn millis_since(since: u64) -> u64 {
(millis_since_epoch() - since as u128 * 1000) as u64
(seconds_since_epoch() - since) * 1000
}

0 comments on commit 50fa51d

Please sign in to comment.