summaryrefslogtreecommitdiff
path: root/src/serde.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/serde.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/serde.rs b/src/serde.rs
index 9049d64..486929a 100644
--- a/src/serde.rs
+++ b/src/serde.rs
@@ -1,22 +1,33 @@
-use chrono::NaiveDateTime;
+use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{Deserialize, Deserializer};
-pub fn naive_read_unixtime<'de, D>(d: D) -> Result<NaiveDateTime, D::Error>
+pub fn naive_read_unixtime<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
where
D: Deserializer<'de>,
{
let ts = <i64>::deserialize(d)?;
- Ok(NaiveDateTime::from_timestamp(ts, 0))
+ Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(ts, 0), Utc))
}
-pub fn option_naive_read_unixtime<'de, D>(d: D) -> Result<Option<NaiveDateTime>, D::Error>
+pub fn option_naive_read_unixtime<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: Deserializer<'de>,
{
match <i64>::deserialize(d) {
Ok(ts) =>
- Ok(Some(NaiveDateTime::from_timestamp(ts, 0))),
+ Ok(Some(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(ts, 0), Utc))),
+ Err(_) => Ok(None)
+ }
+}
+
+pub fn option_naive_read_unixtime_db<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
+where
+ D: Deserializer<'de>,
+{
+ match <i64>::deserialize(d) {
+ Ok(ts) =>
+ Ok(Some(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(ts/1000, 0), Utc))),
Err(_) => Ok(None)
}
}