Lines Matching refs:tz

93 static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)  in read_php_preamble()  argument
102 tz->bc = (**tzf == '\1'); in read_php_preamble()
106 memcpy(tz->location.country_code, *tzf, 2); in read_php_preamble()
107 tz->location.country_code[2] = '\0'; in read_php_preamble()
116 static int read_tzif_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in read_tzif_preamble() argument
137 tz->bc = 0; in read_tzif_preamble()
138 tz->location.country_code[0] = '?'; in read_tzif_preamble()
139 tz->location.country_code[1] = '?'; in read_tzif_preamble()
140 tz->location.country_code[2] = '\0'; in read_tzif_preamble()
148 static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz, unsigned int *type) in read_preamble() argument
153 return read_php_preamble(tzf, tz); in read_preamble()
156 return read_tzif_preamble(tzf, tz); in read_preamble()
162 static void read_32bit_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_32bit_header() argument
167 tz->_bit32.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_32bit_header()
168 tz->_bit32.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_32bit_header()
169 tz->_bit32.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_32bit_header()
170 tz->_bit32.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_32bit_header()
171 tz->_bit32.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_32bit_header()
172 tz->_bit32.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_32bit_header()
177 static int detect_slim_file(timelib_tzinfo *tz) in detect_slim_file() argument
180 (tz->_bit32.ttisgmtcnt == 0) && in detect_slim_file()
181 (tz->_bit32.ttisstdcnt == 0) && in detect_slim_file()
182 (tz->_bit32.leapcnt == 0) && in detect_slim_file()
183 (tz->_bit32.timecnt == 0) && in detect_slim_file()
184 (tz->_bit32.typecnt == 1) && in detect_slim_file()
185 (tz->_bit32.charcnt == 1) in detect_slim_file()
193 static int read_64bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_transitions() argument
199 if (tz->bit64.timecnt) { in read_64bit_transitions()
200 buffer = (int64_t*) timelib_malloc(tz->bit64.timecnt * sizeof(int64_t)); in read_64bit_transitions()
204 memcpy(buffer, *tzf, sizeof(int64_t) * tz->bit64.timecnt); in read_64bit_transitions()
205 *tzf += (sizeof(int64_t) * tz->bit64.timecnt); in read_64bit_transitions()
206 for (i = 0; i < tz->bit64.timecnt; i++) { in read_64bit_transitions()
214 cbuffer = (unsigned char*) timelib_malloc(tz->bit64.timecnt * sizeof(unsigned char)); in read_64bit_transitions()
219 memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit64.timecnt); in read_64bit_transitions()
220 *tzf += sizeof(unsigned char) * tz->bit64.timecnt; in read_64bit_transitions()
223 tz->trans = buffer; in read_64bit_transitions()
224 tz->trans_idx = cbuffer; in read_64bit_transitions()
229 static void skip_32bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in skip_32bit_transitions() argument
231 if (tz->_bit32.timecnt) { in skip_32bit_transitions()
232 *tzf += (sizeof(int32_t) * tz->_bit32.timecnt); in skip_32bit_transitions()
233 *tzf += sizeof(unsigned char) * tz->_bit32.timecnt; in skip_32bit_transitions()
237 static int read_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_types() argument
244 buffer = (unsigned char*) timelib_malloc(tz->bit64.typecnt * sizeof(unsigned char) * 6); in read_64bit_types()
248 memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit64.typecnt); in read_64bit_types()
249 *tzf += sizeof(unsigned char) * 6 * tz->bit64.typecnt; in read_64bit_types()
251 tz->type = (ttinfo*) timelib_calloc(1, tz->bit64.typecnt * sizeof(ttinfo)); in read_64bit_types()
252 if (!tz->type) { in read_64bit_types()
257 for (i = 0; i < tz->bit64.typecnt; i++) { in read_64bit_types()
259 tz->type[i].offset = 0; in read_64bit_types()
260tz->type[i].offset += (int32_t) (((uint32_t) buffer[j]) << 24) + (buffer[j + 1] << 16) + (buffer[j… in read_64bit_types()
261 tz->type[i].isdst = buffer[j + 4]; in read_64bit_types()
262 tz->type[i].abbr_idx = buffer[j + 5]; in read_64bit_types()
267 tz->timezone_abbr = (char*) timelib_malloc(tz->bit64.charcnt); in read_64bit_types()
268 if (!tz->timezone_abbr) { in read_64bit_types()
271 memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit64.charcnt); in read_64bit_types()
272 *tzf += sizeof(char) * tz->bit64.charcnt; in read_64bit_types()
275 if (tz->bit64.leapcnt) { in read_64bit_types()
276 leap_buffer = (int32_t *) timelib_malloc(tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t))); in read_64bit_types()
280 memcpy(leap_buffer, *tzf, tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t))); in read_64bit_types()
281 *tzf += tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t)); in read_64bit_types()
283 tz->leap_times = (tlinfo*) timelib_malloc(tz->bit64.leapcnt * sizeof(tlinfo)); in read_64bit_types()
284 if (!tz->leap_times) { in read_64bit_types()
288 for (i = 0; i < tz->bit64.leapcnt; i++) { in read_64bit_types()
289tz->leap_times[i].trans = timelib_conv_int64_signed(leap_buffer[i * 3 + 1] * 4294967296 + leap_buf… in read_64bit_types()
290 tz->leap_times[i].offset = timelib_conv_int_signed(leap_buffer[i * 3 + 2]); in read_64bit_types()
296 if (tz->bit64.ttisstdcnt) { in read_64bit_types()
297 buffer = (unsigned char*) timelib_malloc(tz->bit64.ttisstdcnt * sizeof(unsigned char)); in read_64bit_types()
301 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit64.ttisstdcnt); in read_64bit_types()
302 *tzf += sizeof(unsigned char) * tz->bit64.ttisstdcnt; in read_64bit_types()
304 for (i = 0; i < tz->bit64.ttisstdcnt; i++) { in read_64bit_types()
305 tz->type[i].isstdcnt = buffer[i]; in read_64bit_types()
311 if (tz->bit64.ttisgmtcnt) { in read_64bit_types()
312 buffer = (unsigned char*) timelib_malloc(tz->bit64.ttisgmtcnt * sizeof(unsigned char)); in read_64bit_types()
316 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit64.ttisgmtcnt); in read_64bit_types()
317 *tzf += sizeof(unsigned char) * tz->bit64.ttisgmtcnt; in read_64bit_types()
319 for (i = 0; i < tz->bit64.ttisgmtcnt; i++) { in read_64bit_types()
320 tz->type[i].isgmtcnt = buffer[i]; in read_64bit_types()
328 static void skip_32bit_types(const unsigned char **tzf, timelib_tzinfo *tz) in skip_32bit_types() argument
331 *tzf += sizeof(unsigned char) * 6 * tz->_bit32.typecnt; in skip_32bit_types()
334 *tzf += sizeof(char) * tz->_bit32.charcnt; in skip_32bit_types()
337 if (tz->_bit32.leapcnt) { in skip_32bit_types()
338 *tzf += sizeof(int32_t) * tz->_bit32.leapcnt * 2; in skip_32bit_types()
342 if (tz->_bit32.ttisstdcnt) { in skip_32bit_types()
343 *tzf += sizeof(unsigned char) * tz->_bit32.ttisstdcnt; in skip_32bit_types()
347 if (tz->_bit32.ttisgmtcnt) { in skip_32bit_types()
348 *tzf += sizeof(unsigned char) * tz->_bit32.ttisgmtcnt; in skip_32bit_types()
352 static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz) in skip_posix_string() argument
364 static void read_location(const unsigned char **tzf, timelib_tzinfo *tz) in read_location() argument
370 tz->location.latitude = timelib_conv_int_unsigned(buffer[0]); in read_location()
371 tz->location.latitude = (tz->location.latitude / 100000) - 90; in read_location()
372 tz->location.longitude = timelib_conv_int_unsigned(buffer[1]); in read_location()
373 tz->location.longitude = (tz->location.longitude / 100000) - 180; in read_location()
377 tz->location.comments = timelib_malloc(comments_len + 1); in read_location()
378 memcpy(tz->location.comments, *tzf, comments_len); in read_location()
379 tz->location.comments[comments_len] = '\0'; in read_location()
383 static void set_default_location_and_comments(const unsigned char **tzf, timelib_tzinfo *tz) in set_default_location_and_comments() argument
385 tz->location.latitude = 0; in set_default_location_and_comments()
386 tz->location.longitude = 0; in set_default_location_and_comments()
387 tz->location.comments = timelib_malloc(2); in set_default_location_and_comments()
388 tz->location.comments[0] = '?'; in set_default_location_and_comments()
389 tz->location.comments[1] = '\0'; in set_default_location_and_comments()
392 void timelib_dump_tzinfo(timelib_tzinfo *tz) in timelib_dump_tzinfo() argument
396 printf("Country Code: %s\n", tz->location.country_code); in timelib_dump_tzinfo()
397 printf("Geo Location: %f,%f\n", tz->location.latitude, tz->location.longitude); in timelib_dump_tzinfo()
398 printf("Comments:\n%s\n", tz->location.comments); in timelib_dump_tzinfo()
399 printf("BC: %s\n", tz->bc ? "" : "yes"); in timelib_dump_tzinfo()
400 printf("Slim File: %s\n", detect_slim_file(tz) ? "yes" : "no"); in timelib_dump_tzinfo()
403 printf("UTC/Local count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.ttisgmtcnt); in timelib_dump_tzinfo()
404 printf("Std/Wall count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.ttisstdcnt); in timelib_dump_tzinfo()
405 printf("Leap.sec. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.leapcnt); in timelib_dump_tzinfo()
406 printf("Trans. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.timecnt); in timelib_dump_tzinfo()
407 printf("Local types count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.typecnt); in timelib_dump_tzinfo()
408 printf("Zone Abbr. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.charcnt); in timelib_dump_tzinfo()
412 (long int) tz->type[0].offset, in timelib_dump_tzinfo()
413 tz->type[0].isdst, in timelib_dump_tzinfo()
414 tz->type[0].abbr_idx, in timelib_dump_tzinfo()
415 &tz->timezone_abbr[tz->type[0].abbr_idx], in timelib_dump_tzinfo()
416 tz->type[0].isstdcnt, in timelib_dump_tzinfo()
417 tz->type[0].isgmtcnt in timelib_dump_tzinfo()
419 for (i = 0; i < tz->bit64.timecnt; i++) { in timelib_dump_tzinfo()
421 tz->trans[i], tz->trans[i], tz->trans_idx[i], in timelib_dump_tzinfo()
422 (long int) tz->type[tz->trans_idx[i]].offset, in timelib_dump_tzinfo()
423 tz->type[tz->trans_idx[i]].isdst, in timelib_dump_tzinfo()
424 tz->type[tz->trans_idx[i]].abbr_idx, in timelib_dump_tzinfo()
425 &tz->timezone_abbr[tz->type[tz->trans_idx[i]].abbr_idx], in timelib_dump_tzinfo()
426 tz->type[tz->trans_idx[i]].isstdcnt, in timelib_dump_tzinfo()
427 tz->type[tz->trans_idx[i]].isgmtcnt in timelib_dump_tzinfo()
430 for (i = 0; i < tz->bit64.leapcnt; i++) { in timelib_dump_tzinfo()
432 tz->leap_times[i].trans, in timelib_dump_tzinfo()
433 (long) tz->leap_times[i].trans, in timelib_dump_tzinfo()
434 tz->leap_times[i].offset); in timelib_dump_tzinfo()
481 static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in skip_64bit_preamble() argument
494 static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_header() argument
499 tz->bit64.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_64bit_header()
500 tz->bit64.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_64bit_header()
501 tz->bit64.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_64bit_header()
502 tz->bit64.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_64bit_header()
503 tz->bit64.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_64bit_header()
504 tz->bit64.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_64bit_header()
579 void timelib_tzinfo_dtor(timelib_tzinfo *tz) in timelib_tzinfo_dtor() argument
581 TIMELIB_TIME_FREE(tz->name); in timelib_tzinfo_dtor()
582 TIMELIB_TIME_FREE(tz->trans); in timelib_tzinfo_dtor()
583 TIMELIB_TIME_FREE(tz->trans_idx); in timelib_tzinfo_dtor()
584 TIMELIB_TIME_FREE(tz->type); in timelib_tzinfo_dtor()
585 TIMELIB_TIME_FREE(tz->timezone_abbr); in timelib_tzinfo_dtor()
586 TIMELIB_TIME_FREE(tz->leap_times); in timelib_tzinfo_dtor()
587 TIMELIB_TIME_FREE(tz->location.comments); in timelib_tzinfo_dtor()
588 TIMELIB_TIME_FREE(tz); in timelib_tzinfo_dtor()
589 tz = NULL; in timelib_tzinfo_dtor()
592 timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz) in timelib_tzinfo_clone() argument
594 timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name); in timelib_tzinfo_clone()
595 tmp->_bit32.ttisgmtcnt = tz->_bit32.ttisgmtcnt; in timelib_tzinfo_clone()
596 tmp->_bit32.ttisstdcnt = tz->_bit32.ttisstdcnt; in timelib_tzinfo_clone()
597 tmp->_bit32.leapcnt = tz->_bit32.leapcnt; in timelib_tzinfo_clone()
598 tmp->_bit32.timecnt = tz->_bit32.timecnt; in timelib_tzinfo_clone()
599 tmp->_bit32.typecnt = tz->_bit32.typecnt; in timelib_tzinfo_clone()
600 tmp->_bit32.charcnt = tz->_bit32.charcnt; in timelib_tzinfo_clone()
601 tmp->bit64.ttisgmtcnt = tz->bit64.ttisgmtcnt; in timelib_tzinfo_clone()
602 tmp->bit64.ttisstdcnt = tz->bit64.ttisstdcnt; in timelib_tzinfo_clone()
603 tmp->bit64.leapcnt = tz->bit64.leapcnt; in timelib_tzinfo_clone()
604 tmp->bit64.timecnt = tz->bit64.timecnt; in timelib_tzinfo_clone()
605 tmp->bit64.typecnt = tz->bit64.typecnt; in timelib_tzinfo_clone()
606 tmp->bit64.charcnt = tz->bit64.charcnt; in timelib_tzinfo_clone()
608 if (tz->bit64.timecnt) { in timelib_tzinfo_clone()
609 tmp->trans = (int64_t *) timelib_malloc(tz->bit64.timecnt * sizeof(int64_t)); in timelib_tzinfo_clone()
610 tmp->trans_idx = (unsigned char*) timelib_malloc(tz->bit64.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
611 memcpy(tmp->trans, tz->trans, tz->bit64.timecnt * sizeof(int64_t)); in timelib_tzinfo_clone()
612 memcpy(tmp->trans_idx, tz->trans_idx, tz->bit64.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
615 tmp->type = (ttinfo*) timelib_malloc(tz->bit64.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
616 memcpy(tmp->type, tz->type, tz->bit64.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
618 tmp->timezone_abbr = (char*) timelib_malloc(tz->bit64.charcnt); in timelib_tzinfo_clone()
619 memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->bit64.charcnt); in timelib_tzinfo_clone()
621 if (tz->bit64.leapcnt) { in timelib_tzinfo_clone()
622 tmp->leap_times = (tlinfo*) timelib_malloc(tz->bit64.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
623 memcpy(tmp->leap_times, tz->leap_times, tz->bit64.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
629 static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_ti… in fetch_timezone_offset() argument
635 if (!tz->bit64.timecnt || !tz->trans) { in fetch_timezone_offset()
636 if (tz->bit64.typecnt == 1) { in fetch_timezone_offset()
638 return &(tz->type[0]); in fetch_timezone_offset()
647 if (ts < tz->trans[0]) { in fetch_timezone_offset()
649 return &(tz->type[0]); in fetch_timezone_offset()
654 for (i = 0; i < tz->bit64.timecnt; i++) { in fetch_timezone_offset()
655 if (ts < tz->trans[i]) { in fetch_timezone_offset()
656 *transition_time = tz->trans[i - 1]; in fetch_timezone_offset()
657 return &(tz->type[tz->trans_idx[i - 1]]); in fetch_timezone_offset()
660 *transition_time = tz->trans[tz->bit64.timecnt - 1]; in fetch_timezone_offset()
661 return &(tz->type[tz->trans_idx[tz->bit64.timecnt - 1]]); in fetch_timezone_offset()
664 static tlinfo* fetch_leaptime_offset(timelib_tzinfo *tz, timelib_sll ts) in fetch_leaptime_offset() argument
668 if (!tz->bit64.leapcnt || !tz->leap_times) { in fetch_leaptime_offset()
672 for (i = tz->bit64.leapcnt - 1; i > 0; i--) { in fetch_leaptime_offset()
673 if (ts > tz->leap_times[i].trans) { in fetch_leaptime_offset()
674 return &(tz->leap_times[i]); in fetch_leaptime_offset()
680 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz) in timelib_timestamp_is_in_dst() argument
685 if ((to = fetch_timezone_offset(tz, ts, &dummy))) { in timelib_timestamp_is_in_dst()
691 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz) in timelib_get_time_zone_info() argument
700 if ((to = fetch_timezone_offset(tz, ts, &transition_time))) { in timelib_get_time_zone_info()
702 abbr = &(tz->timezone_abbr[to->abbr_idx]); in timelib_get_time_zone_info()
707 abbr = tz->timezone_abbr; in timelib_get_time_zone_info()
712 if ((tl = fetch_leaptime_offset(tz, ts))) { in timelib_get_time_zone_info()