@@ -90,8 +90,9 @@ static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_
9090static timelib_rel_time * timelib_diff_with_tzid (timelib_time * one , timelib_time * two )
9191{
9292 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 ;
9596
9697 rt = timelib_rel_time_ctor ();
9798 rt -> invert = 0 ;
@@ -117,16 +118,16 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
117118 if (one -> dst == 1 && two -> dst == 0 ) {
118119 /* First for two "Type 3" times */
119120 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+ ) {
123127 timelib_sll flipped = SECS_PER_HOUR + (rt -> i * 60 ) + (rt -> s );
124128 rt -> h = flipped / SECS_PER_HOUR ;
125129 rt -> i = (flipped - rt -> h * SECS_PER_HOUR ) / 60 ;
126130 rt -> s = flipped % 60 ;
127- }
128- timelib_time_offset_dtor (trans );
129- trans = NULL ;
130131 }
131132 } else if (rt -> h == 0 && (rt -> i < 0 || rt -> s < 0 )) {
132133 /* Then for all the others */
@@ -145,39 +146,40 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
145146 if (one -> zone_type == TIMELIB_ZONETYPE_ID && two -> zone_type == TIMELIB_ZONETYPE_ID && strcmp (one -> tz_info -> name , two -> tz_info -> name ) == 0 ) {
146147 if (one -> dst == 1 && two -> dst == 0 ) { /* Fall Back */
147148 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 );
149150
150151 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 )
154155 ) {
155156 rt -> h -= dst_h_corr ;
156157 rt -> i -= dst_m_corr ;
157158 }
158159 }
159160 } else if (one -> dst == 0 && two -> dst == 1 ) { /* Spring Forward */
160161 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 );
162163
163164 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 )
168169 ) {
169170 rt -> h -= dst_h_corr ;
170171 rt -> i -= dst_m_corr ;
171172 }
172173 }
173174 } else if (two -> sse - one -> sse >= SECS_PER_DAY ) {
174175 /* 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 ;
177178
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+ }
181183 }
182184 }
183185 } else {
@@ -189,10 +191,6 @@ static timelib_rel_time *timelib_diff_with_tzid(timelib_time *one, timelib_time
189191 timelib_do_rel_normalize (rt -> invert ? one : two , rt );
190192 }
191193
192- if (trans ) {
193- timelib_time_offset_dtor (trans );
194- }
195-
196194 return rt ;
197195}
198196
0 commit comments