@@ -90,8 +90,9 @@ static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_
90
90
static timelib_rel_time * timelib_diff_with_tzid (timelib_time * one , timelib_time * two )
91
91
{
92
92
timelib_rel_time * rt ;
93
- timelib_sll dst_corr = 0 , dst_h_corr = 0 , dst_m_corr = 0 ;
94
- timelib_time_offset * trans = NULL ;
93
+ timelib_sll dst_corr = 0 , dst_h_corr = 0 , dst_m_corr = 0 ;
94
+ int32_t trans_offset ;
95
+ timelib_sll trans_transition_time ;
95
96
96
97
rt = timelib_rel_time_ctor ();
97
98
rt -> invert = 0 ;
@@ -117,16 +118,16 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
117
118
if (one -> dst == 1 && two -> dst == 0 ) {
118
119
/* First for two "Type 3" times */
119
120
if (one -> zone_type == TIMELIB_ZONETYPE_ID && two -> zone_type == TIMELIB_ZONETYPE_ID ) {
120
- trans = timelib_get_time_zone_info (two -> sse , two -> tz_info );
121
- if (trans ) {
122
- if (one -> sse < trans -> transition_time && one -> sse >= trans -> transition_time + dst_corr ) {
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
+ ) {
123
127
timelib_sll flipped = SECS_PER_HOUR + (rt -> i * 60 ) + (rt -> s );
124
128
rt -> h = flipped / SECS_PER_HOUR ;
125
129
rt -> i = (flipped - rt -> h * SECS_PER_HOUR ) / 60 ;
126
130
rt -> s = flipped % 60 ;
127
- }
128
- timelib_time_offset_dtor (trans );
129
- trans = NULL ;
130
131
}
131
132
} else if (rt -> h == 0 && (rt -> i < 0 || rt -> s < 0 )) {
132
133
/* Then for all the others */
@@ -145,39 +146,40 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
145
146
if (one -> zone_type == TIMELIB_ZONETYPE_ID && two -> zone_type == TIMELIB_ZONETYPE_ID && strcmp (one -> tz_info -> name , two -> tz_info -> name ) == 0 ) {
146
147
if (one -> dst == 1 && two -> dst == 0 ) { /* Fall Back */
147
148
if (two -> tz_info ) {
148
- trans = timelib_get_time_zone_info (two -> sse , two -> tz_info );
149
+ int success = timelib_get_time_zone_offset_info (two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
149
150
150
151
if (
151
- trans &&
152
- two -> sse >= trans -> transition_time &&
153
- ((two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > (two -> sse - trans -> transition_time )
152
+ success &&
153
+ two -> sse >= trans_transition_time &&
154
+ ((two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > (two -> sse - trans_transition_time )
154
155
) {
155
156
rt -> h -= dst_h_corr ;
156
157
rt -> i -= dst_m_corr ;
157
158
}
158
159
}
159
160
} else if (one -> dst == 0 && two -> dst == 1 ) { /* Spring Forward */
160
161
if (two -> tz_info ) {
161
- trans = timelib_get_time_zone_info (two -> sse , two -> tz_info );
162
+ int success = timelib_get_time_zone_offset_info (two -> sse , two -> tz_info , & trans_offset , & trans_transition_time , NULL );
162
163
163
164
if (
164
- trans &&
165
- !((one -> sse + SECS_PER_DAY > trans -> transition_time ) && (one -> sse + SECS_PER_DAY <= (trans -> transition_time + dst_corr ))) &&
166
- two -> sse >= trans -> transition_time &&
167
- ((two -> sse - one -> sse + dst_corr ) % SECS_PER_DAY ) > (two -> sse - trans -> transition_time )
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 )
168
169
) {
169
170
rt -> h -= dst_h_corr ;
170
171
rt -> i -= dst_m_corr ;
171
172
}
172
173
}
173
174
} else if (two -> sse - one -> sse >= SECS_PER_DAY ) {
174
175
/* Check whether we're in the period to the next transition time */
175
- trans = timelib_get_time_zone_info ( two -> sse - two -> z , two -> tz_info );
176
- dst_corr = one -> z - trans -> offset ;
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 ;
177
178
178
- if (two -> sse >= trans -> transition_time - dst_corr && two -> sse < trans -> transition_time ) {
179
- rt -> d -- ;
180
- rt -> h = 24 ;
179
+ if (two -> sse >= trans_transition_time - dst_corr && two -> sse < trans_transition_time ) {
180
+ rt -> d -- ;
181
+ rt -> h = 24 ;
182
+ }
181
183
}
182
184
}
183
185
} else {
@@ -189,10 +191,6 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
189
191
timelib_do_rel_normalize (rt -> invert ? one : two , rt );
190
192
}
191
193
192
- if (trans ) {
193
- timelib_time_offset_dtor (trans );
194
- }
195
-
196
194
return rt ;
197
195
}
198
196
0 commit comments