PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/date/lib - parse_tz.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 197 274 71.9 %
Date: 2015-08-29 Functions: 18 21 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Derick Rethans <derick@derickrethans.nl>                    |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "timelib.h"
      22             : 
      23             : #include <stdio.h>
      24             : 
      25             : #ifdef HAVE_LOCALE_H
      26             : #include <locale.h>
      27             : #endif
      28             : 
      29             : #ifdef HAVE_STRING_H
      30             : #include <string.h>
      31             : #else
      32             : #include <strings.h>
      33             : #endif
      34             : 
      35             : #define TIMELIB_SUPPORTS_V2DATA
      36             : #include "timezonedb.h"
      37             : 
      38             : #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__))
      39             : # if defined(__LITTLE_ENDIAN__)
      40             : #  undef WORDS_BIGENDIAN
      41             : # else
      42             : #  if defined(__BIG_ENDIAN__)
      43             : #   define WORDS_BIGENDIAN
      44             : #  endif
      45             : # endif
      46             : #endif
      47             : 
      48             : #ifdef WORDS_BIGENDIAN
      49             : #define timelib_conv_int(l) (l)
      50             : #else
      51             : #define timelib_conv_int(l) ((l & 0x000000ff) << 24) + ((l & 0x0000ff00) << 8) + ((l & 0x00ff0000) >> 8) + ((l & 0xff000000) >> 24)
      52             : #endif
      53             : 
      54        1757 : static int read_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
      55             : {
      56             :         uint32_t version;
      57             : 
      58             :         /* read ID */
      59        1757 :         version = (*tzf)[3] - '0';
      60        1757 :         *tzf += 4;
      61             : 
      62             :         /* read BC flag */
      63        1757 :         tz->bc = (**tzf == '\1');
      64        1757 :         *tzf += 1;
      65             : 
      66             :         /* read country code */
      67        1757 :         memcpy(tz->location.country_code, *tzf, 2);
      68        1757 :         tz->location.country_code[2] = '\0';
      69        1757 :         *tzf += 2;
      70             : 
      71             :         /* skip rest of preamble */
      72        1757 :         *tzf += 13;
      73             : 
      74        1757 :         return version;
      75             : }
      76             : 
      77        1757 : static void read_header(const unsigned char **tzf, timelib_tzinfo *tz)
      78             : {
      79             :         uint32_t buffer[6];
      80             : 
      81        1757 :         memcpy(&buffer, *tzf, sizeof(buffer));
      82        1757 :         tz->bit32.ttisgmtcnt = timelib_conv_int(buffer[0]);
      83        1757 :         tz->bit32.ttisstdcnt = timelib_conv_int(buffer[1]);
      84        1757 :         tz->bit32.leapcnt    = timelib_conv_int(buffer[2]);
      85        1757 :         tz->bit32.timecnt    = timelib_conv_int(buffer[3]);
      86        1757 :         tz->bit32.typecnt    = timelib_conv_int(buffer[4]);
      87        1757 :         tz->bit32.charcnt    = timelib_conv_int(buffer[5]);
      88        1757 :         *tzf += sizeof(buffer);
      89        1757 : }
      90             : 
      91        1757 : static void skip_64bit_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
      92             : {
      93        1757 :         if (tz->bit64.timecnt) {
      94        1757 :                 *tzf += (sizeof(int64_t) * tz->bit64.timecnt);
      95        1757 :                 *tzf += (sizeof(unsigned char) * tz->bit64.timecnt);
      96             :         }
      97        1757 : }
      98             : 
      99        1757 : static void read_transistions(const unsigned char **tzf, timelib_tzinfo *tz)
     100             : {
     101        1757 :         int32_t *buffer = NULL;
     102             :         uint32_t i;
     103        1757 :         unsigned char *cbuffer = NULL;
     104             : 
     105        1757 :         if (tz->bit32.timecnt) {
     106        1417 :                 buffer = (int32_t*) malloc(tz->bit32.timecnt * sizeof(int32_t));
     107        1417 :                 if (!buffer) {
     108           0 :                         return;
     109             :                 }
     110        1417 :                 memcpy(buffer, *tzf, sizeof(int32_t) * tz->bit32.timecnt);
     111        1417 :                 *tzf += (sizeof(int32_t) * tz->bit32.timecnt);
     112      150637 :                 for (i = 0; i < tz->bit32.timecnt; i++) {
     113      149220 :                         buffer[i] = timelib_conv_int(buffer[i]);
     114             :                 }
     115             : 
     116        1417 :                 cbuffer = (unsigned char*) malloc(tz->bit32.timecnt * sizeof(unsigned char));
     117        1417 :                 if (!cbuffer) {
     118           0 :                         free(buffer);
     119           0 :                         return;
     120             :                 }
     121        1417 :                 memcpy(cbuffer, *tzf, sizeof(unsigned char) * tz->bit32.timecnt);
     122        1417 :                 *tzf += sizeof(unsigned char) * tz->bit32.timecnt;
     123             :         }
     124             : 
     125        1757 :         tz->trans = buffer;
     126        1757 :         tz->trans_idx = cbuffer;
     127             : }
     128             : 
     129        1757 : static void skip_64bit_types(const unsigned char **tzf, timelib_tzinfo *tz)
     130             : {
     131        1757 :         *tzf += sizeof(unsigned char) * 6 * tz->bit64.typecnt;
     132        1757 :         *tzf += sizeof(char) * tz->bit64.charcnt;
     133        1757 :         if (tz->bit64.leapcnt) {
     134           0 :                 *tzf += sizeof(int64_t) * tz->bit64.leapcnt * 2;
     135             :         }
     136        1757 :         if (tz->bit64.ttisstdcnt) {
     137        1757 :                 *tzf += sizeof(unsigned char) * tz->bit64.ttisstdcnt;
     138             :         }
     139        1757 :         if (tz->bit64.ttisgmtcnt) {
     140        1757 :                 *tzf += sizeof(unsigned char) * tz->bit64.ttisgmtcnt;
     141             :         }
     142        1757 : }
     143             : 
     144        1757 : static void read_types(const unsigned char **tzf, timelib_tzinfo *tz)
     145             : {
     146             :         unsigned char *buffer;
     147             :         int32_t *leap_buffer;
     148             :         unsigned int i, j;
     149             : 
     150        1757 :         buffer = (unsigned char*) malloc(tz->bit32.typecnt * sizeof(unsigned char) * 6);
     151        1757 :         if (!buffer) {
     152           0 :                 return;
     153             :         }
     154        1757 :         memcpy(buffer, *tzf, sizeof(unsigned char) * 6 * tz->bit32.typecnt);
     155        1757 :         *tzf += sizeof(unsigned char) * 6 * tz->bit32.typecnt;
     156             : 
     157        1757 :         tz->type = (ttinfo*) malloc(tz->bit32.typecnt * sizeof(struct ttinfo));
     158        1757 :         if (!tz->type) {
     159           0 :                 free(buffer);
     160           0 :                 return;
     161             :         }
     162             : 
     163       11276 :         for (i = 0; i < tz->bit32.typecnt; i++) {
     164        9519 :                 j = i * 6;
     165        9519 :                 tz->type[i].offset = (buffer[j] * 16777216) + (buffer[j + 1] * 65536) + (buffer[j + 2] * 256) + buffer[j + 3];
     166        9519 :                 tz->type[i].isdst = buffer[j + 4];
     167        9519 :                 tz->type[i].abbr_idx = buffer[j + 5];
     168             :         }
     169        1757 :         free(buffer);
     170             : 
     171        1757 :         tz->timezone_abbr = (char*) malloc(tz->bit32.charcnt);
     172        1757 :         if (!tz->timezone_abbr) {
     173           0 :                 return;
     174             :         }
     175        1757 :         memcpy(tz->timezone_abbr, *tzf, sizeof(char) * tz->bit32.charcnt);
     176        1757 :         *tzf += sizeof(char) * tz->bit32.charcnt;
     177             : 
     178        1757 :         if (tz->bit32.leapcnt) {
     179           0 :                 leap_buffer = (int32_t *) malloc(tz->bit32.leapcnt * 2 * sizeof(int32_t));
     180           0 :                 if (!leap_buffer) {
     181           0 :                         return;
     182             :                 }
     183           0 :                 memcpy(leap_buffer, *tzf, sizeof(int32_t) * tz->bit32.leapcnt * 2);
     184           0 :                 *tzf += sizeof(int32_t) * tz->bit32.leapcnt * 2;
     185             : 
     186           0 :                 tz->leap_times = (tlinfo*) malloc(tz->bit32.leapcnt * sizeof(tlinfo));
     187           0 :                 if (!tz->leap_times) {
     188           0 :                         free(leap_buffer);
     189           0 :                         return;
     190             :                 }
     191           0 :                 for (i = 0; i < tz->bit32.leapcnt; i++) {
     192           0 :                         tz->leap_times[i].trans = timelib_conv_int(leap_buffer[i * 2]);
     193           0 :                         tz->leap_times[i].offset = timelib_conv_int(leap_buffer[i * 2 + 1]);
     194             :                 }
     195           0 :                 free(leap_buffer);
     196             :         }
     197             : 
     198        1757 :         if (tz->bit32.ttisstdcnt) {
     199        1757 :                 buffer = (unsigned char*) malloc(tz->bit32.ttisstdcnt * sizeof(unsigned char));
     200        1757 :                 if (!buffer) {
     201           0 :                         return;
     202             :                 }
     203        1757 :                 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisstdcnt);
     204        1757 :                 *tzf += sizeof(unsigned char) * tz->bit32.ttisstdcnt;
     205             : 
     206       11276 :                 for (i = 0; i < tz->bit32.ttisstdcnt; i++) {
     207        9519 :                         tz->type[i].isstdcnt = buffer[i];
     208             :                 }
     209        1757 :                 free(buffer);
     210             :         }
     211             : 
     212        1757 :         if (tz->bit32.ttisgmtcnt) {
     213        1757 :                 buffer = (unsigned char*) malloc(tz->bit32.ttisgmtcnt * sizeof(unsigned char));
     214        1757 :                 if (!buffer) {
     215           0 :                         return;
     216             :                 }
     217        1757 :                 memcpy(buffer, *tzf, sizeof(unsigned char) * tz->bit32.ttisgmtcnt);
     218        1757 :                 *tzf += sizeof(unsigned char) * tz->bit32.ttisgmtcnt;
     219             : 
     220       11276 :                 for (i = 0; i < tz->bit32.ttisgmtcnt; i++) {
     221        9519 :                         tz->type[i].isgmtcnt = buffer[i];
     222             :                 }
     223        1757 :                 free(buffer);
     224             :         }
     225             : }
     226             : 
     227        1757 : static void skip_posix_string(const unsigned char **tzf, timelib_tzinfo *tz)
     228             : {
     229        1757 :         int n_count = 0;
     230             : 
     231             :         do {
     232       27106 :                 if (*tzf[0] == '\n') {
     233        3514 :                         n_count++;
     234             :                 }
     235       27106 :                 (*tzf)++;
     236       27106 :         } while (n_count < 2);
     237        1757 : }
     238             : 
     239        1757 : static void read_location(const unsigned char **tzf, timelib_tzinfo *tz)
     240             : {
     241             :         uint32_t buffer[3];
     242             :         uint32_t comments_len;
     243             : 
     244        1757 :         memcpy(&buffer, *tzf, sizeof(buffer));
     245        1757 :         tz->location.latitude = timelib_conv_int(buffer[0]);
     246        1757 :         tz->location.latitude = (tz->location.latitude / 100000) - 90;
     247        1757 :         tz->location.longitude = timelib_conv_int(buffer[1]);
     248        1757 :         tz->location.longitude = (tz->location.longitude / 100000) - 180;
     249        1757 :         comments_len = timelib_conv_int(buffer[2]);
     250        1757 :         *tzf += sizeof(buffer);
     251             : 
     252        1757 :         tz->location.comments = malloc(comments_len + 1);
     253        1757 :         memcpy(tz->location.comments, *tzf, comments_len);
     254        1757 :         tz->location.comments[comments_len] = '\0';
     255        1757 :         *tzf += comments_len;
     256        1757 : }
     257             : 
     258           0 : void timelib_dump_tzinfo(timelib_tzinfo *tz)
     259             : {
     260             :         uint32_t i;
     261             : 
     262           0 :         printf("Country Code:      %s\n", tz->location.country_code);
     263           0 :         printf("Geo Location:      %f,%f\n", tz->location.latitude, tz->location.longitude);
     264           0 :         printf("Comments:\n%s\n",          tz->location.comments);
     265           0 :         printf("BC:                %s\n",  tz->bc ? "" : "yes");
     266           0 :         printf("UTC/Local count:   %lu\n", (unsigned long) tz->bit32.ttisgmtcnt);
     267           0 :         printf("Std/Wall count:    %lu\n", (unsigned long) tz->bit32.ttisstdcnt);
     268           0 :         printf("Leap.sec. count:   %lu\n", (unsigned long) tz->bit32.leapcnt);
     269           0 :         printf("Trans. count:      %lu\n", (unsigned long) tz->bit32.timecnt);
     270           0 :         printf("Local types count: %lu\n", (unsigned long) tz->bit32.typecnt);
     271           0 :         printf("Zone Abbr. count:  %lu\n", (unsigned long) tz->bit32.charcnt);
     272             : 
     273           0 :         printf ("%8s (%12s) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n",
     274             :                 "", "", 0,
     275           0 :                 (long int) tz->type[0].offset,
     276           0 :                 tz->type[0].isdst,
     277           0 :                 tz->type[0].abbr_idx,
     278           0 :                 &tz->timezone_abbr[tz->type[0].abbr_idx],
     279           0 :                 tz->type[0].isstdcnt,
     280           0 :                 tz->type[0].isgmtcnt
     281             :                 );
     282           0 :         for (i = 0; i < tz->bit32.timecnt; i++) {
     283           0 :                 printf ("%08X (%12d) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n",
     284           0 :                         tz->trans[i], tz->trans[i], tz->trans_idx[i],
     285           0 :                         (long int) tz->type[tz->trans_idx[i]].offset,
     286           0 :                         tz->type[tz->trans_idx[i]].isdst,
     287           0 :                         tz->type[tz->trans_idx[i]].abbr_idx,
     288           0 :                         &tz->timezone_abbr[tz->type[tz->trans_idx[i]].abbr_idx],
     289           0 :                         tz->type[tz->trans_idx[i]].isstdcnt,
     290           0 :                         tz->type[tz->trans_idx[i]].isgmtcnt
     291             :                         );
     292             :         }
     293           0 :         for (i = 0; i < tz->bit32.leapcnt; i++) {
     294           0 :                 printf ("%08X (%12ld) = %d\n",
     295           0 :                         tz->leap_times[i].trans,
     296           0 :                         (long) tz->leap_times[i].trans,
     297           0 :                         tz->leap_times[i].offset);
     298             :         }
     299           0 : }
     300             : 
     301        2683 : static int seek_to_tz_position(const unsigned char **tzf, char *timezone, const timelib_tzdb *tzdb)
     302             : {
     303        2683 :         int left = 0, right = tzdb->index_size - 1;
     304             : #ifdef HAVE_SETLOCALE
     305        2683 :         char *cur_locale = NULL, *tmp;
     306             : 
     307        2683 :         tmp = setlocale(LC_CTYPE, NULL);
     308        2683 :         if (tmp) {
     309        2683 :                 cur_locale = strdup(tmp);
     310             :         }
     311        2683 :         setlocale(LC_CTYPE, "C");
     312             : #endif
     313             : 
     314             :         do {
     315       21893 :                 int mid = ((unsigned)left + right) >> 1;
     316       21893 :                 int cmp = strcasecmp(timezone, tzdb->index[mid].id);
     317             : 
     318       21893 :                 if (cmp < 0) {
     319        8570 :                         right = mid - 1;
     320       13323 :                 } else if (cmp > 0) {
     321       10762 :                         left = mid + 1;
     322             :                 } else { /* (cmp == 0) */
     323        2561 :                         (*tzf) = &(tzdb->data[tzdb->index[mid].pos]);
     324             : #ifdef HAVE_SETLOCALE
     325        2561 :                         setlocale(LC_CTYPE, cur_locale);
     326        2561 :                         if (cur_locale) free(cur_locale);
     327             : #endif
     328        2561 :                         return 1;
     329             :                 }
     330             : 
     331       19332 :         } while (left <= right);
     332             : 
     333             : #ifdef HAVE_SETLOCALE
     334         122 :         setlocale(LC_CTYPE, cur_locale);
     335         122 :         if (cur_locale) free(cur_locale);
     336             : #endif
     337         122 :         return 0;
     338             : }
     339             : 
     340       36621 : const timelib_tzdb *timelib_builtin_db(void)
     341             : {
     342       36621 :         return &timezonedb_builtin;
     343             : }
     344             : 
     345           0 : const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count)
     346             : {
     347           0 :         *count = sizeof(timezonedb_idx_builtin) / sizeof(*timezonedb_idx_builtin);
     348           0 :         return timezonedb_idx_builtin;
     349             : }
     350             : 
     351         831 : int timelib_timezone_id_is_valid(char *timezone, const timelib_tzdb *tzdb)
     352             : {
     353             :         const unsigned char *tzf;
     354         831 :         return (seek_to_tz_position(&tzf, timezone, tzdb));
     355             : }
     356             : 
     357        1757 : static void skip_64bit_preamble(const unsigned char **tzf, timelib_tzinfo *tz)
     358             : {
     359        1757 :         *tzf += 20;
     360        1757 : }
     361             : 
     362        1757 : static void read_64bit_header(const unsigned char **tzf, timelib_tzinfo *tz)
     363             : {
     364             :         uint32_t buffer[6];
     365             : 
     366        1757 :         memcpy(&buffer, *tzf, sizeof(buffer));
     367        1757 :         tz->bit64.ttisgmtcnt = timelib_conv_int(buffer[0]);
     368        1757 :         tz->bit64.ttisstdcnt = timelib_conv_int(buffer[1]);
     369        1757 :         tz->bit64.leapcnt    = timelib_conv_int(buffer[2]);
     370        1757 :         tz->bit64.timecnt    = timelib_conv_int(buffer[3]);
     371        1757 :         tz->bit64.typecnt    = timelib_conv_int(buffer[4]);
     372        1757 :         tz->bit64.charcnt    = timelib_conv_int(buffer[5]);
     373        1757 :         *tzf += sizeof(buffer);
     374        1757 : }
     375             : 
     376        1852 : timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb)
     377             : {
     378             :         const unsigned char *tzf;
     379             :         timelib_tzinfo *tmp;
     380             :         int version;
     381             : 
     382        1852 :         if (seek_to_tz_position(&tzf, timezone, tzdb)) {
     383        1757 :                 tmp = timelib_tzinfo_ctor(timezone);
     384             : 
     385        1757 :                 version = read_preamble(&tzf, tmp);
     386        1757 :                 read_header(&tzf, tmp);
     387        1757 :                 read_transistions(&tzf, tmp);
     388        1757 :                 read_types(&tzf, tmp);
     389        1757 :                 if (version == 2) {
     390        1757 :                         skip_64bit_preamble(&tzf, tmp);
     391        1757 :                         read_64bit_header(&tzf, tmp);
     392        1757 :                         skip_64bit_transistions(&tzf, tmp);
     393        1757 :                         skip_64bit_types(&tzf, tmp);
     394        1757 :                         skip_posix_string(&tzf, tmp);
     395             :                 }
     396        1757 :                 read_location(&tzf, tmp);
     397             :         } else {
     398          95 :                 tmp = NULL;
     399             :         }
     400             : 
     401        1852 :         return tmp;
     402             : }
     403             : 
     404     2322105 : static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib_sll *transition_time)
     405             : {
     406             :         uint32_t i;
     407             : 
     408             :         /* If there is no transition time, we pick the first one, if that doesn't
     409             :          * exist we return NULL */
     410     2322105 :         if (!tz->bit32.timecnt || !tz->trans) {
     411     2284941 :                 *transition_time = 0;
     412     2284941 :                 if (tz->bit32.typecnt == 1) {
     413     2284941 :                         return &(tz->type[0]);
     414             :                 }
     415           0 :                 return NULL;
     416             :         }
     417             : 
     418             :         /* If the TS is lower than the first transition time, then we scan over
     419             :          * all the transition times to find the first non-DST one, or the first
     420             :          * one in case there are only DST entries. Not sure which smartass came up
     421             :          * with this idea in the first though :) */
     422       37164 :         if (ts < tz->trans[0]) {
     423             :                 uint32_t j;
     424             : 
     425         508 :                 *transition_time = 0;
     426         508 :                 j = 0;
     427        1016 :                 while (j < tz->bit32.timecnt && tz->type[j].isdst) {
     428           0 :                         ++j;
     429             :                 }
     430         508 :                 if (j == tz->bit32.timecnt) {
     431           0 :                         j = 0;
     432             :                 }
     433         508 :                 return &(tz->type[j]);
     434             :         }
     435             : 
     436             :         /* In all other cases we loop through the available transtion times to find
     437             :          * the correct entry */
     438     4915244 :         for (i = 0; i < tz->bit32.timecnt; i++) {
     439     4909385 :                 if (ts < tz->trans[i]) {
     440       30797 :                         *transition_time = tz->trans[i - 1];
     441       30797 :                         return &(tz->type[tz->trans_idx[i - 1]]);
     442             :                 }
     443             :         }
     444        5859 :         *transition_time = tz->trans[tz->bit32.timecnt - 1];
     445        5859 :         return &(tz->type[tz->trans_idx[tz->bit32.timecnt - 1]]);
     446             : }
     447             : 
     448     2322105 : static tlinfo* fetch_leaptime_offset(timelib_tzinfo *tz, timelib_sll ts)
     449             : {
     450             :         int i;
     451             : 
     452     2322105 :         if (!tz->bit32.leapcnt || !tz->leap_times) {
     453     2322105 :                 return NULL;
     454             :         }
     455             : 
     456           0 :         for (i = tz->bit32.leapcnt - 1; i > 0; i--) {
     457           0 :                 if (ts > tz->leap_times[i].trans) {
     458           0 :                         return &(tz->leap_times[i]);
     459             :                 }
     460             :         }
     461           0 :         return NULL;
     462             : }
     463             : 
     464           0 : int timelib_timestamp_is_in_dst(timelib_sll ts, timelib_tzinfo *tz)
     465             : {
     466             :         ttinfo *to;
     467             :         timelib_sll dummy;
     468             : 
     469           0 :         if ((to = fetch_timezone_offset(tz, ts, &dummy))) {
     470           0 :                 return to->isdst;
     471             :         }
     472           0 :         return -1;
     473             : }
     474             : 
     475     2322105 : timelib_time_offset *timelib_get_time_zone_info(timelib_sll ts, timelib_tzinfo *tz)
     476             : {
     477             :         ttinfo *to;
     478             :         tlinfo *tl;
     479     2322105 :         int32_t offset = 0, leap_secs = 0;
     480             :         char *abbr;
     481     2322105 :         timelib_time_offset *tmp = timelib_time_offset_ctor();
     482             :         timelib_sll                transistion_time;
     483             : 
     484     2322105 :         if ((to = fetch_timezone_offset(tz, ts, &transistion_time))) {
     485     2322105 :                 offset = to->offset;
     486     2322105 :                 abbr = &(tz->timezone_abbr[to->abbr_idx]);
     487     2322105 :                 tmp->is_dst = to->isdst;
     488     2322105 :                 tmp->transistion_time = transistion_time;
     489             :         } else {
     490           0 :                 offset = 0;
     491           0 :                 abbr = tz->timezone_abbr;
     492           0 :                 tmp->is_dst = 0;
     493           0 :                 tmp->transistion_time = 0;
     494             :         }
     495             : 
     496     2322105 :         if ((tl = fetch_leaptime_offset(tz, ts))) {
     497           0 :                 leap_secs = -tl->offset;
     498             :         }
     499             : 
     500     2322105 :         tmp->offset = offset;
     501     2322105 :         tmp->leap_secs = leap_secs;
     502     2322105 :         tmp->abbr = abbr ? strdup(abbr) : strdup("GMT");
     503             : 
     504     2322105 :         return tmp;
     505             : }
     506             : 
     507          48 : timelib_sll timelib_get_current_offset(timelib_time *t)
     508             : {
     509             :         timelib_time_offset *gmt_offset;
     510             :         timelib_sll retval;
     511             : 
     512          48 :         switch (t->zone_type) {
     513             :                 case TIMELIB_ZONETYPE_ABBR:
     514             :                 case TIMELIB_ZONETYPE_OFFSET:
     515           0 :                         return (t->z + t->dst) * -60;
     516             : 
     517             :                 case TIMELIB_ZONETYPE_ID:
     518          48 :                         gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);
     519          48 :                         retval = gmt_offset->offset;
     520          48 :                         timelib_time_offset_dtor(gmt_offset);
     521          48 :                         return retval;
     522             : 
     523             :                 default:
     524           0 :                         return 0;
     525             :         }
     526             : }

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:13 +0000 (3 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.