diff --git a/Cargo.lock b/Cargo.lock index 37c95b6..d68141c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "ab_glyph" @@ -2101,6 +2101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", + "itoa", "js-sys", "num-conv", "powerfmt", diff --git a/Cargo.toml b/Cargo.toml index 81433fd..c223f03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ linux-embedded-hal = "0.3.0" embedded-hal = "0.2.5" libc = "0.2.98" rusqlite = "0.32.1" -time = { version = "0.3.9", features = ["parsing"] } +time = { version = "0.3.9", features = ["parsing", "formatting"] } time-tz = "2" image = { version = "0.24.1", optional = true } serde_json = "1.0.79" diff --git a/default.nix b/default.nix index fb16079..8508dbf 100644 --- a/default.nix +++ b/default.nix @@ -2,7 +2,7 @@ rustPlatform.buildRustPackage { pname = "raspi-oled"; - version = "unstable-infdev-4"; + version = "unstable-infdev-6"; src = ./.; @@ -16,7 +16,7 @@ rustPlatform.buildRustPackage { nativeBuildInputs = [ pkg-config ]; - cargoBuildFlags = [ "--no-default-features" "--bin" "take_measurement" ]; + cargoBuildFlags = [ "--no-default-features" "--bin" "main_loop" ]; buildInputs = [ sqlite ]; diff --git a/src/github.rs b/src/github.rs index 2ad37cb..7eaef1b 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,6 +1,7 @@ use std::error::Error; use serde::Deserialize; +use time::{macros::format_description, PrimitiveDateTime}; #[derive(Debug, Clone, PartialEq, Deserialize)] #[non_exhaustive] @@ -207,9 +208,16 @@ pub fn get_new_notifications( } let json = resp.call()?.into_string()?; let items: Vec = serde_json::from_str(&json)?; - let last_modified = items + let mut 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() { + // 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)?; + dt += time::Duration::seconds(1); + *lm = dt.format(&format)?; + } Ok((items, last_modified)) }