From 3d893ae01b64eb51b2f5854949c694090118e052 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 24 Jan 2025 18:47:34 +0100 Subject: Add `Duration` helpers to `time` module --- core/src/time.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'core/src/time.rs') diff --git a/core/src/time.rs b/core/src/time.rs index dcfe4e41..c6e30444 100644 --- a/core/src/time.rs +++ b/core/src/time.rs @@ -2,3 +2,28 @@ pub use web_time::Duration; pub use web_time::Instant; + +/// Creates a [`Duration`] representing the given amount of milliseconds. +pub fn milliseconds(milliseconds: u64) -> Duration { + Duration::from_millis(milliseconds) +} + +/// Creates a [`Duration`] representing the given amount of seconds. +pub fn seconds(seconds: u64) -> Duration { + Duration::from_secs(seconds) +} + +/// Creates a [`Duration`] representing the given amount of minutes. +pub fn minutes(minutes: u64) -> Duration { + seconds(minutes * 60) +} + +/// Creates a [`Duration`] representing the given amount of hours. +pub fn hours(hours: u64) -> Duration { + minutes(hours * 60) +} + +/// Creates a [`Duration`] representing the given amount of days. +pub fn days(days: u64) -> Duration { + hours(days * 24) +} -- cgit