Browse Source

Correct handling of pre-epoch timestamps

Fix an off-by-one on the seconds when subseconds are present, and
correct display of nenoseconds, which are of course inverted due to the
internal value being negative.
Thomas Hurst 5 years ago
parent
commit
d2d2e7325f
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/output/time.rs

+ 11 - 2
src/output/time.rs

@@ -185,14 +185,23 @@ fn systemtime_epoch(time: SystemTime) -> i64 {
     time
         .duration_since(UNIX_EPOCH)
         .map(|t| t.as_secs() as i64)
-        .unwrap_or_else(|e| -(e.duration().as_secs() as i64))
+        .unwrap_or_else(|e| {
+            -(e.duration().as_secs() as i64) - e.duration().subsec_nanos().min(1) as i64
+        })
 }
 
 fn systemtime_nanos(time: SystemTime) -> u32 {
     time
         .duration_since(UNIX_EPOCH)
         .map(|t| t.subsec_nanos())
-        .unwrap_or_else(|e| e.duration().subsec_nanos())
+        .unwrap_or_else(|e| {
+            let nanos = e.duration().subsec_nanos();
+            if nanos == 0 {
+                0
+            } else {
+                1_000_000_000 - nanos
+            }
+        })
 }
 
 #[allow(trivial_numeric_casts)]