File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name = "init4-bin-base"
33
44description = " Internal utilities for binaries produced by the init4 team"
55keywords = [" init4" , " bin" , " base" ]
6- version = " 0.18.0 -rc.0"
6+ version = " 0.18.1 -rc.0"
77edition = " 2021"
88rust-version = " 1.85"
99authors = [" init4" , " James Prestwich" , " evalir" ]
Original file line number Diff line number Diff line change @@ -234,6 +234,21 @@ impl SlotCalculator {
234234 self . point_within_slot ( chrono:: Utc :: now ( ) . timestamp ( ) as u64 )
235235 }
236236
237+ /// The current number of milliseconds into the slot.
238+ ///
239+ /// Truncates the millisecond timestamp to seconds, then uses that to
240+ /// calculate the point within the slot, adding back the milliseconds
241+ /// remainder to the final result to provide millisecond precision.
242+ pub fn current_point_within_slot_ms ( & self ) -> Option < u64 > {
243+ // NB: Only fetch from now() object once and reuse
244+ let timestamp_ms = chrono:: Utc :: now ( ) . timestamp_millis ( ) as u64 ;
245+ let timestamp_s = timestamp_ms / 1000 ;
246+ let fractional = timestamp_ms % 1000 ;
247+
248+ self . point_within_slot ( timestamp_s)
249+ . map ( |point| point * 1000 + fractional)
250+ }
251+
237252 /// Calculates the slot that starts at the given timestamp.
238253 /// Returns `None` if the timestamp is not a slot boundary.
239254 /// Returns `None` if the timestamp is before the chain's start timestamp.
You can’t perform that action at this time.
0 commit comments