Upgraded ADOdb Date to v0.36

Extracted from ADOdb v5.19
Fixes PHP 7 fatal error
This commit is contained in:
Raphaël Doursenaud 2015-11-03 09:29:08 +01:00
parent 7c44198022
commit 442431704b
2 changed files with 43 additions and 11 deletions

View File

@ -12,7 +12,7 @@ Dolibarr uses some external libraries released under different licenses. This is
Component Version License GPL Compatible Usage Component Version License GPL Compatible Usage
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
PHP libraries: PHP libraries:
AdoDb-Date 0.33 Modified BSD License Yes Date convertion (not into rpm package) AdoDb-Date 0.36 Modified BSD License Yes Date convertion (not into rpm package)
ChromePHP 4.1.0 Apache Software License 2.0 Yes Return server log to chrome browser console ChromePHP 4.1.0 Apache Software License 2.0 Yes Return server log to chrome browser console
CKEditor 4.3.3 LGPL-2.1+ Yes Editor WYSIWYG CKEditor 4.3.3 LGPL-2.1+ Yes Editor WYSIWYG
EvalMath 1.0 BSD Yes Safe math expressions evaluation EvalMath 1.0 BSD Yes Safe math expressions evaluation

View File

@ -57,7 +57,7 @@ adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)
COPYRIGHT COPYRIGHT
(c) 2003-2005 John Lim and released under BSD-style license except for code by (c) 2003-2014 John Lim and released under BSD-style license except for code by
jackbbs, which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year jackbbs, which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year
and originally found at http://www.php.net/manual/en/function.mktime.php and originally found at http://www.php.net/manual/en/function.mktime.php
@ -73,6 +73,9 @@ These should be posted to the ADOdb forums at
FUNCTION DESCRIPTIONS FUNCTION DESCRIPTIONS
** FUNCTION adodb_time()
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.
** FUNCTION adodb_getdate($date=false) ** FUNCTION adodb_getdate($date=false)
@ -241,6 +244,14 @@ b. Implement daylight savings, which looks awfully complicated, see
CHANGELOG CHANGELOG
- 16 Jan 2011 0.36
Added adodb_time() which returns current time. If > 2038, will return as float
- 7 Feb 2011 0.35
Changed adodb_date to be symmetric with adodb_mktime. See $jan1_71. fix for bc.
- 13 July 2010 0.34
Changed adodb_get_gm_diff to use DateTimeZone().
- 11 Feb 2008 0.33 - 11 Feb 2008 0.33
* Bug in 0.32 fix for hour handling. Fixed. * Bug in 0.32 fix for hour handling. Fixed.
@ -386,7 +397,7 @@ First implementation.
/* /*
Version Number Version Number
*/ */
define('ADODB_DATE_VERSION',0.33); define('ADODB_DATE_VERSION',0.35);
$ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2); $ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2);
@ -601,6 +612,12 @@ function adodb_date_test()
else print "<p><b>Failed</b> :-(</p>"; else print "<p><b>Failed</b> :-(</p>";
} }
function adodb_time()
{
$d = new DateTime();
return $d->format('U');
}
/** /**
Returns day of week, 0 = Sunday,... 6=Saturday. Returns day of week, 0 = Sunday,... 6=Saturday.
Algorithm from PEAR::Date_Calc Algorithm from PEAR::Date_Calc
@ -729,9 +746,17 @@ global $ADODB_DATETIME_CLASS;
} else { } else {
if (isset($TZ)) return $TZ; if (isset($TZ)) return $TZ;
$y = date('Y'); $y = date('Y');
$TZ = mktime(0,0,0,12,2,$y) - gmmktime(0,0,0,12,2,$y); /*
if (function_exists('date_default_timezone_get') && function_exists('timezone_offset_get')) {
$tzonename = date_default_timezone_get();
if ($tzonename) {
$tobj = new DateTimeZone($tzonename);
$TZ = -timezone_offset_get($tobj,new DateTime("now",$tzo));
}
}
*/
if (empty($TZ)) $TZ = mktime(0,0,0,12,2,$y) - gmmktime(0,0,0,12,2,$y);
} }
return $TZ; return $TZ;
} }
@ -1006,7 +1031,6 @@ function adodb_tz_offset($gmt,$isphp5)
return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60); return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
else else
return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60); return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
break;
} }
@ -1041,11 +1065,19 @@ function adodb_date($fmt,$d=false,$is_gmt=false)
{ {
static $daylight; static $daylight;
global $ADODB_DATETIME_CLASS; global $ADODB_DATETIME_CLASS;
static $jan1_1971;
if (!isset($daylight)) {
$daylight = function_exists('adodb_daylight_sv');
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
}
if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt); if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt);
if (!defined('ADODB_TEST_DATES')) { if (!defined('ADODB_TEST_DATES')) {
if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) // if windows, must be +ve integer
if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= $jan1_1971) // if windows, must be +ve integer
return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d); return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d);
} }
@ -1054,7 +1086,6 @@ global $ADODB_DATETIME_CLASS;
$arr = _adodb_getdate($d,true,$is_gmt); $arr = _adodb_getdate($d,true,$is_gmt);
if (!isset($daylight)) $daylight = function_exists('adodb_daylight_sv');
if ($daylight) adodb_daylight_sv($arr, $is_gmt); if ($daylight) adodb_daylight_sv($arr, $is_gmt);
$year = $arr['year']; $year = $arr['year'];
@ -1075,6 +1106,9 @@ global $ADODB_DATETIME_CLASS;
*/ */
for ($i=0; $i < $max; $i++) { for ($i=0; $i < $max; $i++) {
switch($fmt[$i]) { switch($fmt[$i]) {
case 'e':
$dates .= date('e');
break;
case 'T': case 'T':
if ($ADODB_DATETIME_CLASS) { if ($ADODB_DATETIME_CLASS) {
$dt = new DateTime(); $dt = new DateTime();
@ -1215,7 +1249,7 @@ function adodb_mktime($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_dst=fa
// for windows, we don't check 1970 because with timezone differences, // for windows, we don't check 1970 because with timezone differences,
// 1 Jan 1970 could generate negative timestamp, which is illegal // 1 Jan 1970 could generate negative timestamp, which is illegal
$usephpfns = (1971 < $year && $year < 2038 $usephpfns = (1970 < $year && $year < 2038
|| !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038) || !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038)
); );
@ -1422,5 +1456,3 @@ global $ADODB_DATE_LOCALE;
$ret = adodb_date($fmtdate, $ts, $is_gmt); $ret = adodb_date($fmtdate, $ts, $is_gmt);
return $ret; return $ret;
} }
?>