- Timestamp:
- 09/26/13 15:41:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb-time.inc.php
r34 r8222 74 74 FUNCTION DESCRIPTIONS 75 75 76 ** FUNCTION adodb_time() 77 78 Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) as an unsigned integer. 76 79 77 80 ** FUNCTION adodb_getdate($date=false) … … 242 245 243 246 CHANGELOG 247 - 16 Jan 2011 0.36 248 Added adodb_time() which returns current time. If > 2038, will return as float 249 250 - 7 Feb 2011 0.35 251 Changed adodb_date to be symmetric with adodb_mktime. See $jan1_71. fix for bc. 252 253 - 13 July 2010 0.34 254 Changed 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 266 Added 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 244 273 - 19 March 2006 0.24 245 274 Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used. … … 369 398 Version Number 370 399 */ 371 define('ADODB_DATE_VERSION',0.24); 400 define('ADODB_DATE_VERSION',0.35); 401 402 $ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2); 372 403 373 404 /* … … 388 419 function adodb_date_test_date($y1,$m,$d=13) 389 420 { 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); 391 423 $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>"; 394 428 return false; 395 429 } … … 404 438 if ($s1 == $s2) return true; 405 439 406 echo "error for $fmt, strftime=$s1, $adodb=$s2<br>";440 echo "error for $fmt, strftime=$s1, adodb=$s2<br>"; 407 441 return false; 408 442 } … … 410 444 /** 411 445 Test Suite 412 */ 446 */ 413 447 function adodb_date_test() 414 448 { 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>"; 415 452 416 453 error_reporting(E_ALL); … … 421 458 // This flag disables calling of PHP native functions, so we can properly test the code 422 459 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>'; 423 469 424 470 adodb_date_test_strftime('%Y %m %x %X'); … … 481 527 // Test string formating 482 528 print "<p>Testing date formating</p>"; 529 483 530 $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'; 484 531 $s1 = date($fmt,0); … … 566 613 } 567 614 615 function adodb_time() 616 { 617 $d = new DateTime(); 618 return $d->format('U'); 619 } 620 568 621 /** 569 622 Returns day of week, 0 = Sunday,... 6=Saturday. … … 658 711 } 659 712 713 function 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 660 727 /** 661 get local time zone offset from GMT 728 get local time zone offset from GMT. Does not handle historical timezones before 1970. 662 729 */ 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); 730 function adodb_get_gmt_diff($y,$m,$d) 731 { 732 static $TZ,$tzo; 733 global $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 } 669 760 return $TZ; 670 761 } … … 713 804 global $_month_table_normal,$_month_table_leaf; 714 805 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; 717 808 718 809 if ($m > 12 || $m < 1) return false; … … 737 828 global $_month_table_normal,$_month_table_leaf; 738 829 739 $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff()); 740 830 $d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff_ts($origd)); 741 831 $_day_power = 86400; 742 832 $_hour_power = 3600; … … 928 1018 ); 929 1019 } 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;*/ 1026 function 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 930 1036 931 1037 function adodb_gmdate($fmt,$d=false) … … 959 1065 { 960 1066 static $daylight; 961 1067 global $ADODB_DATETIME_CLASS; 1068 static $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 962 1076 if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); 963 1077 if (!defined('ADODB_TEST_DATES')) { 964 1078 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 966 1081 return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); 967 1082 … … 972 1087 $arr = _adodb_getdate($d,true,$is_gmt); 973 1088 974 if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv');975 1089 if ($daylight) adodb_daylight_sv($arr, $is_gmt); 976 1090 … … 993 1107 for ($i=0; $i < $max; $i++) { 994 1108 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; 996 1120 // YEAR 997 1121 case 'L': $dates .= $arr['leap'] ? '1' : '0'; break; … … 1009 1133 if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs; 1010 1134 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); 1016 1138 break; 1017 1139 1018 1140 case 'Y': $dates .= $year; break; 1019 1141 case 'y': $dates .= substr($year,strlen($year)-2,2); break; … … 1042 1164 // HOUR 1043 1165 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; 1045 1167 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); 1052 1171 break; 1053 1172 … … 1131 1250 // for windows, we don't check 1970 because with timezone differences, 1132 1251 // 1 Jan 1970 could generate negative timestamp, which is illegal 1133 if (1971< $year && $year < 20381252 $usephpfns = (1970 < $year && $year < 2038 1134 1253 || !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) { 1136 1260 return $is_gmt ? 1137 1261 @gmmktime($hr,$min,$sec,$mon,$day,$year): 1138 1262 @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); 1143 1267 1144 1268 /* … … 1157 1281 1158 1282 if ($mon > 12) { 1159 $y = floor( $mon/ 12);1283 $y = floor(($mon-1)/ 12); 1160 1284 $year += $y; 1161 1285 $mon -= $y*12; … … 1333 1457 return $ret; 1334 1458 } 1335 1336 1337 1459 ?>
Note: See TracChangeset
for help on using the changeset viewer.