pub struct RadioDateTimeUtils { /* private fields */ }
Expand description
Represents a date and time transmitted over radio.
Implementations§
Source§impl RadioDateTimeUtils
impl RadioDateTimeUtils
Sourcepub fn new(sunday: u8) -> Self
pub fn new(sunday: u8) -> Self
Initialize a new RadioDateTimeUtils instance
§Arguments
sunday
- the numeric value of Sunday, i.e. 7 for DCF77 or 0 for MSF
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the RadioDateTimeUtils instance, except for Sunday, UTC offset, and in-UTC.
Examples found in repository?
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_year(&self) -> Option<u8>
pub fn get_year(&self) -> Option<u8>
Get the current year, truncated to two digits.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_month(&self) -> Option<u8>
pub fn get_month(&self) -> Option<u8>
Get the current month.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_day(&self) -> Option<u8>
pub fn get_day(&self) -> Option<u8>
Get the current day of the month.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_weekday(&self) -> Option<u8>
pub fn get_weekday(&self) -> Option<u8>
Get the current day of the week as a number.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_hour(&self) -> Option<u8>
pub fn get_hour(&self) -> Option<u8>
Get the current hour.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_minute(&self) -> Option<u8>
pub fn get_minute(&self) -> Option<u8>
Get the current minute.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_dst(&self) -> Option<u8>
pub fn get_dst(&self) -> Option<u8>
Get the current bitmask value (if any) of the daylight saving time status.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_leap_second(&self) -> Option<u8>
pub fn get_leap_second(&self) -> Option<u8>
Get the current bitmask value of the leap second status.
Examples found in repository?
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
Sourcepub fn get_jump_dut1(&self) -> bool
pub fn get_jump_dut1(&self) -> bool
Return if the DUT1 has jumped unexpectedly (not at midnight UTC).
Sourcepub fn get_jump_year(&self) -> bool
pub fn get_jump_year(&self) -> bool
Return if the year has jumped unexpectedly.
Sourcepub fn get_jump_month(&self) -> bool
pub fn get_jump_month(&self) -> bool
Return if the month has jumped unexpectedly.
Sourcepub fn get_jump_day(&self) -> bool
pub fn get_jump_day(&self) -> bool
Return if the day-of-month has jumped unexpectedly.
Sourcepub fn get_jump_weekday(&self) -> bool
pub fn get_jump_weekday(&self) -> bool
Return if the day-of-week has jumped unexpectedly.
Sourcepub fn get_jump_hour(&self) -> bool
pub fn get_jump_hour(&self) -> bool
Return if the hour has jumped unexpectedly.
Examples found in repository?
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn get_jump_minute(&self) -> bool
pub fn get_jump_minute(&self) -> bool
Return if the minute has jumped unexpectedly.
Examples found in repository?
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_utc_offset(&mut self, utc_offset: i16, is_utc: bool)
pub fn set_utc_offset(&mut self, utc_offset: i16, is_utc: bool)
Set the time zone offset from local normal-time to UTC in minutes, eastwards being positive, and set whether the station transmits in UTC.
This function is needed until utc_offset
and is_utc
are part of new()
.
§Arguments
utc_offset
- the offset in minutes, between -1080 and +1080 inclusiveis_utc
- indicates if the station transmits in UTC
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns if the current date/time is valid (date, time, DST are all is_some()
).
Sourcepub fn clear_jumps(&mut self)
pub fn clear_jumps(&mut self)
Clear all jump values.
Sourcepub fn add_minute(&mut self) -> bool
pub fn add_minute(&mut self) -> bool
Add one minute to the current date and time, return if the operation succeeded.
- Years are limited to 2 digits, so this function wraps after 100 years.
- The operation is valid in local time and accounts for DST changes.
Examples found in repository?
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_year(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_year(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the year value, valid values are 0 through 99.
§Arguments
value
- the new year value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_month(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_month(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the month value, valid values are 1 through 12.
§Arguments
value
- the new month value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_weekday(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_weekday(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the day-of-week value, valid values are 0/1 through 6/7, depending on how this instance was created.
§Arguments
value
- the new day-of-week value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_day(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_day(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the day-in-month value, valid values are 1 through the last day of that month.
If the year, month, or weekday are absent, the last day of the month cannot be calculated which means the old day-in-month value is kept.
§Arguments
value
- the new day-in-month value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_hour(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_hour(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the hour value, valid values are 0 through 23.
§Arguments
value
- the new hour value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_minute(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
pub fn set_minute(&mut self, value: Option<u8>, terms: bool, check_jump: bool)
Set the minute value, valid values are 0 through 59.
§Arguments
value
- the new minute value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared toadd_minute()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_dut1(&mut self, value: Option<i8>, terms: bool, check_jump: bool)
pub fn set_dut1(&mut self, value: Option<i8>, terms: bool, check_jump: bool)
Set the DUT1 value, valid values are -99 through 99.
§Arguments
value
- the new DUT1 value. None or invalid values keep the old value.terms
- extra validations to pass.check_jump
- check if the value has jumped unexpectedly compared to IERS.
Sourcepub fn set_month_day(
&mut self,
day_in_year: Option<u16>,
is_leap_year: Option<bool>,
terms_month: bool,
terms_day: bool,
check_jump: bool,
)
pub fn set_month_day( &mut self, day_in_year: Option<u16>, is_leap_year: Option<bool>, terms_month: bool, terms_day: bool, check_jump: bool, )
Set the month and day-in-month value from the given day-in-year and is-leap-year values.
§Arguments
day_in_year
- the new day-in-year value.is_leap_year
- this year is a leap year.terms_month
- extra validation to pass for the month.terms_day
- extra validation to pass for the day-in-month.check_jump
- check if the day-in-month or month have jumped unexpectedly compared toadd_minute()
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_dst(
&mut self,
value: Option<bool>,
announce: Option<bool>,
check_jump: bool,
)
pub fn set_dst( &mut self, value: Option<bool>, announce: Option<bool>, check_jump: bool, )
Set the DST mask value, both the actual value and any information on transitions.
§Arguments
value
- the new DST value. A None value or unannounced changes keep the current value.announce
- if any announcement is made on a transition. The history of this value of the last hour (or part thereof if started later) is kept to compensate for spurious True values.check_jump
- check if the value changed unexpectedly.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
6fn main() {
7 let mut dcf77 = RadioDateTimeUtils::new(7);
8
9 // set date of now, leave out extra checks, do not compare to previous non-existing value:
10
11 // day must be set *after* year, month, and weekday because set_day() checks if its argument
12 // is within the current month which could be 28 or 29 for February depending on the year and
13 // day-of-week for 00 years.
14
15 dcf77.set_year(Some(24), true, false);
16 // year is clipped to century
17 dcf77.set_month(Some(1), true, false);
18 dcf77.set_day(Some(25), true, false);
19 println!("Day-of-month: {:?}", dcf77.get_day());
20 dcf77.set_weekday(Some(4), true, false);
21 dcf77.set_day(Some(25), true, false);
22 dcf77.set_hour(Some(22), true, false);
23 dcf77.set_minute(Some(34), true, false);
24 // seconds are not present in RadioDateTimeUtils
25
26 // Show the date and time:
27 println!(
28 "Initial: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
29 dcf77.get_year(),
30 dcf77.get_month(),
31 dcf77.get_day(),
32 dcf77.get_weekday(),
33 dcf77.get_hour(),
34 dcf77.get_minute(),
35 dcf77.get_jump_minute()
36 );
37
38 // Going to the next minute without telling radio_datetime_utils about it
39 // causes it to think the minute jumped:
40 dcf77.set_minute(Some(35), true, true);
41 println!(
42 "Minute={:?}, jumped={}",
43 dcf77.get_minute(),
44 dcf77.get_jump_minute()
45 );
46 // Advance the time by one minute and show new (predicted) datetime:
47 // add_minute() wants DST to be defined and leaves jump values untouched
48 dcf77.set_dst(Some(false), Some(false), false);
49 println!("add_minute()={}", dcf77.add_minute());
50 println!(
51 "After add_minute(): date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} jumped={}",
52 dcf77.get_year(),
53 dcf77.get_month(),
54 dcf77.get_day(),
55 dcf77.get_weekday(),
56 dcf77.get_hour(),
57 dcf77.get_minute(),
58 dcf77.get_jump_minute()
59 );
60
61 // "Formally" set the minute:
62 dcf77.set_minute(Some(36), true, true);
63 println!(
64 "Minute={:?}, jumped={}",
65 dcf77.get_minute(),
66 dcf77.get_jump_minute()
67 );
68
69 // Setting an illegal value leaves it untouched:
70 dcf77.set_month(Some(14), true, false);
71 println!("Month={:?}", dcf77.get_month());
72 dcf77.set_year(None, true, false);
73 println!("Year={:?}", dcf77.get_year());
74
75 // New century
76 let mut msf = RadioDateTimeUtils::new(0);
77 msf.set_year(Some(99), true, false);
78 msf.set_month(Some(12), true, false);
79 msf.set_weekday(Some(5), true, false); // Friday
80 msf.set_day(Some(31), true, false);
81 msf.set_hour(Some(23), true, false);
82 msf.set_minute(Some(59), true, false);
83 println!(
84 "Old century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
85 msf.get_year(),
86 msf.get_month(),
87 msf.get_day(),
88 msf.get_weekday(),
89 msf.get_hour(),
90 msf.get_minute(),
91 msf.get_dst()
92 );
93
94 // add_minute() wants DST to be defined.
95 // announcements are honored because we omit calling bump_minutes_running() here
96 msf.set_dst(Some(false), Some(true), false);
97 println!("add_minute()={}", msf.add_minute());
98 msf.set_dst(Some(true), Some(true), false);
99 println!(
100 "New century: date={:?}-{:?}-{:?} weekday={:?} time={:?}-{:?} {:?}",
101 msf.get_year(),
102 msf.get_month(),
103 msf.get_day(),
104 msf.get_weekday(),
105 msf.get_hour(),
106 msf.get_minute(),
107 msf.get_dst()
108 );
109
110 // Setting the value twice with set_XXX() does not set the jumped flag the second time:
111 msf.set_hour(Some(2), true, true);
112 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
113 msf.set_hour(Some(2), true, true);
114 println!("Hour={:?} jumped={:?}", msf.get_hour(), msf.get_jump_hour());
115
116 // WWVB (the legacy AM version) transmits the date as year, is-leap-year, day-in-year, it
117 // omits the day-of-week.
118 let mut wwvb = RadioDateTimeUtils::new(0); // pick 0 (-1 is invalid)
119 wwvb.set_year(Some(24), true, false); // year is 0-99
120 wwvb.set_month_day(Some(60), Some(true), true, true, false);
121 wwvb.set_utc_offset(-300, true);
122 // leap day:
123 println!(
124 "WWVB: date={:?}-{:?}-{:?}",
125 wwvb.get_year(),
126 wwvb.get_month(),
127 wwvb.get_day()
128 );
129
130 wwvb.reset();
131 println!(" Reset WWVB: {:#?}", wwvb)
132}
Sourcepub fn set_leap_second(&mut self, announce: Option<bool>, minute_length: u8)
pub fn set_leap_second(&mut self, announce: Option<bool>, minute_length: u8)
Set the leap second value.
§Arguments
announce
- if any announcement is made on a positive leap second. The history of this value of the last hour (or part thereof if started later) is kept to compensate for spurious Some(True) values.minute_length
- the length of the decoded minute in seconds.
Examples found in repository?
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
Sourcepub fn bump_minutes_running(&mut self)
pub fn bump_minutes_running(&mut self)
Bump the internal minute counter needed for set_dst() and set_leap_second()
The code above this library must call this function, as this library cannot know which function got called first, or if just one of them should be called.
Examples found in repository?
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 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 // switch to DST, in the middle of a business week (nothing in this crate
48 // dictates that DST switches should happen on Sunday nights). Normally,
49 // time station start notifying one or more hours in advance. set_dst()
50 // currently only supports notifications one hour in advance.
51 while rdt.get_minute().unwrap() < 59 {
52 rdt.add_minute();
53 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
54 rdt.set_dst(Some(false), Some(true), false);
55 // Keep internal bookkeeping up-to-date:
56 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); // compulsory, sign off the new DST value
70 rdt.bump_minutes_running(); // optional, but a good idea
71 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 // in the new, now normal again, hour:
82 rdt.add_minute();
83 rdt.set_dst(Some(true), Some(false), false);
84 rdt.bump_minutes_running(); // optional
85 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}
More examples
25fn main() {
26 let mut rdt = RadioDateTimeUtils::new(7);
27
28 // initial values
29 rdt.set_year(Some(24), true, false);
30 rdt.set_month(Some(3), true, false);
31 rdt.set_weekday(Some(3), true, false); // Wednesday
32 rdt.set_day(Some(13), true, false);
33 rdt.set_hour(Some(21), true, false);
34 rdt.set_minute(Some(5), true, false);
35 // Remember to initialize the DST field, otherwise add_minute() will
36 // refuse to increase the time which ultimately results in a panic in
37 // a test in set_leap_second() :
38 // thread 'main' panicked at src/lib.rs:
39 // attempt to multiply with overflow
40 rdt.set_dst(Some(false), Some(false), false);
41 rdt.set_leap_second(Some(false), 60);
42 println!(
43 "Initial : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
44 rdt.get_year(),
45 rdt.get_month(),
46 rdt.get_day(),
47 rdt.get_weekday(),
48 rdt.get_hour(),
49 rdt.get_minute(),
50 parse_ls(rdt.get_leap_second())
51 );
52
53 // insert a leap second, in the middle of a business week (nothing in this crate
54 // dictates that leap seconds should happen at midnight, UTC? local?). Normally,
55 // time station start notifying one or more hours in advance. set_leap_second()
56 // currently only supports notifications one hour in advance.
57 while rdt.get_minute().unwrap() < 59 {
58 rdt.add_minute();
59 // Keep feeding the announcement, must be at least for 50% of the last hour or part thereof:
60 rdt.set_leap_second(Some(true), 60);
61 // Keep internal bookkeeping up-to-date:
62 rdt.bump_minutes_running();
63 }
64 println!(
65 "Just before leap second: date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
66 rdt.get_year(),
67 rdt.get_month(),
68 rdt.get_day(),
69 rdt.get_weekday(),
70 rdt.get_hour(),
71 rdt.get_minute(),
72 parse_ls(rdt.get_leap_second())
73 );
74 rdt.add_minute();
75 rdt.set_leap_second(Some(true), 61); // insert the leap second
76 rdt.bump_minutes_running(); // optional, but a good idea
77 println!(
78 "Just after leap second : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
79 rdt.get_year(),
80 rdt.get_month(),
81 rdt.get_day(),
82 rdt.get_weekday(),
83 rdt.get_hour(),
84 rdt.get_minute(),
85 parse_ls(rdt.get_leap_second())
86 );
87 // in the new, now normal again, hour:
88 rdt.add_minute();
89 rdt.set_leap_second(Some(false), 60);
90 rdt.bump_minutes_running(); // optional
91 println!(
92 "Back to business : date={:?}-{:?}-{:?} weekday={:?} time={:?}:{:?} LS={}",
93 rdt.get_year(),
94 rdt.get_month(),
95 rdt.get_day(),
96 rdt.get_weekday(),
97 rdt.get_hour(),
98 rdt.get_minute(),
99 parse_ls(rdt.get_leap_second())
100 );
101}
Sourcepub fn get_utc(&self) -> Option<RadioDateTimeUtils>
pub fn get_utc(&self) -> Option<RadioDateTimeUtils>
Return a copy of the current date/time in UTC (for local time sources), does nothing for incomplete inputs or results that are already converted to UTC.
The return type is Optional until utc_offset is part of new()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
Sourcepub fn get_local_time(&self) -> Option<RadioDateTimeUtils>
pub fn get_local_time(&self) -> Option<RadioDateTimeUtils>
Return a copy of the current date/time in local time (for UTC sources), does nothing for incomplete inputs or results that are already converted to local time.
The return type is Optional until utc_offset is part of new()
.
Examples found in repository?
6fn main() {
7 println!("*** DCF77 ***");
8 let mut dcf77 = RadioDateTimeUtils::new(7);
9 // set_utc_offset() will be part of new() in version 2.0 :
10 dcf77.set_utc_offset(60, false);
11 dcf77.set_year(Some(24), true, false);
12 dcf77.set_month(Some(12), true, false);
13 dcf77.set_weekday(Some(6), true, false);
14 dcf77.set_day(Some(21), true, false);
15 dcf77.set_hour(Some(18), true, false);
16 dcf77.set_minute(Some(42), true, false);
17 dcf77.set_dst(Some(false), Some(false), false);
18 // Show local date/time:
19 println!(
20 "Local: {}-{}-{} {} {}:{} DST={:#02x?}",
21 dcf77.get_year().unwrap(),
22 dcf77.get_month().unwrap(),
23 dcf77.get_day().unwrap(),
24 dcf77.get_weekday().unwrap(),
25 dcf77.get_hour().unwrap(),
26 dcf77.get_minute().unwrap(),
27 dcf77.get_dst()
28 );
29 let utc = dcf77.get_utc().unwrap();
30 println!(
31 "UTC : {}-{}-{} {} {}:{} DST={:#02x?}",
32 utc.get_year().unwrap(),
33 utc.get_month().unwrap(),
34 utc.get_day().unwrap(),
35 utc.get_weekday().unwrap(),
36 utc.get_hour().unwrap(),
37 utc.get_minute().unwrap(),
38 utc.get_dst()
39 );
40
41 println!("*** WWVB ****");
42 let mut wwvb = RadioDateTimeUtils::new(0); // no day-of-week broadcast
43 wwvb.set_utc_offset(-300, true);
44 wwvb.set_year(Some(24), true, false);
45 wwvb.set_month_day(Some(356), Some(true), true, true, false);
46 wwvb.set_hour(Some(17), true, false);
47 wwvb.set_minute(Some(42), true, false);
48 wwvb.set_dst(Some(false), Some(false), false); // WWVB *does* transmit DST information.
49 println!(
50 "UTC : {}-{}-{} -- {}:{} DST={:#02x?}",
51 wwvb.get_year().unwrap(),
52 wwvb.get_month().unwrap(),
53 wwvb.get_day().unwrap(),
54 wwvb.get_hour().unwrap(),
55 wwvb.get_minute().unwrap(),
56 wwvb.get_dst()
57 );
58
59 wwvb.set_weekday(Some(6), true, false); // simulate to get get_local_time() working
60 let localtime = wwvb.get_local_time().unwrap();
61 println!(
62 "EST : {}-{}-{} -- {}:{} DST={:#02x?}",
63 localtime.get_year().unwrap(),
64 localtime.get_month().unwrap(),
65 localtime.get_day().unwrap(),
66 localtime.get_hour().unwrap(),
67 localtime.get_minute().unwrap(),
68 localtime.get_dst()
69 );
70}
Trait Implementations§
Source§impl Clone for RadioDateTimeUtils
impl Clone for RadioDateTimeUtils
Source§fn clone(&self) -> RadioDateTimeUtils
fn clone(&self) -> RadioDateTimeUtils
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more