Fix last-modified value

This commit is contained in:
FliegendeWurst 2024-11-08 17:43:09 +01:00
parent efac4f49a7
commit 13325554a4
4 changed files with 14 additions and 5 deletions

3
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 3
[[package]] [[package]]
name = "ab_glyph" name = "ab_glyph"
@ -2101,6 +2101,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa",
"js-sys", "js-sys",
"num-conv", "num-conv",
"powerfmt", "powerfmt",

View File

@ -12,7 +12,7 @@ linux-embedded-hal = "0.3.0"
embedded-hal = "0.2.5" embedded-hal = "0.2.5"
libc = "0.2.98" libc = "0.2.98"
rusqlite = "0.32.1" rusqlite = "0.32.1"
time = { version = "0.3.9", features = ["parsing"] } time = { version = "0.3.9", features = ["parsing", "formatting"] }
time-tz = "2" time-tz = "2"
image = { version = "0.24.1", optional = true } image = { version = "0.24.1", optional = true }
serde_json = "1.0.79" serde_json = "1.0.79"

View File

@ -2,7 +2,7 @@
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "raspi-oled"; pname = "raspi-oled";
version = "unstable-infdev-4"; version = "unstable-infdev-6";
src = ./.; src = ./.;
@ -16,7 +16,7 @@ rustPlatform.buildRustPackage {
nativeBuildInputs = [ pkg-config ]; nativeBuildInputs = [ pkg-config ];
cargoBuildFlags = [ "--no-default-features" "--bin" "take_measurement" ]; cargoBuildFlags = [ "--no-default-features" "--bin" "main_loop" ];
buildInputs = [ sqlite ]; buildInputs = [ sqlite ];

View File

@ -1,6 +1,7 @@
use std::error::Error; use std::error::Error;
use serde::Deserialize; use serde::Deserialize;
use time::{macros::format_description, PrimitiveDateTime};
#[derive(Debug, Clone, PartialEq, Deserialize)] #[derive(Debug, Clone, PartialEq, Deserialize)]
#[non_exhaustive] #[non_exhaustive]
@ -207,9 +208,16 @@ 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 last_modified = items let mut 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())); .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)) Ok((items, last_modified))
} }