local_offsets/
local_offsets.rs1use android_chrono_tz::Local;
15use chrono::{NaiveDate, TimeZone, Utc};
16
17fn main() {
18 println!("Local time: {}", Local::now());
19
20 let winter = Utc.with_ymd_and_hms(2026, 3, 1, 12, 0, 0).unwrap();
21 println!(
22 "Offset at {winter}: {}",
23 Local.offset_from_utc_datetime(&winter.naive_utc())
24 );
25
26 let summer = Utc.with_ymd_and_hms(2026, 4, 1, 12, 0, 0).unwrap();
27 println!(
28 "Offset at {summer}: {}",
29 Local.offset_from_utc_datetime(&summer.naive_utc())
30 );
31
32 let winter_local = Local.with_ymd_and_hms(2026, 3, 1, 12, 0, 0).unwrap();
33 println!(
34 "Offset at {winter_local}: {:?}",
35 Local.offset_from_local_datetime(&winter_local.naive_local())
36 );
37
38 let summer_local = Local.with_ymd_and_hms(2026, 4, 1, 12, 0, 0).unwrap();
39 println!(
40 "Offset at {summer_local}: {:?}",
41 Local.offset_from_local_datetime(&summer_local.naive_local())
42 );
43
44 let start_local = NaiveDate::from_ymd_opt(2026, 3, 29)
46 .unwrap()
47 .and_hms_opt(1, 30, 0)
48 .unwrap();
49 println!(
50 "At start of DST {start_local}: {:?}",
51 Local.offset_from_local_datetime(&start_local)
52 );
53
54 let end_local = NaiveDate::from_ymd_opt(2026, 10, 25)
56 .unwrap()
57 .and_hms_opt(1, 30, 0)
58 .unwrap();
59 println!(
60 "At end of DST {end_local}: {:?}",
61 Local.offset_from_local_datetime(&end_local)
62 );
63}