From fa7816f3582ed8c847e564200efc4ebeda3dc9ed Mon Sep 17 00:00:00 2001 From: Morgan Date: Sun, 22 Sep 2024 19:56:12 +0000 Subject: [PATCH] Resolve date parsing ambiguity when parsing dates when "time/large-dates" feature is enabled - add explicit delimitter between year and month in date parsing format string - enable "time/large-dates" feature to dev-dependencies resolves #34 --- Cargo.toml | 2 +- src/lib.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c77dc1b..a56e8e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ time = { default-features = false, version = "0.3", features = ["formattin [dev-dependencies] quickcheck = "1.0.3" rand = "0.8.4" -time = { default-features = false, version = "0.3", features = ["formatting", "macros", "parsing", "quickcheck"] } +time = { default-features = false, version = "0.3", features = ["formatting", "large-dates", "macros", "parsing", "quickcheck"] } diff --git a/src/lib.rs b/src/lib.rs index 3d990d3..2728a0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -515,10 +515,14 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result, ASN1Decode } }; - let v = format!("{}{}", y_prefix, v); + let mut v = format!("{}{}", y_prefix, v); + // add a manual delimitter between known year position and rest of the + // date string to handle ambiguities when "time/large-dates" feature is + // enabled + v.insert(4, ':'); let format = time::format_description::parse( - "[year][month][day][hour repr:24][minute][second]Z", + "[year]:[month][day][hour repr:24][minute][second]Z", ) .unwrap(); @@ -549,9 +553,13 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result, ASN1Decode let idx = v.len() - 1; v.insert(idx, '0'); } + // add a manual delimitter between known year position and rest of the + // date string to handle ambiguities when "time/large-dates" feature is + // enabled + v.insert(4, ':'); let format = time::format_description::parse( - "[year][month][day][hour repr:24][minute][second].[subsecond]Z", + "[year]:[month][day][hour repr:24][minute][second].[subsecond]Z", ) .unwrap();