@@ -20,31 +20,26 @@ pub mod instant_to_epoch_seconds {
2020 . duration_since ( UNIX_EPOCH )
2121 . expect ( "Time went backwards" ) ;
2222
23- let epoch_ms = epoch. as_millis ( ) as f64 / 1000.0 ;
23+ let epoch_s = epoch. as_millis ( ) as f64 / 1000.0 ;
2424
25- epoch_ms . serialize ( serializer)
25+ epoch_s . serialize ( serializer)
2626 }
2727
2828 pub fn deserialize < ' de , D > ( deserializer : D ) -> Result < Instant , D :: Error >
2929 where
3030 D : Deserializer < ' de > ,
3131 {
32- let epoch_seconds: f64 = Deserialize :: deserialize ( deserializer) ?;
33-
34- let since_epoch = Duration :: from_secs_f64 ( epoch_seconds) ;
32+ let epoch_s = f64:: deserialize ( deserializer) ?;
33+ let epoch_duration = Duration :: from_secs_f64 ( epoch_s) ;
3534
3635 let system_now = SystemTime :: now ( ) ;
3736 let instant_now = Instant :: now ( ) ;
3837
39- let deserialized_system_time = UNIX_EPOCH + since_epoch;
40-
41- let adjustment = match deserialized_system_time. duration_since ( system_now) {
42- Ok ( duration) => -duration. as_secs_f64 ( ) ,
43- Err ( e) => e. duration ( ) . as_secs_f64 ( ) ,
44- } ;
45-
46- let adjusted_instant = instant_now + Duration :: from_secs_f64 ( adjustment) ;
38+ let duration_since_approx = system_now
39+ . duration_since ( UNIX_EPOCH + epoch_duration)
40+ . expect ( "Time went backwards" ) ;
41+ let instant = instant_now - duration_since_approx;
4742
48- Ok ( adjusted_instant )
43+ Ok ( instant )
4944 }
5045}
0 commit comments