Lines Matching refs:tz

87 static int read_php_preamble(const unsigned char **tzf, timelib_tzinfo *tz)  in read_php_preamble()  argument
96 tz->bc = (**tzf == '\1'); in read_php_preamble()
100 memcpy(tz->location.country_code, *tzf, 2); in read_php_preamble()
101 tz->location.country_code[2] = '\0'; in read_php_preamble()
110 static int read_tzif_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in read_tzif_preamble() argument
131 tz->bc = 0; in read_tzif_preamble()
132 tz->location.country_code[0] = '?'; in read_tzif_preamble()
133 tz->location.country_code[1] = '?'; in read_tzif_preamble()
134 tz->location.country_code[2] = '\0'; in read_tzif_preamble()
142 static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz, unsigned int *type) in read_preamble() argument
147 return read_php_preamble(tzf, tz); in read_preamble()
150 return read_tzif_preamble(tzf, tz); in read_preamble()
156 static void read_32bit_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_32bit_header() argument
161 tz->_bit32.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_32bit_header()
162 tz->_bit32.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_32bit_header()
163 tz->_bit32.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_32bit_header()
164 tz->_bit32.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_32bit_header()
165 tz->_bit32.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_32bit_header()
166 tz->_bit32.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_32bit_header()
171 static int read_64bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_transitions() argument
177 if (tz->bit64.timecnt) { in read_64bit_transitions()
178 buffer = (int64_t*) timelib_malloc(tz->bit64.timecnt * sizeof(int64_t)); in read_64bit_transitions()
182 memcpy(buffer, *tzf, sizeof(int64_t) * tz->bit64.timecnt); in read_64bit_transitions()
183 *tzf += (sizeof(int64_t) * tz->bit64.timecnt); in read_64bit_transitions()
184 for (i = 0; i < tz->bit64.timecnt; i++) { in read_64bit_transitions()
192 cbuffer = (unsigned char*) timelib_malloc(tz->bit64.timecnt * sizeof(unsigned char)); in read_64bit_transitions()
197 memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit64.timecnt); in read_64bit_transitions()
198 *tzf += sizeof(unsigned char) * tz->bit64.timecnt; in read_64bit_transitions()
201 tz->trans = buffer; in read_64bit_transitions()
202 tz->trans_idx = cbuffer; in read_64bit_transitions()
207 static void skip_32bit_transitions(const unsigned char **tzf, timelib_tzinfo *tz) in skip_32bit_transitions() argument
209 if (tz->_bit32.timecnt) { in skip_32bit_transitions()
210 *tzf += (sizeof(int32_t) * tz->_bit32.timecnt); in skip_32bit_transitions()
211 *tzf += sizeof(unsigned char) * tz->_bit32.timecnt; in skip_32bit_transitions()
215 static int read_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_types() argument
222 buffer = (unsigned char*) timelib_malloc(tz->bit64.typecnt * sizeof(unsigned char) * 6); in read_64bit_types()
226 memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit64.typecnt); in read_64bit_types()
227 *tzf += sizeof(unsigned char) * 6 * tz->bit64.typecnt; in read_64bit_types()
229 tz->type = (ttinfo*) timelib_malloc(tz->bit64.typecnt * sizeof(ttinfo)); in read_64bit_types()
230 if (!tz->type) { in read_64bit_types()
235 for (i = 0; i < tz->bit64.typecnt; i++) { in read_64bit_types()
237 tz->type[i].offset = 0; in read_64bit_types()
238tz->type[i].offset += (int32_t) (((uint32_t) buffer[j]) << 24) + (buffer[j + 1] << 16) + (buffer[j… in read_64bit_types()
239 tz->type[i].isdst = buffer[j + 4]; in read_64bit_types()
240 tz->type[i].abbr_idx = buffer[j + 5]; in read_64bit_types()
245 tz->timezone_abbr = (char*) timelib_malloc(tz->bit64.charcnt); in read_64bit_types()
246 if (!tz->timezone_abbr) { in read_64bit_types()
249 memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit64.charcnt); in read_64bit_types()
250 *tzf += sizeof(char) * tz->bit64.charcnt; in read_64bit_types()
253 if (tz->bit64.leapcnt) { in read_64bit_types()
254 leap_buffer = (int32_t *) timelib_malloc(tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t))); in read_64bit_types()
258 memcpy(leap_buffer, *tzf, tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t))); in read_64bit_types()
259 *tzf += tz->bit64.leapcnt * (sizeof(int64_t) + sizeof(int32_t)); in read_64bit_types()
261 tz->leap_times = (tlinfo*) timelib_malloc(tz->bit64.leapcnt * sizeof(tlinfo)); in read_64bit_types()
262 if (!tz->leap_times) { in read_64bit_types()
266 for (i = 0; i < tz->bit64.leapcnt; i++) { in read_64bit_types()
267tz->leap_times[i].trans = timelib_conv_int64_signed(leap_buffer[i * 3 + 1] * 4294967296 + leap_buf… in read_64bit_types()
268 tz->leap_times[i].offset = timelib_conv_int_signed(leap_buffer[i * 3 + 2]); in read_64bit_types()
274 if (tz->bit64.ttisstdcnt) { in read_64bit_types()
275 buffer = (unsigned char*) timelib_malloc(tz->bit64.ttisstdcnt * sizeof(unsigned char)); in read_64bit_types()
279 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit64.ttisstdcnt); in read_64bit_types()
280 *tzf += sizeof(unsigned char) * tz->bit64.ttisstdcnt; in read_64bit_types()
282 for (i = 0; i < tz->bit64.ttisstdcnt; i++) { in read_64bit_types()
283 tz->type[i].isstdcnt = buffer[i]; in read_64bit_types()
289 if (tz->bit64.ttisgmtcnt) { in read_64bit_types()
290 buffer = (unsigned char*) timelib_malloc(tz->bit64.ttisgmtcnt * sizeof(unsigned char)); in read_64bit_types()
294 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit64.ttisgmtcnt); in read_64bit_types()
295 *tzf += sizeof(unsigned char) * tz->bit64.ttisgmtcnt; in read_64bit_types()
297 for (i = 0; i < tz->bit64.ttisgmtcnt; i++) { in read_64bit_types()
298 tz->type[i].isgmtcnt = buffer[i]; in read_64bit_types()
306 static void skip_32bit_types(const unsigned char **tzf, timelib_tzinfo *tz) in skip_32bit_types() argument
309 *tzf += sizeof(unsigned char) * 6 * tz->_bit32.typecnt; in skip_32bit_types()
312 *tzf += sizeof(char) * tz->_bit32.charcnt; in skip_32bit_types()
315 if (tz->_bit32.leapcnt) { in skip_32bit_types()
316 *tzf += sizeof(int32_t) * tz->_bit32.leapcnt * 2; in skip_32bit_types()
320 if (tz->_bit32.ttisstdcnt) { in skip_32bit_types()
321 *tzf += sizeof(unsigned char) * tz->_bit32.ttisstdcnt; in skip_32bit_types()
325 if (tz->_bit32.ttisgmtcnt) { in skip_32bit_types()
326 *tzf += sizeof(unsigned char) * tz->_bit32.ttisgmtcnt; in skip_32bit_types()
330 static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz) in skip_posix_string() argument
342 static void read_location(const unsigned char **tzf, timelib_tzinfo *tz) in read_location() argument
348 tz->location.latitude = timelib_conv_int_unsigned(buffer[0]); in read_location()
349 tz->location.latitude = (tz->location.latitude / 100000) - 90; in read_location()
350 tz->location.longitude = timelib_conv_int_unsigned(buffer[1]); in read_location()
351 tz->location.longitude = (tz->location.longitude / 100000) - 180; in read_location()
355 tz->location.comments = timelib_malloc(comments_len + 1); in read_location()
356 memcpy(tz->location.comments, *tzf, comments_len); in read_location()
357 tz->location.comments[comments_len] = '\0'; in read_location()
361 static void set_default_location_and_comments(const unsigned char **tzf, timelib_tzinfo *tz) in set_default_location_and_comments() argument
363 tz->location.latitude = 0; in set_default_location_and_comments()
364 tz->location.longitude = 0; in set_default_location_and_comments()
365 tz->location.comments = timelib_malloc(2); in set_default_location_and_comments()
366 tz->location.comments[0] = '?'; in set_default_location_and_comments()
367 tz->location.comments[1] = '\0'; in set_default_location_and_comments()
370 void timelib_dump_tzinfo(timelib_tzinfo *tz) in timelib_dump_tzinfo() argument
374 printf("Country Code: %s\n", tz->location.country_code); in timelib_dump_tzinfo()
375 printf("Geo Location: %f,%f\n", tz->location.latitude, tz->location.longitude); in timelib_dump_tzinfo()
376 printf("Comments:\n%s\n", tz->location.comments); in timelib_dump_tzinfo()
377 printf("BC: %s\n", tz->bc ? "" : "yes"); in timelib_dump_tzinfo()
380 printf("UTC/Local count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.ttisgmtcnt); in timelib_dump_tzinfo()
381 printf("Std/Wall count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.ttisstdcnt); in timelib_dump_tzinfo()
382 printf("Leap.sec. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.leapcnt); in timelib_dump_tzinfo()
383 printf("Trans. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.timecnt); in timelib_dump_tzinfo()
384 printf("Local types count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.typecnt); in timelib_dump_tzinfo()
385 printf("Zone Abbr. count: " TIMELIB_ULONG_FMT "\n", (timelib_ulong) tz->bit64.charcnt); in timelib_dump_tzinfo()
389 (long int) tz->type[0].offset, in timelib_dump_tzinfo()
390 tz->type[0].isdst, in timelib_dump_tzinfo()
391 tz->type[0].abbr_idx, in timelib_dump_tzinfo()
392 &tz->timezone_abbr[tz->type[0].abbr_idx], in timelib_dump_tzinfo()
393 tz->type[0].isstdcnt, in timelib_dump_tzinfo()
394 tz->type[0].isgmtcnt in timelib_dump_tzinfo()
396 for (i = 0; i < tz->bit64.timecnt; i++) { in timelib_dump_tzinfo()
398 tz->trans[i], tz->trans[i], tz->trans_idx[i], in timelib_dump_tzinfo()
399 (long int) tz->type[tz->trans_idx[i]].offset, in timelib_dump_tzinfo()
400 tz->type[tz->trans_idx[i]].isdst, in timelib_dump_tzinfo()
401 tz->type[tz->trans_idx[i]].abbr_idx, in timelib_dump_tzinfo()
402 &tz->timezone_abbr[tz->type[tz->trans_idx[i]].abbr_idx], in timelib_dump_tzinfo()
403 tz->type[tz->trans_idx[i]].isstdcnt, in timelib_dump_tzinfo()
404 tz->type[tz->trans_idx[i]].isgmtcnt in timelib_dump_tzinfo()
407 for (i = 0; i < tz->bit64.leapcnt; i++) { in timelib_dump_tzinfo()
409 tz->leap_times[i].trans, in timelib_dump_tzinfo()
410 (long) tz->leap_times[i].trans, in timelib_dump_tzinfo()
411 tz->leap_times[i].offset); in timelib_dump_tzinfo()
458 static int skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz) in skip_64bit_preamble() argument
471 static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz) in read_64bit_header() argument
476 tz->bit64.ttisgmtcnt = timelib_conv_int_unsigned(buffer[0]); in read_64bit_header()
477 tz->bit64.ttisstdcnt = timelib_conv_int_unsigned(buffer[1]); in read_64bit_header()
478 tz->bit64.leapcnt = timelib_conv_int_unsigned(buffer[2]); in read_64bit_header()
479 tz->bit64.timecnt = timelib_conv_int_unsigned(buffer[3]); in read_64bit_header()
480 tz->bit64.typecnt = timelib_conv_int_unsigned(buffer[4]); in read_64bit_header()
481 tz->bit64.charcnt = timelib_conv_int_unsigned(buffer[5]); in read_64bit_header()
550 void timelib_tzinfo_dtor(timelib_tzinfo *tz) in timelib_tzinfo_dtor() argument
552 TIMELIB_TIME_FREE(tz->name); in timelib_tzinfo_dtor()
553 TIMELIB_TIME_FREE(tz->trans); in timelib_tzinfo_dtor()
554 TIMELIB_TIME_FREE(tz->trans_idx); in timelib_tzinfo_dtor()
555 TIMELIB_TIME_FREE(tz->type); in timelib_tzinfo_dtor()
556 TIMELIB_TIME_FREE(tz->timezone_abbr); in timelib_tzinfo_dtor()
557 TIMELIB_TIME_FREE(tz->leap_times); in timelib_tzinfo_dtor()
558 TIMELIB_TIME_FREE(tz->location.comments); in timelib_tzinfo_dtor()
559 TIMELIB_TIME_FREE(tz); in timelib_tzinfo_dtor()
560 tz = NULL; in timelib_tzinfo_dtor()
563 timelib_tzinfo *timelib_tzinfo_clone(timelib_tzinfo *tz) in timelib_tzinfo_clone() argument
565 timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name); in timelib_tzinfo_clone()
566 tmp->_bit32.ttisgmtcnt = tz->_bit32.ttisgmtcnt; in timelib_tzinfo_clone()
567 tmp->_bit32.ttisstdcnt = tz->_bit32.ttisstdcnt; in timelib_tzinfo_clone()
568 tmp->_bit32.leapcnt = tz->_bit32.leapcnt; in timelib_tzinfo_clone()
569 tmp->_bit32.timecnt = tz->_bit32.timecnt; in timelib_tzinfo_clone()
570 tmp->_bit32.typecnt = tz->_bit32.typecnt; in timelib_tzinfo_clone()
571 tmp->_bit32.charcnt = tz->_bit32.charcnt; in timelib_tzinfo_clone()
572 tmp->bit64.ttisgmtcnt = tz->bit64.ttisgmtcnt; in timelib_tzinfo_clone()
573 tmp->bit64.ttisstdcnt = tz->bit64.ttisstdcnt; in timelib_tzinfo_clone()
574 tmp->bit64.leapcnt = tz->bit64.leapcnt; in timelib_tzinfo_clone()
575 tmp->bit64.timecnt = tz->bit64.timecnt; in timelib_tzinfo_clone()
576 tmp->bit64.typecnt = tz->bit64.typecnt; in timelib_tzinfo_clone()
577 tmp->bit64.charcnt = tz->bit64.charcnt; in timelib_tzinfo_clone()
579 if (tz->bit64.timecnt) { in timelib_tzinfo_clone()
580 tmp->trans = (int64_t *) timelib_malloc(tz->bit64.timecnt * sizeof(int64_t)); in timelib_tzinfo_clone()
581 tmp->trans_idx = (unsigned char*) timelib_malloc(tz->bit64.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
582 memcpy(tmp->trans, tz->trans, tz->bit64.timecnt * sizeof(int64_t)); in timelib_tzinfo_clone()
583 memcpy(tmp->trans_idx, tz->trans_idx, tz->bit64.timecnt * sizeof(unsigned char)); in timelib_tzinfo_clone()
586 tmp->type = (ttinfo*) timelib_malloc(tz->bit64.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
587 memcpy(tmp->type, tz->type, tz->bit64.typecnt * sizeof(ttinfo)); in timelib_tzinfo_clone()
589 tmp->timezone_abbr = (char*) timelib_malloc(tz->bit64.charcnt); in timelib_tzinfo_clone()
590 memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->bit64.charcnt); in timelib_tzinfo_clone()
592 if (tz->bit64.leapcnt) { in timelib_tzinfo_clone()
593 tmp->leap_times = (tlinfo*) timelib_malloc(tz->bit64.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
594 memcpy(tmp->leap_times, tz->leap_times, tz->bit64.leapcnt * sizeof(tlinfo)); in timelib_tzinfo_clone()
600 static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_ti… in fetch_timezone_offset() argument
606 if (!tz->bit64.timecnt || !tz->trans) { in fetch_timezone_offset()
607 if (tz->bit64.typecnt == 1) { in fetch_timezone_offset()
609 return &(tz->type[0]); in fetch_timezone_offset()
618 if (ts < tz->trans[0]) { in fetch_timezone_offset()
620 return &(tz->type[0]); in fetch_timezone_offset()
625 for (i = 0; i < tz->bit64.timecnt; i++) { in fetch_timezone_offset()
626 if (ts < tz->trans[i]) { in fetch_timezone_offset()
627 *transition_time = tz->trans[i - 1]; in fetch_timezone_offset()
628 return &(tz->type[tz->trans_idx[i - 1]]); in fetch_timezone_offset()
631 *transition_time = tz->trans[tz->bit64.timecnt - 1]; in fetch_timezone_offset()
632 return &(tz->type[tz->trans_idx[tz->bit64.timecnt - 1]]); in fetch_timezone_offset()
635 static tlinfo* fetch_leaptime_offset(timelib_tzinfo *tz, timelib_sll ts) in fetch_leaptime_offset() argument
639 if (!tz->bit64.leapcnt || !tz->leap_times) { in fetch_leaptime_offset()
643 for (i = tz->bit64.leapcnt - 1; i > 0; i--) { in fetch_leaptime_offset()
644 if (ts > tz->leap_times[i].trans) { in fetch_leaptime_offset()
645 return &(tz->leap_times[i]); in fetch_leaptime_offset()
651 int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz) in timelib_timestamp_is_in_dst() argument
656 if ((to = fetch_timezone_offset(tz, ts, &dummy))) { in timelib_timestamp_is_in_dst()
662 timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz) in timelib_get_time_zone_info() argument
671 if ((to = fetch_timezone_offset(tz, ts, &transition_time))) { in timelib_get_time_zone_info()
673 abbr = &(tz->timezone_abbr[to->abbr_idx]); in timelib_get_time_zone_info()
678 abbr = tz->timezone_abbr; in timelib_get_time_zone_info()
683 if ((tl = fetch_leaptime_offset(tz, ts))) { in timelib_get_time_zone_info()