Skip to content

Commit 3a545c9

Browse files
committed
feat: adds support for millisecond slot timepoints
1 parent 5062916 commit 3a545c9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/utils/calc.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ 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+
pub fn current_point_within_slot_ms(&self) -> Option<u64> {
239+
let now = chrono::Utc::now();
240+
let timestamp = now.timestamp() as u64;
241+
let millis = now.timestamp_subsec_millis() as u64;
242+
243+
self.point_within_slot(timestamp).map(|point| {
244+
std::time::Duration::from_secs(point).as_millis() as u64 + millis
245+
})
246+
}
247+
237248
/// Calculates the slot that starts at the given timestamp.
238249
/// Returns `None` if the timestamp is not a slot boundary.
239250
/// Returns `None` if the timestamp is before the chain's start timestamp.

0 commit comments

Comments
 (0)