1use tz::datetime::{DateTime, UtcDateTime};
2use tz::error::TzError;
3use tz::timezone::{AlternateTime, LeapSecond, LocalTimeType, MonthWeekDay, RuleDay, TimeZoneRef, Transition, TransitionRule};
4
5fn main() -> Result<(), TzError> {
6 macro_rules! unwrap {
7 ($x:expr) => {
8 match $x {
9 Ok(x) => x,
10 Err(_) => panic!(),
11 }
12 };
13 }
14
15 const TIME_ZONE_REF: TimeZoneRef<'static> = unwrap!(TimeZoneRef::new(
16 &[
17 Transition::new(-2334101314, 1),
18 Transition::new(-1157283000, 2),
19 Transition::new(-1155436200, 1),
20 Transition::new(-880198200, 3),
21 Transition::new(-769395600, 4),
22 Transition::new(-765376200, 1),
23 Transition::new(-712150200, 5),
24 ],
25 const {
26 &[
27 unwrap!(LocalTimeType::new(-37886, false, Some(b"LMT"))),
28 unwrap!(LocalTimeType::new(-37800, false, Some(b"HST"))),
29 unwrap!(LocalTimeType::new(-34200, true, Some(b"HDT"))),
30 unwrap!(LocalTimeType::new(-34200, true, Some(b"HWT"))),
31 unwrap!(LocalTimeType::new(-34200, true, Some(b"HPT"))),
32 unwrap!(LocalTimeType::new(-36000, false, Some(b"HST"))),
33 ]
34 },
35 &[
36 LeapSecond::new(78796800, 1),
37 LeapSecond::new(94694401, 2),
38 LeapSecond::new(126230402, 3),
39 LeapSecond::new(157766403, 4),
40 LeapSecond::new(189302404, 5),
41 LeapSecond::new(220924805, 6),
42 ],
43 const {
44 &Some(TransitionRule::Alternate(unwrap!(AlternateTime::new(
45 unwrap!(LocalTimeType::new(-36000, false, Some(b"HST"))),
46 unwrap!(LocalTimeType::new(-34200, true, Some(b"HPT"))),
47 RuleDay::MonthWeekDay(unwrap!(MonthWeekDay::new(10, 5, 0))),
48 93600,
49 RuleDay::MonthWeekDay(unwrap!(MonthWeekDay::new(3, 4, 4))),
50 7200,
51 ))))
52 },
53 ));
54
55 const LOCAL_TIME_TYPE: LocalTimeType = *unwrap!(TIME_ZONE_REF.find_local_time_type(0));
56
57 const UTC: TimeZoneRef<'static> = TimeZoneRef::utc();
58
59 const UNIX_EPOCH: UtcDateTime = unwrap!(UtcDateTime::from_timespec(0, 0));
60 const UTC_DATE_TIME: UtcDateTime = unwrap!(UtcDateTime::new(2000, 1, 1, 0, 0, 0, 1000));
61
62 const DATE_TIME: DateTime = unwrap!(DateTime::new(2000, 1, 1, 1, 0, 0, 1000, unwrap!(LocalTimeType::with_ut_offset(3600))));
63
64 const DATE_TIME_1: DateTime = unwrap!(UTC_DATE_TIME.project(TIME_ZONE_REF));
65 const DATE_TIME_2: DateTime = unwrap!(DATE_TIME_1.project(UTC));
66
67 println!("{TIME_ZONE_REF:#?}");
68 println!("{LOCAL_TIME_TYPE:?}");
69
70 println!("{UNIX_EPOCH:?}");
71 println!("{UTC_DATE_TIME:?}");
72
73 println!("{DATE_TIME:#?}");
74
75 println!("{DATE_TIME_1:#?}");
76 println!("{DATE_TIME_2:#?}");
77
78 Ok(())
79}