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 - interval.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 0 86 0.0 %
Date: 2014-04-16 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 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             : #include <math.h>
      23             : 
      24           0 : timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
      25             : {
      26             :         timelib_rel_time *rt;
      27             :         timelib_time *swp;
      28           0 :         timelib_sll dst_corr = 0 ,dst_h_corr = 0, dst_m_corr = 0;
      29             :         timelib_time one_backup, two_backup;
      30             : 
      31           0 :         rt = timelib_rel_time_ctor();
      32           0 :         rt->invert = 0;
      33           0 :         if (one->sse > two->sse) {
      34           0 :                 swp = two;
      35           0 :                 two = one;
      36           0 :                 one = swp;
      37           0 :                 rt->invert = 1;
      38             :         }
      39             : 
      40             :         /* Calculate correction for DST change over, but only if the TZ type is ID
      41             :          * and it's the same */
      42           0 :         if (one->zone_type == 3 && two->zone_type == 3
      43           0 :                 && (strcmp(one->tz_info->name, two->tz_info->name) == 0)
      44           0 :                 && (one->z != two->z))
      45             :         {
      46           0 :                 dst_corr = two->z - one->z;
      47           0 :                 dst_h_corr = dst_corr / 3600;
      48           0 :                 dst_m_corr = (dst_corr % 3600) / 60;
      49             :         }
      50             : 
      51             :         /* Save old TZ info */
      52           0 :         memcpy(&one_backup, one, sizeof(one_backup));
      53           0 :         memcpy(&two_backup, two, sizeof(two_backup));
      54             : 
      55           0 :     timelib_apply_localtime(one, 0);
      56           0 :     timelib_apply_localtime(two, 0);
      57             : 
      58           0 :         rt->y = two->y - one->y;
      59           0 :         rt->m = two->m - one->m;
      60           0 :         rt->d = two->d - one->d;
      61           0 :         rt->h = two->h - one->h;
      62           0 :         rt->i = two->i - one->i;
      63           0 :         rt->s = two->s - one->s;
      64           0 :         if (one_backup.dst == 0 && two_backup.dst == 1 && two->sse >= one->sse + 86400 - dst_corr) {
      65           0 :                 rt->h += dst_h_corr;
      66           0 :                 rt->i += dst_m_corr;
      67             :         }
      68             : 
      69           0 :         rt->days = abs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));
      70             : 
      71           0 :         timelib_do_rel_normalize(rt->invert ? one : two, rt);
      72             : 
      73             :         /* We need to do this after normalisation otherwise we can't get "24H" */
      74           0 :         if (one_backup.dst == 1 && two_backup.dst == 0 && two->sse >= one->sse + 86400) {
      75           0 :                 if (two->sse < one->sse + 86400 - dst_corr) {
      76           0 :                         rt->d--;
      77           0 :                         rt->h = 24;
      78             :                 } else {
      79           0 :                         rt->h += dst_h_corr;
      80           0 :                         rt->i += dst_m_corr;
      81             :                 }
      82             :         }
      83             : 
      84             :         /* Restore old TZ info */
      85           0 :         memcpy(one, &one_backup, sizeof(one_backup));
      86           0 :         memcpy(two, &two_backup, sizeof(two_backup));
      87             : 
      88           0 :         return rt;
      89             : }
      90             : 
      91           0 : timelib_time *timelib_add(timelib_time *old_time, timelib_rel_time *interval)
      92             : {
      93           0 :         int bias = 1;
      94           0 :         timelib_time *t = timelib_time_clone(old_time);
      95             : 
      96           0 :         if (interval->have_weekday_relative || interval->have_special_relative) {
      97           0 :                 memcpy(&t->relative, interval, sizeof(struct timelib_rel_time));
      98             :         } else {
      99           0 :                 if (interval->invert) {
     100           0 :                         bias = -1;
     101             :                 }
     102           0 :                 memset(&t->relative, 0, sizeof(struct timelib_rel_time));
     103           0 :                 t->relative.y = interval->y * bias;
     104           0 :                 t->relative.m = interval->m * bias;
     105           0 :                 t->relative.d = interval->d * bias;
     106           0 :                 t->relative.h = interval->h * bias;
     107           0 :                 t->relative.i = interval->i * bias;
     108           0 :                 t->relative.s = interval->s * bias;
     109             :         }
     110           0 :         t->have_relative = 1;
     111           0 :         t->sse_uptodate = 0;
     112             : 
     113           0 :         timelib_update_ts(t, NULL);
     114             : 
     115             : //      printf("%lld %lld %d\n", old_time->dst, t->dst, (t->sse - old_time->sse));
     116             :         /* Adjust for backwards DST changeover */
     117           0 :         if (old_time->dst == 1 && t->dst == 0 && !interval->y && !interval->m && !interval->d) {
     118           0 :                 t->sse -= old_time->z;
     119           0 :                 t->sse += t->z;
     120             :         }
     121             : 
     122           0 :         timelib_update_from_sse(t);
     123           0 :         t->have_relative = 0;
     124             : 
     125           0 :         return t;
     126             : }
     127             : 
     128           0 : timelib_time *timelib_sub(timelib_time *old_time, timelib_rel_time *interval)
     129             : {
     130           0 :         int bias = 1;
     131           0 :         timelib_time *t = timelib_time_clone(old_time);
     132             : 
     133           0 :         if (interval->invert) {
     134           0 :                 bias = -1;
     135             :         }
     136             : 
     137           0 :         memset(&t->relative, 0, sizeof(struct timelib_rel_time));
     138           0 :         t->relative.y = 0 - (interval->y * bias);
     139           0 :         t->relative.m = 0 - (interval->m * bias);
     140           0 :         t->relative.d = 0 - (interval->d * bias);
     141           0 :         t->relative.h = 0 - (interval->h * bias);
     142           0 :         t->relative.i = 0 - (interval->i * bias);
     143           0 :         t->relative.s = 0 - (interval->s * bias);
     144           0 :         t->have_relative = 1;
     145           0 :         t->sse_uptodate = 0;
     146             : 
     147           0 :         timelib_update_ts(t, NULL);
     148             : 
     149             :         /* Adjust for backwards DST changeover */
     150           0 :         if (old_time->dst == 1 && t->dst == 0 && !interval->y && !interval->m && !interval->d) {
     151           0 :                 t->sse -= old_time->z;
     152           0 :                 t->sse += t->z;
     153             :         }
     154             :         /* Adjust for forwards DST changeover */
     155           0 :         if (old_time->dst == 0 && t->dst == 1 && !interval->y && !interval->m && !interval->d ) {
     156           0 :                 t->sse -= old_time->z;
     157           0 :                 t->sse += t->z;
     158             :         }
     159             : 
     160           0 :         timelib_update_from_sse(t);
     161             : 
     162           0 :         t->have_relative = 0;
     163             : 
     164           0 :         return t;
     165             : }

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:46 +0000 (7 days ago)

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