Add Duration helpers to time module

This commit is contained in:
Héctor Ramón Jiménez 2025-01-24 18:47:34 +01:00
parent 3a07c631ad
commit 3d893ae01b
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 40 additions and 19 deletions

View file

@ -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)
}