@@ -36,25 +36,6 @@ static void swap_times(timelib_time **one, timelib_time **two, timelib_rel_time
36
36
rt -> invert = 1 ;
37
37
}
38
38
39
- static void swap_if_negative (timelib_rel_time * rt )
40
- {
41
- if (rt -> y == 0 && rt -> m == 0 && rt -> d == 0 && rt -> h == 0 && rt -> i == 0 && rt -> s == 0 && rt -> us == 0 ) {
42
- return ;
43
- }
44
- if (rt -> y >= 0 && rt -> m >= 0 && rt -> d >= 0 && rt -> h >= 0 && rt -> i >= 0 && rt -> s >= 0 && rt -> us >= 0 ) {
45
- return ;
46
- }
47
-
48
- rt -> invert = 1 - rt -> invert ;
49
- rt -> y = 0 - rt -> y ;
50
- rt -> m = 0 - rt -> m ;
51
- rt -> d = 0 - rt -> d ;
52
- rt -> h = 0 - rt -> h ;
53
- rt -> i = 0 - rt -> i ;
54
- rt -> s = 0 - rt -> s ;
55
- rt -> us = 0 - rt -> us ;
56
- }
57
-
58
39
static void sort_old_to_new (timelib_time * * one , timelib_time * * two , timelib_rel_time * rt )
59
40
{
60
41
/* Check whether date/times need to be inverted. If both times are
@@ -115,80 +96,48 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
115
96
rt -> days = timelib_diff_days (one , two );
116
97
117
98
/* Fall Back: Cater for transition period, where rt->invert is 0, but there are negative numbers */
118
- if (one -> dst == 1 && two -> dst == 0 ) {
119
- /* First for two "Type 3" times */
120
- if (one -> zone_type == TIMELIB_ZONETYPE_ID && two -> zone_type == TIMELIB_ZONETYPE_ID ) {
121
- int success = timelib_get_time_zone_offset_info (two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
122
- if (
123
- success &&
124
- one -> sse < trans_transition_time &&
125
- one -> sse >= trans_transition_time + dst_corr
126
- ) {
127
- timelib_sll flipped = SECS_PER_HOUR + (rt -> i * 60 ) + (rt -> s );
128
- rt -> h = flipped / SECS_PER_HOUR ;
129
- rt -> i = (flipped - rt -> h * SECS_PER_HOUR ) / 60 ;
130
- rt -> s = flipped % 60 ;
131
- }
132
- } else if (rt -> h == 0 && (rt -> i < 0 || rt -> s < 0 )) {
133
- /* Then for all the others */
134
- timelib_sll flipped = SECS_PER_HOUR + (rt -> i * 60 ) + (rt -> s );
135
- rt -> h = flipped / SECS_PER_HOUR ;
136
- rt -> i = (flipped - rt -> h * SECS_PER_HOUR ) / 60 ;
137
- rt -> s = flipped % 60 ;
138
- dst_corr += SECS_PER_HOUR ;
139
- dst_h_corr ++ ;
140
- }
99
+ if (two -> sse < one -> sse ) {
100
+ timelib_sll flipped = llabs ((rt -> i * 60 ) + (rt -> s ) - dst_corr );
101
+ rt -> h = flipped / SECS_PER_HOUR ;
102
+ rt -> i = (flipped - rt -> h * SECS_PER_HOUR ) / 60 ;
103
+ rt -> s = flipped % 60 ;
104
+
105
+ rt -> invert = 1 - rt -> invert ;
141
106
}
142
107
143
108
timelib_do_rel_normalize (rt -> invert ? one : two , rt );
144
109
145
- /* Do corrections for "Type 3" times with the same TZID */
146
- if (one -> zone_type == TIMELIB_ZONETYPE_ID && two -> zone_type == TIMELIB_ZONETYPE_ID && strcmp (one -> tz_info -> name , two -> tz_info -> name ) == 0 ) {
147
- if (one -> dst == 1 && two -> dst == 0 ) { /* Fall Back */
148
- if (two -> tz_info ) {
149
- int success = timelib_get_time_zone_offset_info (two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
150
-
151
- if (
152
- success &&
153
- two -> sse >= trans_transition_time &&
154
- ((two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > (two -> sse - trans_transition_time )
155
- ) {
156
- rt -> h -= dst_h_corr ;
157
- rt -> i -= dst_m_corr ;
158
- }
110
+ if (one -> dst == 1 && two -> dst == 0 ) { /* Fall Back */
111
+ if (two -> tz_info ) {
112
+ if ((two -> sse - one -> sse + dst_corr ) < SECS_PER_DAY ) {
113
+ rt -> h -= dst_h_corr ;
114
+ rt -> i -= dst_m_corr ;
159
115
}
160
- } else if ( one -> dst == 0 && two -> dst == 1 ) { /* Spring Forward */
161
- if (two -> tz_info ) {
162
- int success = timelib_get_time_zone_offset_info (two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
163
-
164
- if (
165
- success &&
166
- !(( one -> sse + SECS_PER_DAY > trans_transition_time ) && ( one -> sse + SECS_PER_DAY <= ( trans_transition_time + dst_corr ))) &&
167
- two -> sse >= trans_transition_time &&
168
- (( two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > ( two -> sse - trans_transition_time )
169
- ) {
170
- rt -> h -= dst_h_corr ;
171
- rt -> i -= dst_m_corr ;
172
- }
116
+ }
117
+ } else if (one -> dst == 0 && two -> dst == 1 ) { /* Spring Forward */
118
+ if (two -> tz_info ) {
119
+ int success = timelib_get_time_zone_offset_info ( two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
120
+
121
+ if (
122
+ success &&
123
+ !(( one -> sse + SECS_PER_DAY > trans_transition_time ) && ( one -> sse + SECS_PER_DAY <= ( trans_transition_time + dst_corr ))) &&
124
+ two -> sse >= trans_transition_time &&
125
+ (( two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > ( two -> sse - trans_transition_time )
126
+ ) {
127
+ rt -> h -= dst_h_corr ;
128
+ rt -> i -= dst_m_corr ;
173
129
}
174
- } else if ( two -> sse - one -> sse >= SECS_PER_DAY ) {
175
- /* Check whether we're in the period to the next transition time */
176
- if ( timelib_get_time_zone_offset_info ( two -> sse - two -> z , two -> tz_info , & trans_offset , & trans_transition_time , NULL )) {
177
- dst_corr = one -> z - trans_offset ;
178
-
179
- if ( two -> sse >= trans_transition_time - dst_corr && two -> sse < trans_transition_time ) {
180
- rt -> d -- ;
181
- rt -> h = 24 ;
182
- }
130
+ }
131
+ } else if ( two -> sse - one -> sse >= SECS_PER_DAY ) {
132
+ /* Check whether we're in the period to the next transition time */
133
+ if ( timelib_get_time_zone_offset_info ( two -> sse - two -> z , two -> tz_info , & trans_offset , & trans_transition_time , NULL )) {
134
+ dst_corr = one -> z - trans_offset ;
135
+
136
+ if ( two -> sse >= trans_transition_time - dst_corr && two -> sse < trans_transition_time ) {
137
+ rt -> d -- ;
138
+ rt -> h = 24 ;
183
139
}
184
140
}
185
- } else {
186
- rt -> h -= dst_h_corr ;
187
- rt -> i -= dst_m_corr ;
188
-
189
- swap_if_negative (rt );
190
-
191
- timelib_do_rel_normalize (rt -> invert ? one : two , rt );
192
141
}
193
142
194
143
return rt ;
0 commit comments