Fix last modified properly

This commit is contained in:
FliegendeWurst 2024-11-08 18:33:26 +01:00
parent 13325554a4
commit 6e0dbcf006
2 changed files with 9 additions and 8 deletions

View File

@ -2,7 +2,7 @@
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "raspi-oled"; pname = "raspi-oled";
version = "unstable-infdev-6"; version = "unstable-infdev-7";
src = ./.; src = ./.;

View File

@ -208,16 +208,17 @@ pub fn get_new_notifications(
} }
let json = resp.call()?.into_string()?; let json = resp.call()?.into_string()?;
let items: Vec<Notification> = serde_json::from_str(&json)?; let items: Vec<Notification> = serde_json::from_str(&json)?;
let mut last_modified = items let new_last_modified = items
.get(0) .get(0)
.map(|x| x.updated_at.clone()) .map(|x| x.updated_at.clone());
.or_else(|| last_modified.map(|x| x.to_owned())); let last_modified = if let Some(lm) = new_last_modified {
if let Some(lm) = last_modified.as_mut() {
// parse and increase by one second // parse and increase by one second
let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z"); let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z");
let mut dt = PrimitiveDateTime::parse(lm, format)?; let mut dt = PrimitiveDateTime::parse(&lm, format)?;
dt += time::Duration::seconds(1); dt += time::Duration::seconds(1);
*lm = dt.format(&format)?; Some(dt.format(&format)?)
} } else {
last_modified.map(|x| x.to_owned())
};
Ok((items, last_modified)) Ok((items, last_modified))
} }