epoch_converter/
lib.rs

1pub mod epoch_units;
2mod timestamp;
3pub mod units;
4
5#[cfg(test)]
6mod tests {
7    use crate::epoch_units::epoch_units;
8    use crate::units::units;
9    // Test units()
10    #[test]
11    fn test_seconds() {
12        assert_eq!(1, units(1).seconds);
13        assert_eq!(10, units(10).seconds);
14    }
15
16    #[test]
17    fn test_minutes() {
18        assert_eq!(1, units(60).minutes);
19        assert_eq!(10, units(600).minutes);
20    }
21
22    #[test]
23    fn test_hours() {
24        assert_eq!(1, units(3600).hours);
25        assert_eq!(10, units(36000).hours);
26    }
27
28    #[test]
29    fn test_days() {
30        assert_eq!(1, units(86400).days);
31        assert_eq!(10, units(864000).days);
32    }
33
34    #[test]
35    fn test_weeks() {
36        assert_eq!(1, units(604800).weeks);
37        assert_eq!(10, units(6048000).weeks);
38    }
39
40    #[test]
41    fn test_months() {
42        assert_eq!(1, units(2629743).months);
43        assert_eq!(10, units(26297430).months);
44    }
45
46    #[test]
47    fn test_years() {
48        assert_eq!(1, units(31556926).years);
49        assert_eq!(10, units(315569260).years);
50    }
51
52    // Test epoch_units(), using epoch time 1000000000, which is Sunday, September 9, 2001 1:46:40 AM UTC±00:00.
53    #[test]
54    fn test_epoch_seconds() {
55        assert_eq!(63135769600, epoch_units(1000000000).seconds)
56    }
57
58    #[test]
59    fn test_epoch_minutes() {
60        assert_eq!(1052262826, epoch_units(1000000000).minutes)
61    }
62
63    #[test]
64    fn test_epoch_hours() {
65        assert_eq!(17537713, epoch_units(1000000000).hours)
66    }
67
68    #[test]
69    fn test_epoch_days() {
70        assert_eq!(730738, epoch_units(1000000000).days)
71    }
72
73    #[test]
74    fn test_epoch_weeks() {
75        assert_eq!(104390, epoch_units(1000000000).weeks)
76    }
77
78    #[test]
79    fn test_epoch_months() {
80        assert_eq!(24008, epoch_units(1000000000).months)
81    }
82    #[test]
83    fn test_epoch_years() {
84        assert_eq!(2001, epoch_units(1000000000).years)
85    }
86
87    // Test epoch_units()'s check and convert
88    #[test]
89    fn milliseconds_convert() {
90        assert_eq!(63135769600, epoch_units(1000000000000).seconds)
91    }
92
93    #[test]
94    fn microseconds_convert() {
95        assert_eq!(63135769600, epoch_units(1000000000000000).seconds)
96    }
97
98    #[test]
99    fn nanoseconds_convert() {
100        assert_eq!(63135769600, epoch_units(1000000000000000000).seconds)
101    }
102
103    #[test]
104    fn maximum_time() {
105        dbg!(epoch_units(18446744073709551615));
106        assert_eq!(2554, epoch_units(18446744073709551615).years);
107    }
108}