// SPDX-License-Identifier: MIT OR Apache-2.0 // Copyright 2024 René Ladan use radio_datetime_utils::RadioDateTimeUtils; fn main() { let mut dcf77 = RadioDateTimeUtils::new(7); // set date of now, leave out extra checks, do not compare to previous non-existing value: // day must be set *after* year, month, and weekday because set_day() checks if its argument // is within the current month which could be 28 or 29 for February depending on the year and // day-of-week for 00 years. dcf77.set_year(Some(24), true, false); // year is clipped to century dcf77.set_month(Some(1), true, false); dcf77.set_day(Some(25), true, false); println!("Day-of-month: {:?}", dcf77.get_day()); dcf77.set_weekday(Some(4), true, false); dcf77.set_day(Some(25), true, false); dcf77.set_hour(Some(22), true, false); dcf77.set_minute(Some(34), true, false); // seconds are not present in RadioDateTimeUtils // Show the date and time: println!( "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}", dcf77.get_year(), dcf77.get_month(), dcf77.get_day(), dcf77.get_weekday(), dcf77.get_hour(), dcf77.get_minute(), dcf77.get_jump_minute() ); // Going to the next minute without telling radio_datetime_utils about it // causes it to think the minute jumped: dcf77.set_minute(Some(35), true, true); println!( "Minute={:?}, jumped={}", dcf77.get_minute(), dcf77.get_jump_minute() ); // Advance the time by one minute and show new (predicted) datetime: // add_minute() wants DST to be defined and leaves jump values untouched dcf77.set_dst(Some(false), Some(false), false); println!("add_minute()={}", dcf77.add_minute()); println!( "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}", dcf77.get_year(), dcf77.get_month(), dcf77.get_day(), dcf77.get_weekday(), dcf77.get_hour(), dcf77.get_minute(), dcf77.get_jump_minute() ); // "Formally" set the minute: dcf77.set_minute(Some(36), true, true); println!( "Minute={:?}, jumped={}", dcf77.get_minute(), dcf77.get_jump_minute() ); // Setting an illegal value leaves it untouched: dcf77.set_month(Some(14), true, false); println!("Month={:?}", dcf77.get_month()); dcf77.set_year(None, true, false); println!("Year={:?}", dcf77.get_year()); // New century let mut npl = RadioDateTimeUtils::new(0); npl.set_year(Some(99), true, false); npl.set_month(Some(12), true, false); npl.set_weekday(Some(5), true, false); // Friday npl.set_day(Some(31), true, false); npl.set_hour(Some(23), true, false); npl.set_minute(Some(59), true, false); println!( "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}", npl.get_year(), npl.get_month(), npl.get_day(), npl.get_weekday(), npl.get_hour(), npl.get_minute(), npl.get_dst() ); // add_minute() wants DST to be defined. // announcements are honored because we omit calling bump_minutes_running() here npl.set_dst(Some(false), Some(true), false); println!("add_minute()={}", npl.add_minute()); npl.set_dst(Some(true), Some(true), false); println!( "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}", npl.get_year(), npl.get_month(), npl.get_day(), npl.get_weekday(), npl.get_hour(), npl.get_minute(), npl.get_dst() ); }