Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb-time.inc.php

    r34 r8222  
    7474FUNCTION DESCRIPTIONS 
    7575 
     76** FUNCTION adodb_time() 
     77 
     78Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) as an unsigned integer. 
    7679 
    7780** FUNCTION adodb_getdate($date=false) 
     
    242245 
    243246CHANGELOG 
     247- 16 Jan 2011 0.36 
     248Added adodb_time() which returns current time. If > 2038, will return as float 
     249 
     250- 7 Feb 2011 0.35 
     251Changed adodb_date to be symmetric with adodb_mktime. See $jan1_71. fix for bc.  
     252 
     253- 13 July 2010 0.34 
     254Changed adodb_get_gm_diff to use DateTimeZone(). 
     255 
     256- 11 Feb 2008 0.33 
     257* Bug in 0.32 fix for hour handling. Fixed. 
     258 
     259- 1 Feb 2008 0.32 
     260* Now adodb_mktime(0,0,0,12+$m,20,2040) works properly.  
     261 
     262- 10 Jan 2008 0.31 
     263* Now adodb_mktime(0,0,0,24,1,2037) works correctly. 
     264 
     265- 15 July 2007 0.30 
     266Added PHP 5.2.0 compatability fixes.  
     267 * gmtime behaviour for 1970 has changed. We use the actual date if it is between 1970 to 2038 to get the 
     268 * timezone, otherwise we use the current year as the baseline to retrieve the timezone. 
     269 * Also the timezone's in php 5.2.* support historical data better, eg. if timezone today was +8, but  
     270   in 1970 it was +7:30, then php 5.2 return +7:30, while this library will use +8. 
     271 *  
     272  
    244273- 19 March 2006 0.24 
    245274Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used. 
     
    369398        Version Number 
    370399*/ 
    371 define('ADODB_DATE_VERSION',0.24); 
     400define('ADODB_DATE_VERSION',0.35); 
     401 
     402$ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2); 
    372403 
    373404/* 
     
    388419function adodb_date_test_date($y1,$m,$d=13) 
    389420{ 
    390         $t = adodb_mktime(0,0,0,$m,$d,$y1); 
     421        $h = round(rand()% 24); 
     422        $t = adodb_mktime($h,0,0,$m,$d,$y1); 
    391423        $rez = adodb_date('Y-n-j H:i:s',$t); 
    392         if ("$y1-$m-$d 00:00:00" != $rez) { 
    393                 print "<b>$y1 error, expected=$y1-$m-$d 00:00:00, adodb=$rez</b><br>"; 
     424        if ($h == 0) $h = '00'; 
     425        else if ($h < 10) $h = '0'.$h; 
     426        if ("$y1-$m-$d $h:00:00" != $rez) { 
     427                print "<b>$y1 error, expected=$y1-$m-$d $h:00:00, adodb=$rez</b><br>"; 
    394428                return false; 
    395429        } 
     
    404438        if ($s1 == $s2) return true; 
    405439         
    406         echo "error for $fmt,  strftime=$s1, $adodb=$s2<br>"; 
     440        echo "error for $fmt,  strftime=$s1, adodb=$s2<br>"; 
    407441        return false; 
    408442} 
     
    410444/** 
    411445         Test Suite 
    412 */ 
     446*/       
    413447function adodb_date_test() 
    414448{ 
     449         
     450        for ($m=-24; $m<=24; $m++) 
     451                echo "$m :",adodb_date('d-m-Y',adodb_mktime(0,0,0,1+$m,20,2040)),"<br>"; 
    415452         
    416453        error_reporting(E_ALL); 
     
    421458        // This flag disables calling of PHP native functions, so we can properly test the code 
    422459        if (!defined('ADODB_TEST_DATES')) define('ADODB_TEST_DATES',1); 
     460         
     461        $t = time(); 
     462         
     463         
     464        $fmt = 'Y-m-d H:i:s'; 
     465        echo '<pre>'; 
     466        echo 'adodb: ',adodb_date($fmt,$t),'<br>'; 
     467        echo 'php  : ',date($fmt,$t),'<br>'; 
     468        echo '</pre>'; 
    423469         
    424470        adodb_date_test_strftime('%Y %m %x %X'); 
     
    481527        // Test string formating 
    482528        print "<p>Testing date formating</p>"; 
     529         
    483530        $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003'; 
    484531        $s1 = date($fmt,0); 
     
    566613} 
    567614 
     615function adodb_time() 
     616{ 
     617        $d = new DateTime(); 
     618        return $d->format('U'); 
     619} 
     620 
    568621/** 
    569622        Returns day of week, 0 = Sunday,... 6=Saturday.  
     
    658711} 
    659712 
     713function adodb_get_gmt_diff_ts($ts)  
     714{ 
     715        if (0 <= $ts && $ts <= 0x7FFFFFFF) { // check if number in 32-bit signed range) { 
     716                $arr = getdate($ts); 
     717                $y = $arr['year']; 
     718                $m = $arr['mon']; 
     719                $d = $arr['mday']; 
     720                return adodb_get_gmt_diff($y,$m,$d);     
     721        } else { 
     722                return adodb_get_gmt_diff(false,false,false); 
     723        } 
     724         
     725} 
     726 
    660727/** 
    661  get local time zone offset from GMT 
     728 get local time zone offset from GMT. Does not handle historical timezones before 1970. 
    662729*/ 
    663 function adodb_get_gmt_diff()  
    664 { 
    665 static $TZ; 
    666         if (isset($TZ)) return $TZ; 
    667          
    668         $TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0); 
     730function adodb_get_gmt_diff($y,$m,$d)  
     731{ 
     732static $TZ,$tzo; 
     733global $ADODB_DATETIME_CLASS; 
     734 
     735        if (!defined('ADODB_TEST_DATES')) $y = false; 
     736        else if ($y < 1970 || $y >= 2038) $y = false; 
     737 
     738        if ($ADODB_DATETIME_CLASS && $y !== false) { 
     739                $dt = new DateTime(); 
     740                $dt->setISODate($y,$m,$d); 
     741                if (empty($tzo)) { 
     742                        $tzo = new DateTimeZone(date_default_timezone_get()); 
     743                #       $tzt = timezone_transitions_get( $tzo ); 
     744                } 
     745                return -$tzo->getOffset($dt); 
     746        } else { 
     747                if (isset($TZ)) return $TZ; 
     748                $y = date('Y'); 
     749                /* 
     750                if (function_exists('date_default_timezone_get') && function_exists('timezone_offset_get')) { 
     751                        $tzonename = date_default_timezone_get(); 
     752                        if ($tzonename) { 
     753                                $tobj = new DateTimeZone($tzonename); 
     754                                $TZ = -timezone_offset_get($tobj,new DateTime("now",$tzo)); 
     755                        } 
     756                }  
     757                */ 
     758                if (empty($TZ)) $TZ = mktime(0,0,0,12,2,$y) - gmmktime(0,0,0,12,2,$y); 
     759        } 
    669760        return $TZ; 
    670761} 
     
    713804global $_month_table_normal,$_month_table_leaf; 
    714805 
    715         if (_adodb_is_leap_year($y)) $marr =& $_month_table_leaf; 
    716         else $marr =& $_month_table_normal; 
     806        if (_adodb_is_leap_year($y)) $marr = $_month_table_leaf; 
     807        else $marr = $_month_table_normal; 
    717808         
    718809        if ($m > 12 || $m < 1) return false; 
     
    737828global $_month_table_normal,$_month_table_leaf; 
    738829 
    739         $d =  $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); 
    740          
     830        $d =  $origd - ($is_gmt ? 0 : adodb_get_gmt_diff_ts($origd)); 
    741831        $_day_power = 86400; 
    742832        $_hour_power = 3600; 
     
    9281018        ); 
    9291019} 
     1020/* 
     1021                if ($isphp5) 
     1022                                $dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);  
     1023                        else 
     1024                                $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);  
     1025                        break;*/ 
     1026function adodb_tz_offset($gmt,$isphp5) 
     1027{ 
     1028        $zhrs = abs($gmt)/3600; 
     1029        $hrs = floor($zhrs); 
     1030        if ($isphp5)  
     1031                return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);  
     1032        else 
     1033                return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);  
     1034} 
     1035 
    9301036 
    9311037function adodb_gmdate($fmt,$d=false) 
     
    9591065{ 
    9601066static $daylight; 
    961  
     1067global $ADODB_DATETIME_CLASS; 
     1068static $jan1_1971; 
     1069 
     1070 
     1071        if (!isset($daylight)) { 
     1072                $daylight = function_exists('adodb_daylight_sv'); 
     1073                if (empty($jan1_1971)) $jan1_1971 = mktime(0,0,0,1,1,1971); // we only use date() when > 1970 as adodb_mktime() only uses mktime() when > 1970 
     1074        } 
     1075         
    9621076        if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); 
    9631077        if (!defined('ADODB_TEST_DATES')) { 
    9641078                if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range 
    965                         if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer 
     1079                 
     1080                        if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= $jan1_1971) // if windows, must be +ve integer 
    9661081                                return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); 
    9671082 
     
    9721087        $arr = _adodb_getdate($d,true,$is_gmt); 
    9731088         
    974         if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv'); 
    9751089        if ($daylight) adodb_daylight_sv($arr, $is_gmt); 
    9761090         
     
    9931107        for ($i=0; $i < $max; $i++) { 
    9941108                switch($fmt[$i]) { 
    995                 case 'T': $dates .= date('T');break; 
     1109                case 'e': 
     1110                        $dates .= date('e'); 
     1111                        break; 
     1112                case 'T':  
     1113                        if ($ADODB_DATETIME_CLASS) { 
     1114                                $dt = new DateTime(); 
     1115                                $dt->SetDate($year,$month,$day); 
     1116                                $dates .= $dt->Format('T'); 
     1117                        } else 
     1118                                $dates .= date('T'); 
     1119                        break; 
    9961120                // YEAR 
    9971121                case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; 
     
    10091133                        if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; 
    10101134                         
    1011                         $gmt = adodb_get_gmt_diff(); 
    1012                         if ($isphp5)  
    1013                                 $dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);  
    1014                         else 
    1015                                 $dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);  
     1135                        $gmt = adodb_get_gmt_diff($year,$month,$day); 
     1136                         
     1137                        $dates .= ' '.adodb_tz_offset($gmt,$isphp5); 
    10161138                        break; 
    1017                                  
     1139                         
    10181140                case 'Y': $dates .= $year; break; 
    10191141                case 'y': $dates .= substr($year,strlen($year)-2,2); break; 
     
    10421164                // HOUR 
    10431165                case 'Z': 
    1044                         $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break; 
     1166                        $dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff($year,$month,$day); break; 
    10451167                case 'O':  
    1046                         $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff(); 
    1047                          
    1048                         if ($isphp5) 
    1049                                 $dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);  
    1050                         else 
    1051                                 $dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);  
     1168                        $gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$month,$day); 
     1169                         
     1170                        $dates .= adodb_tz_offset($gmt,$isphp5); 
    10521171                        break; 
    10531172                         
     
    11311250                // for windows, we don't check 1970 because with timezone differences,  
    11321251                // 1 Jan 1970 could generate negative timestamp, which is illegal 
    1133                 if (1971 < $year && $year < 2038 
     1252                $usephpfns = (1970 < $year && $year < 2038 
    11341253                        || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) 
    1135                         ) { 
     1254                        );  
     1255                         
     1256                 
     1257                if ($usephpfns && ($year + $mon/12+$day/365.25+$hr/(24*365.25) >= 2038)) $usephpfns = false; 
     1258                         
     1259                if ($usephpfns) { 
    11361260                                return $is_gmt ? 
    11371261                                        @gmmktime($hr,$min,$sec,$mon,$day,$year): 
    11381262                                        @mktime($hr,$min,$sec,$mon,$day,$year); 
    1139                         } 
    1140         } 
    1141          
    1142         $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff(); 
     1263                } 
     1264        } 
     1265         
     1266        $gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$mon,$day); 
    11431267 
    11441268        /* 
     
    11571281 
    11581282        if ($mon > 12) { 
    1159                 $y = floor($mon / 12); 
     1283                $y = floor(($mon-1)/ 12); 
    11601284                $year += $y; 
    11611285                $mon -= $y*12; 
     
    13331457        return $ret; 
    13341458} 
    1335  
    1336  
    13371459?> 
Note: See TracChangeset for help on using the changeset viewer.