29#define TIMELIB_SUPPORTS_V2DATA
30#define TIMELIB_SUPPORT_SLIM_FILE
33#if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
34# if defined(__LITTLE_ENDIAN__)
35# undef WORDS_BIGENDIAN
37# if defined(__BIG_ENDIAN__)
38# define WORDS_BIGENDIAN
43#if (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN))
44# if __BYTE_ORDER == __BIG_ENDIAN
45# define WORDS_BIGENDIAN
50# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
51# define WORDS_BIGENDIAN
53# undef WORDS_BIGENDIAN
58static inline uint32_t timelib_conv_int_unsigned(uint32_t
value)
63static inline uint64_t timelib_conv_int64_unsigned(uint64_t
value)
68static inline uint32_t timelib_conv_int_unsigned(uint32_t
value)
71 ((
value & 0x000000ff) << 24) +
72 ((
value & 0x0000ff00) << 8) +
73 ((
value & 0x00ff0000) >> 8) +
74 ((
value & 0xff000000) >> 24);
77static inline uint64_t timelib_conv_int64_unsigned(uint64_t
value)
80 ((
value & 0x00000000000000ff) << 56) +
81 ((
value & 0x000000000000ff00) << 40) +
82 ((
value & 0x0000000000ff0000) << 24) +
83 ((
value & 0x00000000ff000000) << 8) +
84 ((
value & 0x000000ff00000000) >> 8) +
85 ((
value & 0x0000ff0000000000) >> 24) +
86 ((
value & 0x00ff000000000000) >> 40) +
87 ((
value & 0xff00000000000000) >> 56);
91#define timelib_conv_int_signed(value) ((int32_t) timelib_conv_int_unsigned((int32_t) value))
92#define timelib_conv_int64_signed(value) ((int64_t) timelib_conv_int64_unsigned((int64_t) value))
94static int read_php_preamble(
const unsigned char **tzf,
timelib_tzinfo *tz)
99 version = (*tzf)[3] -
'0';
103 tz->
bc = (**tzf ==
'\1');
117static int read_tzif_preamble(
const unsigned char **tzf,
timelib_tzinfo *tz)
152static int read_preamble(
const unsigned char **tzf,
timelib_tzinfo *tz,
unsigned int *
type)
155 if (memcmp(*tzf,
"PHP", 3) == 0) {
157 return read_php_preamble(tzf, tz);
158 }
else if (memcmp(*tzf,
"TZif", 4) == 0) {
160 return read_tzif_preamble(tzf, tz);
166static void read_32bit_header(
const unsigned char **tzf,
timelib_tzinfo *tz)
197static int read_64bit_transitions(
const unsigned char **tzf,
timelib_tzinfo *tz)
201 unsigned char *cbuffer =
NULL;
233static void skip_32bit_transitions(
const unsigned char **tzf,
timelib_tzinfo *tz)
241static int read_64bit_types(
const unsigned char **tzf,
timelib_tzinfo *tz)
244 int32_t *leap_buffer;
287 *tzf += tz->
bit64.
leapcnt * (
sizeof(int64_t) +
sizeof(int32_t));
334static void skip_32bit_types(
const unsigned char **tzf,
timelib_tzinfo *tz)
358static void read_posix_string(
const unsigned char **tzf,
timelib_tzinfo *tz)
360 const unsigned char *
begin;
366 while (*tzf[0] !=
'\n') {
397 size_t new_length = old_length +
strlen(abbr) + 1;
406static signed int add_new_ttinfo_index(
timelib_tzinfo *tz, int32_t
offset,
int isdst,
char *abbr)
446static void read_location(
const unsigned char **tzf,
timelib_tzinfo *tz)
449 uint32_t comments_len;
456 comments_len = timelib_conv_int_unsigned(
buffer[2]);
462 *tzf += comments_len;
465static void set_default_location_and_comments(
const unsigned char **tzf,
timelib_tzinfo *tz)
482 "%04lld-%02lld-%02lld %02lld:%02lld:%02lld UT",
497 "%3d [%6ld %1d %3d '%s' (%d,%d)]",
513 char *date_str, *trans_str;
518 printf(
"BC: %s\n", tz->
bc ?
"no" :
"yes");
519 printf(
"Slim File: %s\n", detect_slim_file(tz) ?
"yes" :
"no");
529 trans_str = format_offset_type(tz, 0);
530 printf(
"%22s (%20s) = %s\n",
"",
"", trans_str);
534 date_str = format_ut_time(tz->
trans[i], tz);
535 trans_str = format_offset_type(tz, tz->
trans_idx[i]);
537 "%s (%20" PRId64
") = %s\n",
546 date_str = format_ut_time(tz->
trans[i], tz);
557 printf(
"\n%43sNo POSIX string\n",
"");
562 printf(
"\n%43sEmpty POSIX string\n",
"");
569 printf(
"%43sstd: %s\n",
"", trans_str);
574 printf(
"%43sdst: %s\n",
"", trans_str);
580static int seek_to_tz_position(
const unsigned char **tzf,
const char *
timezone,
const timelib_tzdb *tzdb)
594 }
else if (cmp > 0) {
619 const unsigned char *tzf;
620 return (seek_to_tz_position(&tzf,
timezone, tzdb));
623static int skip_64bit_preamble(
const unsigned char **tzf,
timelib_tzinfo *tz)
625 if (memcmp(*tzf,
"TZif2", 5) == 0) {
628 }
else if (memcmp(*tzf,
"TZif3", 5) == 0) {
631 }
else if (memcmp(*tzf,
"TZif4", 5) == 0) {
639static void read_64bit_header(
const unsigned char **tzf,
timelib_tzinfo *tz)
664 const unsigned char *tzf;
667 int transitions_result, types_result;
672 if (seek_to_tz_position(&tzf,
timezone, tzdb)) {
673 tmp = timelib_tzinfo_ctor(
timezone);
675 version = read_preamble(&tzf, tmp, &
type);
676 if (version < 2 || version > 4) {
683 read_32bit_header(&tzf, tmp);
684 skip_32bit_transitions(&tzf, tmp);
685 skip_32bit_types(&tzf, tmp);
687 if (!skip_64bit_preamble(&tzf, tmp)) {
693 read_64bit_header(&tzf, tmp);
694 if ((transitions_result = read_64bit_transitions(&tzf, tmp)) != 0) {
700 if ((types_result = read_64bit_types(&tzf, tmp)) != 0) {
706 read_posix_string(&tzf, tmp);
709 }
else if (!integrate_posix_string(tmp)) {
716 read_location(&tzf, tmp);
718 set_default_location_and_comments(&tzf, tmp);
802 *transition_time = INT64_MIN;
807 *transition_time = INT64_MIN;
808 return &(tz->
type[0]);
815 if (ts < tz->trans[0]) {
816 *transition_time = INT64_MIN;
817 return &(tz->
type[0]);
844 if (ts < tz->trans[mid]) {
885 int32_t
offset = 0, leap_secs = 0;
902 if ((tl = fetch_leaptime_offset(tz, ts))) {
929 if (transition_time) {
930 *transition_time = tmp_transition_time;
942 return t->
z + (t->
dst * 3600);
962 if ((one->
z + (one->
dst * 3600)) == (two->
z + (two->
dst * 3600))) {
printf(string $format, mixed ... $values)
count(Countable|array $value, int $mode=COUNT_NORMAL)
ttinfo * timelib_fetch_posix_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time)
void timelib_posix_str_dtor(timelib_posix_str *ps)
timelib_posix_str * timelib_parse_posix_str(const char *posix)
const timelib_tzdb_index_entry * timelib_timezone_identifiers_list(const timelib_tzdb *tzdb, int *count)
int timelib_same_timezone(timelib_time *one, timelib_time *two)
timelib_tzinfo * timelib_tzinfo_clone(timelib_tzinfo *tz)
void timelib_dump_tzinfo(timelib_tzinfo *tz)
void timelib_tzinfo_dtor(timelib_tzinfo *tz)
timelib_tzinfo * timelib_parse_tzfile(const char *timezone, const timelib_tzdb *tzdb, int *error_code)
timelib_time_offset * timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz)
timelib_sll timelib_get_current_offset(timelib_time *t)
int timelib_timezone_id_is_valid(const char *timezone, const timelib_tzdb *tzdb)
int timelib_get_time_zone_offset_info(timelib_sll ts, timelib_tzinfo *tz, int32_t *offset, timelib_sll *transition_time, unsigned int *is_dst)
const timelib_tzdb * timelib_builtin_db(void)
#define timelib_conv_int64_signed(value)
ttinfo * timelib_fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time)
#define timelib_conv_int_signed(value)
int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz)
php_json_error_code error_code
timelib_sll transition_time
const timelib_tzdb_index_entry * index
const unsigned char * data
struct _timelib_tzinfo::@164363312306351063307143032200107146325273170202 bit64
struct _timelib_tzinfo::@167337112217316310035373242356361101315007242016 _bit32
timelib_posix_str * posix_info
unsigned char * trans_idx
timelib_time * timelib_time_ctor(void)
int timelib_strcasecmp(const char *s1, const char *s2)
void timelib_time_dtor(timelib_time *t)
timelib_time_offset * timelib_time_offset_ctor(void)
#define TIMELIB_ZONETYPE_ID
void timelib_unixtime2gmt(timelib_time *tm, timelib_sll ts)
#define TIMELIB_ERROR_NO_ERROR
#define TIMELIB_ERROR_CORRUPT_POSIX_STRING
#define TIMELIB_ERROR_EMPTY_POSIX_STRING
#define TIMELIB_ZONETYPE_OFFSET
struct _timelib_tzdb timelib_tzdb
#define TIMELIB_ERROR_CORRUPT_NO_ABBREVIATION
struct _timelib_time timelib_time
#define TIMELIB_ERROR_CORRUPT_NO_64BIT_PREAMBLE
#define TIMELIB_ULONG_FMT
#define TIMELIB_ERROR_NO_SUCH_TIMEZONE
#define TIMELIB_ERROR_UNSUPPORTED_VERSION
#define TIMELIB_ERROR_CORRUPT_TRANSITIONS_DONT_INCREASE
struct _timelib_tzdb_index_entry timelib_tzdb_index_entry
signed long long timelib_sll
struct _timelib_time_offset timelib_time_offset
struct _timelib_tzinfo timelib_tzinfo
#define TIMELIB_ZONETYPE_ABBR
#define TIMELIB_ERROR_CANNOT_ALLOCATE
#define TIMELIB_TIME_FREE(m)
#define TIMELIB_TZINFO_ZONEINFO
#define TIMELIB_TZINFO_PHP
const timelib_tzdb timezonedb_builtin
strcmp(string $string1, string $string2)