Resolve date parsing ambiguity when parsing dates when "time/large-da… #35

Open
morganava wants to merge 1 commits from morganava/issue_34 into develop
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] [dev-dependencies]
quickcheck = "1.0.3" quickcheck = "1.0.3"
rand = "0.8.4" 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( 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(); .unwrap();
@@ -549,9 +553,13 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result<Vec<ASN1Block>, ASN1Decode
let idx = v.len() - 1; let idx = v.len() - 1;
v.insert(idx, '0'); 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( 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(); .unwrap();