[pbs-devel] [RFC proxmox 1/5] time: add test for leap second parsing/converting

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Sep 15 12:20:50 CEST 2020


Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    test fails, fixed by next patch

 proxmox/src/tools/time.rs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/proxmox/src/tools/time.rs b/proxmox/src/tools/time.rs
index 803c6c0..78d75b9 100644
--- a/proxmox/src/tools/time.rs
+++ b/proxmox/src/tools/time.rs
@@ -279,3 +279,26 @@ pub fn parse_rfc3339(i: &str) -> Result<i64, Error> {
         Ok(epoch)
     }).map_err(|err| format_err!("parse_rfc_3339 failed - {}", err))
 }
+
+#[test]
+fn test_leap_seconds() {
+    let convert_reconvert = |epoch| {
+        let rfc3339 = epoch_to_rfc3339_utc(epoch)
+            .expect("leap second epoch to rfc3339 should work");
+
+        let parsed = parse_rfc3339(&rfc3339)
+            .expect("parsing converted leap second epoch should work");
+
+        assert_eq!(epoch, parsed);
+    };
+
+    // 2005-12-31T23:59:59Z was followed by a leap second
+    let epoch = 1136073599;
+    convert_reconvert(epoch);
+    convert_reconvert(epoch + 1);
+    convert_reconvert(epoch + 2);
+
+    let parsed = parse_rfc3339("2005-12-31T23:59:60Z")
+        .expect("parsing leap second should work");
+    assert_eq!(parsed, epoch + 1);
+}
-- 
2.20.1






More information about the pbs-devel mailing list