From 6e0dbcf006225df7a636ba9eecc28bb899348073 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 8 Nov 2024 18:33:26 +0100 Subject: [PATCH] Fix last modified properly --- default.nix | 2 +- src/github.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/default.nix b/default.nix index 8508dbf..240fa50 100644 --- a/default.nix +++ b/default.nix @@ -2,7 +2,7 @@ rustPlatform.buildRustPackage { pname = "raspi-oled"; - version = "unstable-infdev-6"; + version = "unstable-infdev-7"; src = ./.; diff --git a/src/github.rs b/src/github.rs index 7eaef1b..2a6cfaf 100644 --- a/src/github.rs +++ b/src/github.rs @@ -208,16 +208,17 @@ pub fn get_new_notifications( } let json = resp.call()?.into_string()?; let items: Vec = serde_json::from_str(&json)?; - let mut last_modified = items + let new_last_modified = items .get(0) - .map(|x| x.updated_at.clone()) - .or_else(|| last_modified.map(|x| x.to_owned())); - if let Some(lm) = last_modified.as_mut() { + .map(|x| x.updated_at.clone()); + let last_modified = if let Some(lm) = new_last_modified { // parse and increase by one second 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); - *lm = dt.format(&format)?; - } + Some(dt.format(&format)?) + } else { + last_modified.map(|x| x.to_owned()) + }; Ok((items, last_modified)) }