Skip to content

Commit

Permalink
consider timestamp without colon in offset as wrong date
Browse files Browse the repository at this point in the history
refactor when chronotope/chrono#1083 will land
  • Loading branch information
Lurk committed Oct 14, 2023
1 parent fbca2bb commit d2d3ae5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/nodes/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ impl Deserializer for Metadata {
if line.starts_with("header: ") {
meta.header = Some(line.replace("header: ", ""));
} else if line.starts_with("timestamp: ") {
meta.timestamp = DateTime::parse_from_str(
line.replace("timestamp: ", "").as_str(),
"%Y-%m-%d %H:%M:%S %z",
)
.ok();
// remove this when %:z works as expected
if line.trim().chars().rev().nth(5) == Some('+') {
meta.timestamp = DateTime::parse_from_str(
line.replace("timestamp: ", "").as_str(),
// %:z does not work as expected
// https://github.com/chronotope/chrono/pull/1083
"%Y-%m-%d %H:%M:%S %:z",
)
.ok();
}
} else if line.starts_with("image: ") {
meta.image = Some(line.replace("image: ", ""));
} else if line.starts_with("preview: ") {
Expand Down Expand Up @@ -213,6 +218,10 @@ mod tests {

#[test]
fn deserialize_wrong_date() {
assert_eq!(
Metadata::deserialize("timestamp: 2022-01-01 00:00:00 +0200\n^^^\n\n"),
Some(Metadata::new::<&str>(None, None, None, None, None))
);
assert_eq!(
Metadata::deserialize("timestamp: 2022-01-01 00:00:00\n^^^\n\n"),
Some(Metadata::new::<&str>(None, None, None, None, None))
Expand Down

0 comments on commit d2d3ae5

Please sign in to comment.