Source for file dateTime.php
Documentation is available at dateTime.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
// | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
// +----------------------------------------------------------------------+
// $Id: dateTime.php,v 1.5 2003/01/04 11:56:20 mj Exp $
var $ereg_iso8601 = '(-?[0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]*)?(Z|[+\-][0-9]{4}|[+\-][0-9]{2}:[0-9]{2})?';
#"(-?[0-9]{4})-". // centuries & years CCYY-
#"([0-9]{2})-". // months MM-
#"([0-9]{2})". // days DD
#"([0-9]{2}):". // hours hh:
#"([0-9]{2}):". // minutes mm:
#"([0-9]{2})(\.[0-9]*)?". // seconds ss.ss...
#"(Z|[+\-][0-9]{4}|[+\-][0-9]{2}:[0-9]{2})?"; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
# if no 8th reg (Z) assumes UTC
function SOAP_Type_dateTime ($date = -1 )
if ($date == -1 ) $date = time();
$this->timestamp = $date;
$this->timestamp = $this->toUnixtime ($date);
function toSOAP ($date = NULL )
return $this->toUTC ($date);
function toString ($timestamp = 0 )
if (!$timestamp) $timestamp = $this->timestamp;
if ($timestamp < 0 ) return 0;
return date('Y-m-d\TH:i:sO',$timestamp);
function _split ($datestr)
$datestr = $this->toString ();
else if (gettype($datestr) == 'integer')
$datestr = $this->toString ($datestr);
if (ereg($this->ereg_iso8601,$datestr,$regs)) {
if ($regs[8 ] != '' && $regs[8 ] != 'Z') {
$regs[4 ] = $regs[4 ] - $h;
if ($regs[4 ] < 0 ) $regs[4 ] += 24;
$regs[5 ] = $regs[5 ] - $m;
if ($regs[5 ] < 0 ) $regs[5 ] += 60;
$regs[4 ] = $regs[4 ] + $h;
if ($regs[4 ] > 23 ) $regs[4 ] -= 24;
$regs[5 ] = $regs[5 ] + $m;
if ($regs[5 ] > 59 ) $regs[5 ] -= 60;
function toUTC ($datestr = NULL )
$regs = $this->_split ($datestr);
return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1 ],$regs[2 ],$regs[3 ],$regs[4 ],$regs[5 ],$regs[6 ]);
function toUnixtime ($datestr = NULL )
$regs = $this->_split ($datestr);
return strtotime(" $regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z" );
function compare ($date1, $date2 = NULL )
$date1 = $this->timestamp;
$date1 = $this->toUnixtime ($date1);
$date2 = $this->toUnixtime ($date2);
if ($date1 != -1 && $date2 != -1 ) return $date1 - $date2;
function _test ($orig = '2001-04-25T09:31:41-0700')
$utc = $this->toUTC ($orig);
$ts1 = $this->toUnixtime ($orig);
$ts2 = $this->toUnixtime ($utc);
$b1 = $this->toString ($ts1);
$b2 = $this->toString ($ts2);
print " orig toUTC: $utc\n";
print " orig ts back: $b1\n";
print " utc ts back: $b2\n";
if ($b1 != $orig || $b2 != $orig) {
echo "Error in iso8601 conversions\n";
#$d = new SOAP_Type_dateTime();
#echo $d->compare("2001-04-25T20:31:41Z","2001-04-25T20:31:41Z")."\n";
#echo $d->compare("2001-04-25T20:31:41Z","2001-04-25T12:31:41-0800")."\n";
#echo $d->compare("2001-04-25T20:31:41Z","2001-04-25T12:31:41-08:00")."\n";
Documentation generated on Mon, 11 Mar 2019 13:59:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|