1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
pub fn chrono_datetime_now() -> DateTime<Utc> {
Utc::now()
}
pub fn chrono_into_bson<T: chrono::TimeZone>(data: DateTime<T>) -> bson::DateTime {
bson::DateTime::from_chrono(data)
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Timestamp(i64);
impl Timestamp {
pub fn new(data: i64) -> Self {
Self(data)
}
pub fn now() -> DateTime<Utc> {
chrono_datetime_now()
}
pub fn chrono_to_bson(&self, data: crate::ChronoDateTime) -> bson::DateTime {
chrono_into_bson::<Utc>(data)
}
pub fn timestamp() -> i64 {
Self::now().timestamp()
}
}
impl Default for Timestamp {
fn default() -> Self {
Self::new(Self::timestamp())
}
}