From 5764b9b4d8f673060ec492d95f11bf13bbf19b46 Mon Sep 17 00:00:00 2001 From: adrianwb Date: Tue, 12 Dec 2023 17:13:31 +0000 Subject: [PATCH] Prevent FridgeTag (cumulative) breaches going past midnight --- src/berlinger.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/berlinger.rs b/src/berlinger.rs index 0549fe0..97f81e4 100644 --- a/src/berlinger.rs +++ b/src/berlinger.rs @@ -464,12 +464,18 @@ fn parse_fridgetag_breach( } if valid_breach { + let breach_start_timestamp = NaiveDateTime::new(breach_date, start_time); + let mut breach_end_timestamp = breach_start_timestamp + breach_duration; // only true for consecutive breaches, but this is all the data we have for FridgeTags + + if breach_end_timestamp.date() > breach_date { // FridgeTag breach can't go into next day + breach_end_timestamp = NaiveDateTime::new(breach_date, zero_time) + Duration::days(1); + } let temperature_breach = TemperatureBreach { breach_type: breach_type, start_timestamp: breach_start_timestamp, - end_timestamp: breach_start_timestamp + breach_duration, // only true for consecutive breaches, but this is all the data we have for FridgeTags + end_timestamp: breach_end_timestamp, duration: breach_duration, acknowledged: false, };