// SPDX-License-Identifier: MIT OR Apache-2.0 // Copyright 2024 René Ladan use radio_datetime_utils::{RadioDateTimeUtils, DST_ANNOUNCED, DST_PROCESSED, DST_SUMMER}; // quick and dirty parsing function fn parse_dst(dst: Option) -> String { if dst.is_none() { return String::from("*"); } let mut res = String::from(""); let s_dst = dst.unwrap(); if s_dst & DST_ANNOUNCED != 0 { res += "announced "; } if s_dst & DST_PROCESSED != 0 { res += "processed "; } if s_dst & DST_SUMMER != 0 { res += "summer"; } res } fn main() { let mut rdt = RadioDateTimeUtils::new(7); // initial values rdt.set_year(Some(24), true, false); rdt.set_month(Some(3), true, false); rdt.set_weekday(Some(3), true, false); // Wednesday rdt.set_day(Some(13), true, false); rdt.set_hour(Some(21), true, false); rdt.set_minute(Some(5), true, false); rdt.set_dst(Some(false), Some(false), false); println!( "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}", rdt.get_year(), rdt.get_month(), rdt.get_day(), rdt.get_weekday(), rdt.get_hour(), rdt.get_minute(), parse_dst(rdt.get_dst()) ); // switch to DST, in the middle of a business week (nothing in this crate // dictates that DST switches should happen on Sunday nights). Normally, // time station start notifying one or more hours in advance. set_dst() // currently only supports notifications one hour in advance. while rdt.get_minute().unwrap() < 59 { rdt.add_minute(); // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof: rdt.set_dst(Some(false), Some(true), false); // Keep internal bookkeeping up-to-date: rdt.bump_minutes_running(); } println!( "Just before switch: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}", rdt.get_year(), rdt.get_month(), rdt.get_day(), rdt.get_weekday(), rdt.get_hour(), rdt.get_minute(), parse_dst(rdt.get_dst()) ); rdt.add_minute(); rdt.set_dst(Some(true), Some(true), false); // compulsory, sign off the new DST value rdt.bump_minutes_running(); // optional, but a good idea println!( "Just after switch : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}", rdt.get_year(), rdt.get_month(), rdt.get_day(), rdt.get_weekday(), rdt.get_hour(), rdt.get_minute(), parse_dst(rdt.get_dst()) ); // in the new, now normal again, hour: rdt.add_minute(); rdt.set_dst(Some(true), Some(false), false); rdt.bump_minutes_running(); // optional println!( "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}", rdt.get_year(), rdt.get_month(), rdt.get_day(), rdt.get_weekday(), rdt.get_hour(), rdt.get_minute(), parse_dst(rdt.get_dst()) ); }