quantities/duration.rs
1// ---------------------------------------------------------------------------
2// Copyright: (c) 2022 ff. Michael Amrhein (michael@adrhinum.de)
3// License: This program is part of a larger application. For license
4// details please read the file LICENSE.TXT provided together
5// with the application.
6// ---------------------------------------------------------------------------
7// $Source: src/duration.rs $
8// $Revision: 2022-04-16T08:18:48+02:00 $
9
10//! Definition of basic quantity `Duration`.
11
12use crate::prelude::*;
13
14#[quantity]
15#[ref_unit(Second, "s", NONE, "Reference unit of quantity `Duration`")]
16#[unit(Nanosecond, "ns", NANO, 0.000000001, "0.000000001·s")]
17#[unit(Microsecond, "µs", MICRO, 0.000001, "0.000001·s")]
18#[unit(Millisecond, "ms", MILLI, 0.001, "0.001·s")]
19#[unit(Minute, "min", 60, "60·s")]
20#[unit(Hour, "h", 3600, "60·min")]
21#[unit(Day, "d", 86400, "24·h")]
22/// Duration: 'what a clock reads'
23///
24/// Reference unit: Second ('s')
25///
26/// Predefined units:
27///
28/// | Symbol | Name | Definition | Equivalent in 's' |
29/// |--------|-----------------------|-------------------|---------------------|
30/// | ns | Nanosecond | 0.000000001·s | 0.000000001 |
31/// | µs | Microsecond | 0.000001·s | 0.000001 |
32/// | ms | Millisecond | 0.001·s | 0.001 |
33/// | min | Minute | 60·s | 60 |
34/// | h | Hour | 60·min | 3600 |
35/// | d | Day | 24·h | 86400 |
36pub struct Duration {}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_duration() {
44 let amnt: AmountT = Amnt!(29.35);
45 let d = amnt * MILLISECOND;
46 assert_eq!(d.amount, amnt);
47 assert_eq!(d.unit, MILLISECOND);
48 #[cfg(feature = "std")]
49 assert_eq!(d.to_string(), "29.35 ms");
50 }
51}