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
This commit is contained in:
Morgan
2024-09-22 19:56:12 +00:00
parent 74719369dd
commit fa7816f358
2 changed files with 12 additions and 4 deletions

View File

@@ -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"] }

View File

@@ -515,10 +515,14 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result<Vec<ASN1Block>, 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<Vec<ASN1Block>, 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();