From ed7c58cf4710dfc1b9164d1f3f3fb339e07f3d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 15 Sep 2020 12:20:50 +0200 Subject: [PATCH] time: add test for leap second parsing/converting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- 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 803c6c06..78d75b91 100644 --- a/proxmox/src/tools/time.rs +++ b/proxmox/src/tools/time.rs @@ -279,3 +279,26 @@ pub fn parse_rfc3339(i: &str) -> Result { 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); +}