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

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:54 +0000 (24 hours ago)

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