-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
serde_millis
where appropriate instead of builtin serde
- Loading branch information
Showing
5 changed files
with
10 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,6 @@ | ||
use std::time::{SystemTime, Duration, UNIX_EPOCH}; | ||
|
||
use serde::Serializer; | ||
|
||
|
||
fn tstamp_to_ms(tm: SystemTime) -> u64 { | ||
let ts = tm.duration_since(UNIX_EPOCH) | ||
.expect("timestamp is always after unix epoch"); | ||
return ts.as_secs()*1000 + (ts.subsec_nanos() / 1000000) as u64; | ||
} | ||
|
||
pub fn ms_to_system_time(ms: u64) -> SystemTime { | ||
UNIX_EPOCH + Duration::from_millis(ms) | ||
} | ||
|
||
pub fn serialize_timestamp<S>(tm: &SystemTime, ser: S) | ||
-> Result<S::Ok, S::Error> | ||
where S: Serializer | ||
{ | ||
ser.serialize_u64(tstamp_to_ms(*tm)) | ||
} | ||
|
||
pub fn serialize_opt_timestamp<S>(tm: &Option<SystemTime>, ser: S) | ||
-> Result<S::Ok, S::Error> | ||
where S: Serializer | ||
{ | ||
match *tm { | ||
Some(ts) => { | ||
ser.serialize_some(&tstamp_to_ms(ts)) | ||
} | ||
None => { | ||
ser.serialize_none() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters