@@ -20,31 +20,26 @@ pub mod instant_to_epoch_seconds {
20
20
. duration_since ( UNIX_EPOCH )
21
21
. expect ( "Time went backwards" ) ;
22
22
23
- let epoch_ms = epoch. as_millis ( ) as f64 / 1000.0 ;
23
+ let epoch_s = epoch. as_millis ( ) as f64 / 1000.0 ;
24
24
25
- epoch_ms . serialize ( serializer)
25
+ epoch_s . serialize ( serializer)
26
26
}
27
27
28
28
pub fn deserialize < ' de , D > ( deserializer : D ) -> Result < Instant , D :: Error >
29
29
where
30
30
D : Deserializer < ' de > ,
31
31
{
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) ;
35
34
36
35
let system_now = SystemTime :: now ( ) ;
37
36
let instant_now = Instant :: now ( ) ;
38
37
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;
47
42
48
- Ok ( adjusted_instant )
43
+ Ok ( instant )
49
44
}
50
45
}
0 commit comments