From 5b58040975cdaa95350d0575ff6b1dfc20241eed Mon Sep 17 00:00:00 2001 From: Brent Schroeter Date: Sat, 6 Sep 2025 12:31:29 -0700 Subject: [PATCH] move time zone selection to config.rs --- src/config.rs | 3 +++ src/main.rs | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1a08346..bc59158 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,9 @@ pub(crate) const T_ON: &'static str = "17:00"; /// End of "on" cycle for switch, in 24 hour "HH:MM" format. pub(crate) const T_OFF: &'static str = "09:00"; +/// Time zone for T_ON and T_OFF. +pub(crate) const TZ: chrono_tz::Tz = chrono_tz::US::Pacific; + /// Access point SSID. pub(crate) const WIFI_SSID: &'static str = "Example"; diff --git a/src/main.rs b/src/main.rs index 2d346c8..8c773a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use std::default::Default; use anyhow::{bail, Result}; use chrono::{NaiveTime, Utc}; -use chrono_tz::US::Pacific; use esp_idf_svc::{ eventloop::EspSystemEventLoop, hal::{ @@ -44,12 +43,12 @@ fn main() -> Result<()> { // ======== Main Control Loop ======== // loop { - let now = Utc::now().with_timezone(&Pacific); - info!("Current time: {}", now); + let dt = Utc::now().with_timezone(&config::TZ); + info!("Current time: {}", dt); - let t = now.time(); + let t = dt.time(); - let active = match (t_on < t_off, t > t_on, t > t_off) { + let switch_active = match (t_on < t_off, t > t_on, t > t_off) { // Active period falls within single day, and t falls between t_on // and t_off. (true, true, false) => true, @@ -61,7 +60,7 @@ fn main() -> Result<()> { _ => false, }; - if active { + if switch_active { switch_driver.set_high()?; } else { switch_driver.set_low()?;