wrapper_chrono/
wrapper.rs

1use chrono::{DateTime, Duration, Local, Utc};
2use darth_rust::DarthRust;
3
4#[derive(Debug, DarthRust)]
5pub struct WrapperChrono {
6    pub time: i64,
7}
8pub trait ChronoTrait {
9    fn utc_add_time_by_weeks(&self) -> DateTime<Utc>;
10    fn utc_add_time_by_days(&self) -> DateTime<Utc>;
11    fn utc_add_time_by_hours(&self) -> DateTime<Utc>;
12    fn utc_add_time_by_minutes(&self) -> DateTime<Utc>;
13    fn utc_add_time_by_seconds(&self) -> DateTime<Utc>;
14    fn local_add_time_by_weeks(&self) -> DateTime<Local>;
15    fn local_add_time_by_days(&self) -> DateTime<Local>;
16    fn local_add_time_by_hours(&self) -> DateTime<Local>;
17    fn local_add_time_by_minutes(&self) -> DateTime<Local>;
18    fn local_add_time_by_seconds(&self) -> DateTime<Local>;
19    fn date_utc_is_expired(expiration_date: DateTime<Utc>) -> bool;
20    fn date_local_is_expired(expiration_date: DateTime<Local>) -> bool;
21    fn new_date_utc_now() -> DateTime<Utc>;
22    fn new_date_local_now() -> DateTime<Local>;
23    fn duration_sec(&self) -> Duration;
24    fn duration_hours(&self) -> Duration;
25    fn duration_minutes(&self) -> Duration;
26    fn duration_days(&self) -> Duration;
27    fn duration_weeks(&self) -> Duration;
28}
29
30impl ChronoTrait for WrapperChrono {
31    fn duration_sec(&self) -> Duration {
32        let time = self.time;
33        Duration::seconds(time)
34    }
35    fn duration_hours(&self) -> Duration {
36        let time = self.time;
37        Duration::hours(time)
38    }
39    fn duration_days(&self) -> Duration {
40        let time = self.time;
41        Duration::days(time)
42    }
43    fn duration_minutes(&self) -> Duration {
44        let time = self.time;
45        Duration::minutes(time)
46    }
47    fn duration_weeks(&self) -> Duration {
48        let time = self.time;
49        Duration::weeks(time)
50    }
51    fn utc_add_time_by_hours(&self) -> DateTime<Utc> {
52        let now = Self::new_date_utc_now();
53        let duration = self.duration_hours();
54        now + duration
55    }
56    fn utc_add_time_by_minutes(&self) -> DateTime<Utc> {
57        let now = Self::new_date_utc_now();
58        let duration = self.duration_minutes();
59        now + duration
60    }
61    fn utc_add_time_by_seconds(&self) -> DateTime<Utc> {
62        let now = Self::new_date_utc_now();
63        let duration = self.duration_sec();
64        now + duration
65    }
66    fn utc_add_time_by_weeks(&self) -> DateTime<Utc> {
67        let now = Self::new_date_utc_now();
68        let duration = self.duration_weeks();
69        now + duration
70    }
71    fn utc_add_time_by_days(&self) -> DateTime<Utc> {
72        let now = Self::new_date_utc_now();
73        let duration = self.duration_days();
74        now + duration
75    }
76    fn local_add_time_by_minutes(&self) -> DateTime<Local> {
77        let now = Self::new_date_local_now();
78        let duration = self.duration_minutes();
79        now + duration
80    }
81    fn local_add_time_by_weeks(&self) -> DateTime<Local> {
82        let now = Self::new_date_local_now();
83        let duration = self.duration_weeks();
84        now + duration
85    }
86    fn local_add_time_by_seconds(&self) -> DateTime<Local> {
87        let now = Self::new_date_local_now();
88        let duration = self.duration_sec();
89        now + duration
90    }
91    fn local_add_time_by_hours(&self) -> DateTime<Local> {
92        let now = Self::new_date_local_now();
93        let duration = self.duration_hours();
94        now + duration
95    }
96    fn local_add_time_by_days(&self) -> DateTime<Local> {
97        let now = Self::new_date_local_now();
98        let duration = self.duration_days();
99        now + duration
100    }
101    fn new_date_local_now() -> DateTime<Local> {
102        Local::now()
103    }
104    fn new_date_utc_now() -> DateTime<Utc> {
105        Utc::now()
106    }
107    fn date_utc_is_expired(expiration_date: DateTime<Utc>) -> bool {
108        let now = Self::new_date_utc_now();
109        now > expiration_date
110    }
111    fn date_local_is_expired(expiration_date: DateTime<Local>) -> bool {
112        let now = Self::new_date_local_now();
113        now > expiration_date
114    }
115}