all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 3/5] time: add tests for RFC3339 corner cases
Date: Tue, 15 Sep 2020 12:20:52 +0200	[thread overview]
Message-ID: <20200915102054.2866527-4-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20200915102054.2866527-1-f.gruenbichler@proxmox.com>

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

Notes:
    test fails untils next patch

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

diff --git a/proxmox/src/tools/time.rs b/proxmox/src/tools/time.rs
index f7faade..5747854 100644
--- a/proxmox/src/tools/time.rs
+++ b/proxmox/src/tools/time.rs
@@ -302,3 +302,57 @@ fn test_leap_seconds() {
         .expect("parsing leap second should work");
     assert_eq!(parsed, epoch + 1);
 }
+
+#[test]
+fn test_rfc3339_range() {
+    // also tests single-digit years/first decade values
+    let lower = -62167219200;
+    let lower_str = "0000-01-01T00:00:00Z";
+
+    let upper = 253402300799;
+    let upper_str = "9999-12-31T23:59:59Z";
+
+    let converted = epoch_to_rfc3339_utc(lower)
+        .expect("converting lower bound of RFC3339 range should work");
+    assert_eq!(converted, lower_str);
+
+    let converted = epoch_to_rfc3339_utc(upper)
+        .expect("converting upper bound of RFC3339 range should work");
+    assert_eq!(converted, upper_str);
+
+    let parsed = parse_rfc3339(lower_str)
+        .expect("parsing lower bound of RFC3339 range should work");
+    assert_eq!(parsed, lower);
+
+    let parsed = parse_rfc3339(upper_str)
+        .expect("parsing upper bound of RFC3339 range should work");
+    assert_eq!(parsed, upper);
+
+    epoch_to_rfc3339_utc(lower-1)
+        .expect_err("converting below lower bound of RFC3339 range should fail");
+
+    epoch_to_rfc3339_utc(upper+1)
+        .expect_err("converting above upper bound of RFC3339 range should fail");
+
+    let first_century = -59011459201;
+    let first_century_str = "0099-12-31T23:59:59Z";
+
+    let converted = epoch_to_rfc3339_utc(first_century)
+        .expect("converting epoch representing first century year should work");
+    assert_eq!(converted, first_century_str);
+
+    let parsed = parse_rfc3339(first_century_str)
+        .expect("parsing first century string should work");
+    assert_eq!(parsed, first_century);
+
+    let first_millenium = -59011459200;
+    let first_millenium_str = "0100-01-01T00:00:00Z";
+
+    let converted = epoch_to_rfc3339_utc(first_millenium)
+        .expect("converting epoch representing first millenium year should work");
+    assert_eq!(converted, first_millenium_str);
+
+    let parsed = parse_rfc3339(first_millenium_str)
+        .expect("parsing first millenium string should work");
+    assert_eq!(parsed, first_millenium);
+}
-- 
2.20.1





  parent reply	other threads:[~2020-09-15 10:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-15 10:20 [pbs-devel] [PATCH proxmox 0/5] time conversion tests and fixes Fabian Grünbichler
2020-09-15 10:20 ` [pbs-devel] [RFC proxmox 1/5] time: add test for leap second parsing/converting Fabian Grünbichler
2020-09-15 11:35   ` Thomas Lamprecht
2020-09-15 10:20 ` [pbs-devel] [RFC proxmox 2/5] time: allow leap seconds when parsing RFC3339 Fabian Grünbichler
2020-09-15 10:20 ` Fabian Grünbichler [this message]
2020-09-15 10:20 ` [pbs-devel] [PATCH proxmox 4/5] time/rfc3339: add leading zeroes for years < 1000 Fabian Grünbichler
2020-09-15 10:20 ` [pbs-devel] [PATCH proxmox 5/5] time: add tests for gmtime range Fabian Grünbichler
2020-09-15 11:48 ` [pbs-devel] applied: [PATCH proxmox 0/5] time conversion tests and fixes Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200915102054.2866527-4-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal