Skip to content

Commit

Permalink
fix: assume UTC when parsing package_release_date (#18)
Browse files Browse the repository at this point in the history
see chronotope/chrono#1321 for more context
  • Loading branch information
samcday authored Dec 24, 2024
1 parent 5c56e33 commit 2a2baf7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/api/structs/digital_item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::util::make_string_fs_safe;

use chrono::{DateTime, Datelike};
use chrono::{DateTime, Datelike, NaiveDateTime};

Check failure on line 3 in src/api/structs/digital_item.rs

View workflow job for this annotation

GitHub Actions / build-windows

unused import: `DateTime`
use serde::{self, Deserialize};
use std::{collections::HashMap, path::Path};

Expand Down Expand Up @@ -47,9 +47,12 @@ impl DigitalItem {

pub fn release_year(&self) -> String {
match &self.package_release_date {
Some(d) => match DateTime::parse_from_str(d, FORMAT) {
Ok(dt) => dt.year().to_string(),
Err(_) => String::from("0000"),
Some(d) => match NaiveDateTime::parse_from_str(d, FORMAT) {
Ok(dt) => dt.and_utc().year().to_string(),
Err(err) => {
debug!("Failed to parse date time: {}", err);
String::from("0000")
},
},
None => String::from("0000"),
}
Expand Down

0 comments on commit 2a2baf7

Please sign in to comment.