@@ -7,80 +7,14 @@ use crate::{
7
7
use alloc:: string:: String ;
8
8
use core:: fmt:: Write ;
9
9
10
- #[ derive( Debug ) ]
11
- pub struct MonthWeekDay ( pub Month , pub u8 , pub WeekDay ) ;
12
-
13
- #[ derive( Debug ) ]
14
- pub enum PosixDate {
15
- JulianNoLeap ( u16 ) ,
16
- JulianLeap ( u16 ) ,
17
- MonthWeekDay ( MonthWeekDay ) ,
18
- }
19
-
20
- impl PosixDate {
21
- pub ( crate ) fn from_rule ( rule : & Rule ) -> Self {
22
- match rule. on_date {
23
- DayOfMonth :: Day ( day) if rule. in_month == Month :: Jan || rule. in_month == Month :: Feb => {
24
- PosixDate :: JulianNoLeap ( month_to_day ( rule. in_month as u8 , 1 ) as u16 + day as u16 )
25
- }
26
- DayOfMonth :: Day ( day) => {
27
- PosixDate :: JulianNoLeap ( month_to_day ( rule. in_month as u8 , 1 ) as u16 + day as u16 )
28
- }
29
- DayOfMonth :: Last ( wd) => PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , 5 , wd) ) ,
30
- DayOfMonth :: WeekDayGEThanMonthDay ( week_day, day_of_month) => {
31
- let week = 1 + ( day_of_month - 1 ) / 7 ;
32
- PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , week, week_day) )
33
- }
34
- DayOfMonth :: WeekDayLEThanMonthDay ( week_day, day_of_month) => {
35
- let week = day_of_month / 7 ;
36
- PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , week, week_day) )
37
- }
38
- }
39
- }
40
- }
41
-
42
- #[ derive( Debug ) ]
43
- pub struct PosixDateTime {
44
- pub date : PosixDate ,
45
- pub time : Time ,
46
- }
47
-
48
- impl PosixDateTime {
49
- pub ( crate ) fn from_rule_and_transition_info ( rule : & Rule , offset : Time , savings : Time ) -> Self {
50
- let date = PosixDate :: from_rule ( rule) ;
51
- let time = match rule. at {
52
- QualifiedTime :: Local ( time) => time,
53
- QualifiedTime :: Standard ( standard_time) => standard_time. add ( rule. save ) ,
54
- QualifiedTime :: Universal ( universal_time) => universal_time. add ( offset) . add ( savings) ,
55
- } ;
56
- Self { date, time }
57
- }
58
- }
59
-
60
10
#[ non_exhaustive]
61
- #[ derive( Debug ) ]
62
- pub struct PosixTransition {
63
- pub abbr : PosixAbbreviation ,
64
- pub savings : Time ,
65
- pub start : PosixDateTime ,
66
- pub end : PosixDateTime ,
67
- }
68
-
69
- #[ non_exhaustive]
70
- #[ derive( Debug ) ]
11
+ #[ derive( Debug , PartialEq ) ]
71
12
pub struct PosixTimeZone {
72
13
pub abbr : PosixAbbreviation ,
73
14
pub offset : Time ,
74
15
pub transition_info : Option < PosixTransition > ,
75
16
}
76
17
77
- #[ non_exhaustive]
78
- #[ derive( Debug ) ]
79
- pub struct PosixAbbreviation {
80
- is_numeric : bool ,
81
- formatted : String ,
82
- }
83
-
84
18
impl PosixTimeZone {
85
19
pub ( crate ) fn from_zone_and_savings ( entry : & ZoneEntry , savings : Time ) -> Self {
86
20
let offset = entry. std_offset . add ( savings) ;
@@ -167,6 +101,73 @@ impl PosixTimeZone {
167
101
}
168
102
}
169
103
104
+ #[ non_exhaustive]
105
+ #[ derive( Debug , PartialEq ) ]
106
+ pub struct PosixTransition {
107
+ pub abbr : PosixAbbreviation ,
108
+ pub savings : Time ,
109
+ pub start : PosixDateTime ,
110
+ pub end : PosixDateTime ,
111
+ }
112
+
113
+ #[ non_exhaustive]
114
+ #[ derive( Debug , PartialEq ) ]
115
+ pub struct PosixAbbreviation {
116
+ is_numeric : bool ,
117
+ formatted : String ,
118
+ }
119
+ #[ derive( Debug , PartialEq ) ]
120
+ pub struct MonthWeekDay ( pub Month , pub u8 , pub WeekDay ) ;
121
+
122
+ #[ derive( Debug , PartialEq ) ]
123
+ pub enum PosixDate {
124
+ JulianNoLeap ( u16 ) ,
125
+ JulianLeap ( u16 ) ,
126
+ MonthWeekDay ( MonthWeekDay ) ,
127
+ }
128
+
129
+ impl PosixDate {
130
+ pub ( crate ) fn from_rule ( rule : & Rule ) -> Self {
131
+ match rule. on_date {
132
+ DayOfMonth :: Day ( day) if rule. in_month == Month :: Jan || rule. in_month == Month :: Feb => {
133
+ PosixDate :: JulianNoLeap ( month_to_day ( rule. in_month as u8 , 1 ) as u16 + day as u16 )
134
+ }
135
+ DayOfMonth :: Day ( day) => {
136
+ PosixDate :: JulianNoLeap ( month_to_day ( rule. in_month as u8 , 1 ) as u16 + day as u16 )
137
+ }
138
+ DayOfMonth :: Last ( wd) => PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , 5 , wd) ) ,
139
+ DayOfMonth :: WeekDayGEThanMonthDay ( week_day, day_of_month) => {
140
+ let week = 1 + ( day_of_month - 1 ) / 7 ;
141
+ PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , week, week_day) )
142
+ }
143
+ DayOfMonth :: WeekDayLEThanMonthDay ( week_day, day_of_month) => {
144
+ let week = day_of_month / 7 ;
145
+ PosixDate :: MonthWeekDay ( MonthWeekDay ( rule. in_month , week, week_day) )
146
+ }
147
+ }
148
+ }
149
+ }
150
+
151
+ #[ derive( Debug , PartialEq ) ]
152
+ pub struct PosixDateTime {
153
+ pub date : PosixDate ,
154
+ pub time : Time ,
155
+ }
156
+
157
+ impl PosixDateTime {
158
+ pub ( crate ) fn from_rule_and_transition_info ( rule : & Rule , offset : Time , savings : Time ) -> Self {
159
+ let date = PosixDate :: from_rule ( rule) ;
160
+ let time = match rule. at {
161
+ QualifiedTime :: Local ( time) => time,
162
+ QualifiedTime :: Standard ( standard_time) => standard_time. add ( rule. save ) ,
163
+ QualifiedTime :: Universal ( universal_time) => universal_time. add ( offset) . add ( savings) ,
164
+ } ;
165
+ Self { date, time }
166
+ }
167
+ }
168
+
169
+ // ==== Helper functions ====
170
+
170
171
fn is_numeric ( str : & str ) -> bool {
171
172
str. parse :: < i16 > ( ) . is_ok ( )
172
173
}
0 commit comments