diff --git a/firmware/src/http.rs b/firmware/src/http.rs index ee1bbe5..65ec445 100644 --- a/firmware/src/http.rs +++ b/firmware/src/http.rs @@ -2,7 +2,7 @@ use crate::json::{self, FromJson, ToJson}; use crate::time; use crate::wifi::{DnsSocket, TcpClient, TcpConnection, Wifi}; use alloc::vec::Vec; -use chrono::{DateTime, Utc}; +use chrono::DateTime; use core::convert::Infallible; use core::{fmt, str}; use embedded_io_async::{BufRead, Read}; @@ -219,10 +219,9 @@ impl Connection<'_> { .headers() .find_map(|(k, v)| (k == "Date").then_some(v)) .and_then(|v| str::from_utf8(v).ok()) - .and_then(|s| DateTime::parse_from_rfc2822(s).ok()) - .map(|d| d.with_timezone(&Utc)); + .and_then(|s| DateTime::parse_from_rfc2822(s).ok()); if let Some(time) = time { - time::set(time); + time::set(&time); } // Check HTTP response status diff --git a/firmware/src/time.rs b/firmware/src/time.rs index 1c67ec1..356e708 100644 --- a/firmware/src/time.rs +++ b/firmware/src/time.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, TimeDelta, Utc}; +use chrono::{DateTime, TimeDelta, TimeZone, Utc}; use core::cell::RefCell; use embassy_sync::blocking_mutex::CriticalSectionMutex; use embassy_time::Instant; @@ -49,13 +49,14 @@ pub fn uptime() -> Option { Instant::now().to_duration() } -/// Current time +/// Current time. Always given in UTC since the local timezone is unknown. pub fn now() -> Option> { Instant::now().to_datetime() } /// Set current time by using the given current time to calculate the time of system start -pub fn set(now: DateTime) { +pub fn set(now: &DateTime) { + let now = now.with_timezone(&Utc); if let Some(uptime) = uptime() { set_start_time(now - uptime); debug!("Time: Current time set to {}", now);