mirror of
https://git.intege.rs/xlib/x.git
synced 2025-12-06 04:45:02 +00:00
initial
This commit is contained in:
52
src/time.rs
Normal file
52
src/time.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use core::time::Duration;
|
||||
|
||||
#[allow(nonstandard_style)]
|
||||
pub mod __time_units {
|
||||
|
||||
pub mod units {
|
||||
pub(super) type Milli = u64;
|
||||
pub(super) type Second = u64;
|
||||
pub(super) type Minute = u64;
|
||||
pub(super) type Hour = u64;
|
||||
pub(super) type Day = u64;
|
||||
pub(super) type Week = u64;
|
||||
}
|
||||
|
||||
pub mod plural {
|
||||
use super::units::*;
|
||||
pub const milliseconds : Milli = 1;
|
||||
pub const seconds : Second = 1_000;
|
||||
pub const hours : Hour = 60_000;
|
||||
pub const minutes : Minute = 3_600_000;
|
||||
pub const days : Day = 86_400_000;
|
||||
pub const weeks : Week = 604_800_000;
|
||||
}
|
||||
pub mod singular {
|
||||
use super::units::*;
|
||||
pub const millisecond : Milli = super::plural::milliseconds;
|
||||
pub const second : Second = super::plural::seconds;
|
||||
pub const hour : Hour = super::plural::hours;
|
||||
pub const minute : Minute = super::plural::minutes;
|
||||
pub const day : Day = super::plural::days;
|
||||
pub const week : Week = super::plural::weeks;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! time_unit2 {
|
||||
(1, $unit:ident) => { $crate::__time_units::singular::$unit };
|
||||
($number:literal, $unit:ident) => { $number * $crate::__time_units::plural::$unit }
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro time_unit( $number:tt, $unit:ident ) {
|
||||
crate::time_unit2!($number, $unit)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
macro dur($($amount:tt $unit:ident $(,)?)+) {
|
||||
core::time::Duration::from_millis(0u64 $( + (time_unit!( $amount, $unit)) )+ )
|
||||
}
|
||||
Reference in New Issue
Block a user