1use radio_datetime_utils::{DST_ANNOUNCED, DST_PROCESSED, DST_SUMMER, RadioDateTimeUtils};
5
6fn parse_dst(dst: Option<u8>) -> String {
8 if dst.is_none() {
9 return String::from("*");
10 }
11 let mut res = String::from("");
12 let s_dst = dst.unwrap();
13 if s_dst & DST_ANNOUNCED != 0 {
14 res += "announced ";
15 }
16 if s_dst & DST_PROCESSED != 0 {
17 res += "processed ";
18 }
19 if s_dst & DST_SUMMER != 0 {
20 res += "summer";
21 }
22 res
23}
24
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 rdt.set_dst(Some(false), Some(false), false);
36 println!(
37 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}",
38 rdt.get_year(),
39 rdt.get_month(),
40 rdt.get_day(),
41 rdt.get_weekday(),
42 rdt.get_hour(),
43 rdt.get_minute(),
44 parse_dst(rdt.get_dst())
45 );
46
47 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 rdt.set_dst(Some(false), Some(true), false);
55 rdt.bump_minutes_running();
57 }
58 println!(
59 "Just before switch: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}",
60 rdt.get_year(),
61 rdt.get_month(),
62 rdt.get_day(),
63 rdt.get_weekday(),
64 rdt.get_hour(),
65 rdt.get_minute(),
66 parse_dst(rdt.get_dst())
67 );
68 rdt.add_minute();
69 rdt.set_dst(Some(true), Some(true), false); rdt.bump_minutes_running(); println!(
72 "Just after switch : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}",
73 rdt.get_year(),
74 rdt.get_month(),
75 rdt.get_day(),
76 rdt.get_weekday(),
77 rdt.get_hour(),
78 rdt.get_minute(),
79 parse_dst(rdt.get_dst())
80 );
81 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); println!(
86 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} DST={}",
87 rdt.get_year(),
88 rdt.get_month(),
89 rdt.get_day(),
90 rdt.get_weekday(),
91 rdt.get_hour(),
92 rdt.get_minute(),
93 parse_dst(rdt.get_dst())
94 );
95}