Lines Matching refs:tz

66 static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)  in read_php_preamble()  argument
75 tz->bc = (**tzf == '\1'); in read_php_preamble()
79 memcpy(tz->location.country_code, *tzf, 2); in read_php_preamble()
80 tz->location.country_code[2] = '\0'; in read_php_preamble()
89 static int read_tzif_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in read_tzif_preamble() argument
110 tz->bc = 0; in read_tzif_preamble()
111 tz->location.country_code[0] = '?'; in read_tzif_preamble()
112 tz->location.country_code[1] = '?'; in read_tzif_preamble()
113 tz->location.country_code[2] = '\0'; in read_tzif_preamble()
121 static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz, unsigned int *type) in read_preamble() argument
126 return read_php_preamble(tzf, tz); in read_preamble()
129 return read_tzif_preamble(tzf, tz); in read_preamble()
135 static void read_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_header() argument
140 tz->bit32.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_header()
141 tz->bit32.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_header()
142 tz->bit32.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_header()
143 tz->bit32.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_header()
144 tz->bit32.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_header()
145 tz->bit32.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_header()
149 static void skip_64bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in skip_64bit_transitions() argument
151 if (tz->bit64.timecnt) { in skip_64bit_transitions()
152 *tzf += (sizeof(int64_t) * tz->bit64.timecnt); in skip_64bit_transitions()
153 *tzf += (sizeof(unsigned char) * tz->bit64.timecnt); in skip_64bit_transitions()
157 static int read_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in read_transitions() argument
163 if (tz->bit32.timecnt) { in read_transitions()
164 buffer = (int32_t*) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t)); in read_transitions()
168 memcpy(buffer, *tzf, sizeof(int32_t) * tz->bit32.timecnt); in read_transitions()
169 *tzf += (sizeof(int32_t) * tz->bit32.timecnt); in read_transitions()
170 for (i = 0; i < tz->bit32.timecnt; i++) { in read_transitions()
178 cbuffer = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char)); in read_transitions()
183 memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit32.timecnt); in read_transitions()
184 *tzf += sizeof(unsigned char) * tz->bit32.timecnt; in read_transitions()
187 tz->trans = buffer; in read_transitions()
188 tz->trans_idx = cbuffer; in read_transitions()
193 static void skip_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz) in skip_64bit_types() argument
195 *tzf += sizeof(unsigned char) * 6 * tz->bit64.typecnt; in skip_64bit_types()
196 *tzf += sizeof(char) * tz->bit64.charcnt; in skip_64bit_types()
197 if (tz->bit64.leapcnt) { in skip_64bit_types()
198 *tzf += sizeof(int64_t) * tz->bit64.leapcnt * 2; in skip_64bit_types()
200 if (tz->bit64.ttisstdcnt) { in skip_64bit_types()
201 *tzf += sizeof(unsigned char) * tz->bit64.ttisstdcnt; in skip_64bit_types()
203 if (tz->bit64.ttisgmtcnt) { in skip_64bit_types()
204 *tzf += sizeof(unsigned char) * tz->bit64.ttisgmtcnt; in skip_64bit_types()
208 static int read_types(const unsigned char **tzf, timelib_tzinfo *tz) in read_types() argument
214 buffer = (unsigned char*) timelib_malloc(tz->bit32.typecnt * sizeof(unsigned char) * 6); in read_types()
218 memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit32.typecnt); in read_types()
219 *tzf += sizeof(unsigned char) * 6 * tz->bit32.typecnt; in read_types()
221 tz->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(ttinfo)); in read_types()
222 if (!tz->type) { in read_types()
227 for (i = 0; i < tz->bit32.typecnt; i++) { in read_types()
229 tz->type[i].offset = 0; in read_types()
230tz->type[i].offset += (int32_t) (((uint32_t) buffer[j]) << 24) + (buffer[j + 1] << 16) + (buffer[j… in read_types()
231 tz->type[i].isdst = buffer[j + 4]; in read_types()
232 tz->type[i].abbr_idx = buffer[j + 5]; in read_types()
236 tz->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt); in read_types()
237 if (!tz->timezone_abbr) { in read_types()
240 memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit32.charcnt); in read_types()
241 *tzf += sizeof(char) * tz->bit32.charcnt; in read_types()
243 if (tz->bit32.leapcnt) { in read_types()
244 leap_buffer = (int32_t *) timelib_malloc(tz->bit32.leapcnt * 2 * sizeof(int32_t)); in read_types()
248 memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->bit32.leapcnt * 2); in read_types()
249 *tzf += sizeof(int32_t) * tz->bit32.leapcnt * 2; in read_types()
251 tz->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo)); in read_types()
252 if (!tz->leap_times) { in read_types()
256 for (i = 0; i < tz->bit32.leapcnt; i++) { in read_types()
257 tz->leap_times[i].trans = timelib_conv_int_signed(leap_buffer[i * 2]); in read_types()
258 tz->leap_times[i].offset = timelib_conv_int_signed(leap_buffer[i * 2 + 1]); in read_types()
263 if (tz->bit32.ttisstdcnt) { in read_types()
264 buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisstdcnt * sizeof(unsigned char)); in read_types()
268 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisstdcnt); in read_types()
269 *tzf += sizeof(unsigned char) * tz->bit32.ttisstdcnt; in read_types()
271 for (i = 0; i < tz->bit32.ttisstdcnt; i++) { in read_types()
272 tz->type[i].isstdcnt = buffer[i]; in read_types()
277 if (tz->bit32.ttisgmtcnt) { in read_types()
278 buffer = (unsigned char*) timelib_malloc(tz->bit32.ttisgmtcnt * sizeof(unsigned char)); in read_types()
282 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisgmtcnt); in read_types()
283 *tzf += sizeof(unsigned char) * tz->bit32.ttisgmtcnt; in read_types()
285 for (i = 0; i < tz->bit32.ttisgmtcnt; i++) { in read_types()
286 tz->type[i].isgmtcnt = buffer[i]; in read_types()
294 static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz) in skip_posix_string() argument
306 static void read_location(const unsigned char **tzf, timelib_tzinfo *tz) in read_location() argument
312 tz->location.latitude = timelib_conv_int_unsigned(buffer[0]); in read_location()
313 tz->location.latitude = (tz->location.latitude / 100000) - 90; in read_location()
314 tz->location.longitude = timelib_conv_int_unsigned(buffer[1]); in read_location()
315 tz->location.longitude = (tz->location.longitude / 100000) - 180; in read_location()
319 tz->location.comments = timelib_malloc(comments_len + 1); in read_location()
320 memcpy(tz->location.comments, *tzf, comments_len); in read_location()
321 tz->location.comments[comments_len] = '\0'; in read_location()
325 static void set_default_location_and_comments(const unsigned char **tzf, timelib_tzinfo *tz) in set_default_location_and_comments() argument
327 tz->location.latitude = 0; in set_default_location_and_comments()
328 tz->location.longitude = 0; in set_default_location_and_comments()
329 tz->location.comments = timelib_malloc(2); in set_default_location_and_comments()
330 tz->location.comments[0] = '?'; in set_default_location_and_comments()
331 tz->location.comments[1] = '\0'; in set_default_location_and_comments()
334 void timelib_dump_tzinfo(timelib_tzinfo *tz) in timelib_dump_tzinfo() argument
338 printf("Country Code: %s\n", tz->location.country_code); in timelib_dump_tzinfo()
339 printf("Geo Location: %f,%f\n", tz->location.latitude, tz->location.longitude); in timelib_dump_tzinfo()
340 printf("Comments:\n%s\n", tz->location.comments); in timelib_dump_tzinfo()
341 printf("BC: %s\n", tz->bc ? "" : "yes"); in timelib_dump_tzinfo()
342 printf("UTC/Local count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.ttisgmtcnt); in timelib_dump_tzinfo()
343 printf("Std/Wall count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.ttisstdcnt); in timelib_dump_tzinfo()
344 printf("Leap.sec. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.leapcnt); in timelib_dump_tzinfo()
345 printf("Trans. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.timecnt); in timelib_dump_tzinfo()
346 printf("Local types count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.typecnt); in timelib_dump_tzinfo()
347 printf("Zone Abbr. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit32.charcnt); in timelib_dump_tzinfo()
351 (long int) tz->type[0].offset, in timelib_dump_tzinfo()
352 tz->type[0].isdst, in timelib_dump_tzinfo()
353 tz->type[0].abbr_idx, in timelib_dump_tzinfo()
354 &tz->timezone_abbr[tz->type[0].abbr_idx], in timelib_dump_tzinfo()
355 tz->type[0].isstdcnt, in timelib_dump_tzinfo()
356 tz->type[0].isgmtcnt in timelib_dump_tzinfo()
358 for (i = 0; i < tz->bit32.timecnt; i++) { in timelib_dump_tzinfo()
360 tz->trans[i], tz->trans[i], tz->trans_idx[i], in timelib_dump_tzinfo()
361 (long int) tz->type[tz->trans_idx[i]].offset, in timelib_dump_tzinfo()
362 tz->type[tz->trans_idx[i]].isdst, in timelib_dump_tzinfo()
363 tz->type[tz->trans_idx[i]].abbr_idx, in timelib_dump_tzinfo()
364 &tz->timezone_abbr[tz->type[tz->trans_idx[i]].abbr_idx], in timelib_dump_tzinfo()
365 tz->type[tz->trans_idx[i]].isstdcnt, in timelib_dump_tzinfo()
366 tz->type[tz->trans_idx[i]].isgmtcnt in timelib_dump_tzinfo()
369 for (i = 0; i < tz->bit32.leapcnt; i++) { in timelib_dump_tzinfo()
371 tz->leap_times[i].trans, in timelib_dump_tzinfo()
372 (long) tz->leap_times[i].trans, in timelib_dump_tzinfo()
373 tz->leap_times[i].offset); in timelib_dump_tzinfo()
420 static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in skip_64bit_preamble() argument
433 static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_header() argument
438 tz->bit64.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_64bit_header()
439 tz->bit64.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_64bit_header()
440 tz->bit64.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_64bit_header()
441 tz->bit64.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_64bit_header()
442 tz->bit64.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_64bit_header()
443 tz->bit64.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_64bit_header()
512 void timelib_tzinfo_dtor(timelib_tzinfo *tz) in timelib_tzinfo_dtor() argument
514 TIMELIB_TIME_FREE(tz->name); in timelib_tzinfo_dtor()
515 TIMELIB_TIME_FREE(tz->trans); in timelib_tzinfo_dtor()
516 TIMELIB_TIME_FREE(tz->trans_idx); in timelib_tzinfo_dtor()
517 TIMELIB_TIME_FREE(tz->type); in timelib_tzinfo_dtor()
518 TIMELIB_TIME_FREE(tz->timezone_abbr); in timelib_tzinfo_dtor()
519 TIMELIB_TIME_FREE(tz->leap_times); in timelib_tzinfo_dtor()
520 TIMELIB_TIME_FREE(tz->location.comments); in timelib_tzinfo_dtor()
521 TIMELIB_TIME_FREE(tz); in timelib_tzinfo_dtor()
522 tz = NULL; in timelib_tzinfo_dtor()
525 timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz) in timelib_tzinfo_clone() argument
527 timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name); in timelib_tzinfo_clone()
528 tmp->bit32.ttisgmtcnt = tz->bit32.ttisgmtcnt; in timelib_tzinfo_clone()
529 tmp->bit32.ttisstdcnt = tz->bit32.ttisstdcnt; in timelib_tzinfo_clone()
530 tmp->bit32.leapcnt = tz->bit32.leapcnt; in timelib_tzinfo_clone()
531 tmp->bit32.timecnt = tz->bit32.timecnt; in timelib_tzinfo_clone()
532 tmp->bit32.typecnt = tz->bit32.typecnt; in timelib_tzinfo_clone()
533 tmp->bit32.charcnt = tz->bit32.charcnt; in timelib_tzinfo_clone()
535 if (tz->bit32.timecnt) { in timelib_tzinfo_clone()
536 tmp->trans = (int32_t *) timelib_malloc(tz->bit32.timecnt * sizeof(int32_t)); in timelib_tzinfo_clone()
537 tmp->trans_idx = (unsigned char*) timelib_malloc(tz->bit32.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
538 memcpy(tmp->trans, tz->trans, tz->bit32.timecnt * sizeof(int32_t)); in timelib_tzinfo_clone()
539 memcpy(tmp->trans_idx, tz->trans_idx, tz->bit32.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
542 tmp->type = (ttinfo*) timelib_malloc(tz->bit32.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
543 memcpy(tmp->type, tz->type, tz->bit32.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
545 tmp->timezone_abbr = (char*) timelib_malloc(tz->bit32.charcnt); in timelib_tzinfo_clone()
546 memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->bit32.charcnt); in timelib_tzinfo_clone()
548 if (tz->bit32.leapcnt) { in timelib_tzinfo_clone()
549 tmp->leap_times = (tlinfo*) timelib_malloc(tz->bit32.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
550 memcpy(tmp->leap_times, tz->leap_times, tz->bit32.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
556 static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_ti… in fetch_timezone_offset() argument
562 if (!tz->bit32.timecnt || !tz->trans) { in fetch_timezone_offset()
564 if (tz->bit32.typecnt == 1) { in fetch_timezone_offset()
565 return &(tz->type[0]); in fetch_timezone_offset()
574 if (ts < tz->trans[0]) { in fetch_timezone_offset()
579 while (j < tz->bit32.timecnt && tz->type[tz->trans_idx[j]].isdst) { in fetch_timezone_offset()
582 if (j == tz->bit32.timecnt) { in fetch_timezone_offset()
585 return &(tz->type[tz->trans_idx[j]]); in fetch_timezone_offset()
590 for (i = 0; i < tz->bit32.timecnt; i++) { in fetch_timezone_offset()
591 if (ts < tz->trans[i]) { in fetch_timezone_offset()
592 *transition_time = tz->trans[i - 1]; in fetch_timezone_offset()
593 return &(tz->type[tz->trans_idx[i - 1]]); in fetch_timezone_offset()
596 *transition_time = tz->trans[tz->bit32.timecnt - 1]; in fetch_timezone_offset()
597 return &(tz->type[tz->trans_idx[tz->bit32.timecnt - 1]]); in fetch_timezone_offset()
600 static tlinfo* fetch_leaptime_offset(timelib_tzinfo *tz, timelib_sll ts) in fetch_leaptime_offset() argument
604 if (!tz->bit32.leapcnt || !tz->leap_times) { in fetch_leaptime_offset()
608 for (i = tz->bit32.leapcnt - 1; i > 0; i--) { in fetch_leaptime_offset()
609 if (ts > tz->leap_times[i].trans) { in fetch_leaptime_offset()
610 return &(tz->leap_times[i]); in fetch_leaptime_offset()
616 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz) in timelib_timestamp_is_in_dst() argument
621 if ((to = fetch_timezone_offset(tz, ts, &dummy))) { in timelib_timestamp_is_in_dst()
627 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz) in timelib_get_time_zone_info() argument
636 if ((to = fetch_timezone_offset(tz, ts, &transition_time))) { in timelib_get_time_zone_info()
638 abbr = &(tz->timezone_abbr[to->abbr_idx]); in timelib_get_time_zone_info()
643 abbr = tz->timezone_abbr; in timelib_get_time_zone_info()
648 if ((tl = fetch_leaptime_offset(tz, ts))) { in timelib_get_time_zone_info()