[PEAR] Modernize Validate code

Upgraded IDNA to IDNA2
Added PEAR Date
> fixed: The each function is deprecated
This commit is contained in:
Diogo Cordeiro 2019-07-07 23:34:41 +01:00
parent a5259073df
commit a38f25f7cd
58 changed files with 61118 additions and 3686 deletions

6672
extlib/Date.php Normal file

File diff suppressed because it is too large Load Diff

4728
extlib/Date/Calc.php Normal file

File diff suppressed because it is too large Load Diff

242
extlib/Date/Human.php Normal file
View File

@ -0,0 +1,242 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// {{{ Header
/**
* Class to convert date strings between Gregorian and Human calendar formats
*
* The Human Calendar format has been proposed by Scott Flansburg and can be
* explained as follows:
* The year is made up of 13 months
* Each month has 28 days
* Counting of months starts from 0 (zero) so the months will run from 0 to 12
* New Years day (00) is a monthless day
* Note: Leap Years are not yet accounted for in the Human Calendar system
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 1997-2006 Allan Kent
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted under the terms of the BSD License.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Date
* @author Allan Kent <allan@lodestone.co.za>
* @copyright 1997-2006 Allan Kent
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/Date
* @since File available since Release 1.3
*/
// }}}
// {{{ Class: Date_Human
/**
* Class to convert date strings between Gregorian and Human calendar formats
*
* The Human Calendar format has been proposed by Scott Flansburg and can be
* explained as follows:
* The year is made up of 13 months
* Each month has 28 days
* Counting of months starts from 0 (zero) so the months will run from 0 to 12
* New Years day (00) is a monthless day
* Note: Leap Years are not yet accounted for in the Human Calendar system
*
* @category Date and Time
* @package Date
* @author Allan Kent <allan@lodestone.co.za>
* @copyright 1997-2005 Allan Kent
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @version Release: 1.5.0a4
* @link http://pear.php.net/package/Date
* @since Class available since Release 1.3
*/
class Date_Human
{
// {{{ gregorianToHuman()
/**
* Returns an associative array containing the converted date information
* in 'Human Calendar' format.
*
* If the day is New Years Day, the function will return
* "hdom" => 0
* "hdow" => 0
* "hwom" => 0
* "hwoy" => 0
* "hmoy" => -1
* Since 0 is a valid month number under the Human Calendar, I have left
* the month as -1 for New Years Day.
*
* @param int $day in DD format, default current local day
* @param int $month in MM format, default current local month
* @param int $year in CCYY format, default to current local year
*
* @return associative array(
* hdom, // Human Day Of Month, starting at 1
* hdow, // Human Day Of Week, starting at 1
* hwom, // Human Week of Month, starting at 1
* hwoy, // Human Week of Year, starting at 1
* hmoy, // Human Month of Year, starting at 0
* )
* @access public
* @static
*/
public function gregorianToHuman($day = 0, $month = 0, $year = 0)
{
/*
* Check to see if any of the arguments are empty
* If they are then populate the $dateinfo array
* Then check to see which arguments are empty and fill
* those with the current date info
*/
if ((empty($day) || (empty($month)) || empty($year))) {
$dateinfo = getdate(time());
}
if (empty($day)) {
$day = $dateinfo["mday"];
}
if (empty($month)) {
$month = $dateinfo["mon"];
}
if (empty($year)) {
$year = $dateinfo["year"];
}
/*
* We need to know how many days into the year we are
*/
$dateinfo = getdate(mktime(0, 0, 0, $month, $day, $year));
$dayofyear = $dateinfo["yday"];
/*
* Human Calendar starts at 0 for months and the first day of the year
* is designated 00, so we need to start our day of the year at 0 for
* these calculations.
* Also, the day of the month is calculated with a modulus of 28.
* Because a day is 28 days, the last day of the month would have a
* remainder of 0 and not 28 as it should be. Decrementing $dayofyear
* gets around this.
*/
$dayofyear--;
/*
* 28 days in a month...
*/
$humanMonthOfYear = floor($dayofyear / 28);
/*
* If we are in the first month then the day of the month is $dayofyear
* else we need to find the modulus of 28.
*/
if ($humanMonthOfYear == 0) {
$humanDayOfMonth = $dayofyear;
} else {
$humanDayOfMonth = ($dayofyear) % 28;
}
/*
* Day of the week is modulus 7
*/
$humanDayOfWeek = $dayofyear % 7;
/*
* We can now increment $dayofyear back to it's correct value for
* the remainder of the calculations
*/
$dayofyear++;
/*
* $humanDayOfMonth needs to be incremented now - recall that we fudged
* it a bit by decrementing $dayofyear earlier
* Same goes for $humanDayOfWeek
*/
$humanDayOfMonth++;
$humanDayOfWeek++;
/*
* Week of the month is day of the month divided by 7, rounded up
* Same for week of the year, but use $dayofyear instead $humanDayOfMonth
*/
$humanWeekOfMonth = ceil($humanDayOfMonth / 7);
$humanWeekOfYear = ceil($dayofyear / 7);
/*
* Return an associative array of the values
*/
return array("hdom" => $humanDayOfMonth,
"hdow" => $humanDayOfWeek,
"hwom" => $humanWeekOfMonth,
"hwoy" => $humanWeekOfYear,
"hmoy" => $humanMonthOfYear);
}
// }}}
// {{{ humanToGregorian()
/**
* Returns unix timestamp for a given Human Calendar date
*
* @param int $day in DD format
* @param int $month in MM format
* @param int $year in CCYY format, default to current local year
*
* @return int unix timestamp of date
* @access public
* @static
*/
public function humanToGregorian($day, $month, $year = 0)
{
/*
* Check to see if the year has been passed through.
* If not get current year
*/
if (empty($year)) {
$dateinfo = getdate(time());
$year = $dateinfo["year"];
}
/*
* We need to get the day of the year that we are currently at so that
* we can work out the Gregorian Month and day
*/
$DayOfYear = $month * 28;
$DayOfYear += $day;
/*
* Human Calendar starts at 0, so we need to increment $DayOfYear
* to take into account the day 00
*/
$DayOfYear++;
/*
* the mktime() function will correctly calculate the date for out of
* range values, so putting $DayOfYear instead of the day of the month
* will work fine.
*/
$GregorianTimeStamp = mktime(0, 0, 0, 1, $DayOfYear, $year);
return $GregorianTimeStamp;
}
// }}}
}
// }}}
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/

1181
extlib/Date/Span.php Normal file

File diff suppressed because it is too large Load Diff

7402
extlib/Date/TimeZone.php Normal file

File diff suppressed because it is too large Load Diff

30
extlib/Date/docs/LICENSE Normal file
View File

@ -0,0 +1,30 @@
Copyright (c) 1997-2006 Baba Buehler, Pierre-Alain Joye
All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The names of Baba Buehler, Pierre-Alain Joye nor the names of
contributors may not be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

12
extlib/Date/docs/TODO Normal file
View File

@ -0,0 +1,12 @@
$Id$
TODO
- Fix once the timezone problem
- Once TZ works nicely, update the testunit_date and use
the real timezone and dct to check the expected time offset
- Clean the test cases and atomic display instead of a global ok or failed
- Write the docs....
- More strict complaint againts ISO 8601
- Complaint againts RFC 822 Date and Time Specification
- Complaint againts ISO 3339

View File

@ -0,0 +1,137 @@
<html>
<head>
<title>Date Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
span.code {
font-family: Monospace;
}
</style>
</head>
<body>
<?php
require_once "Date.php";
function echo_code($ps_date)
{
echo '<span class="code">' . $ps_date . "</span><br />\n";
}
$date = new Date();
?>
<h4>Object is set to currrent time and local time zone by default:</h4>
<?php
echo_code($date->format('%d/%m/%Y %H.%M.%S%O (%Z)'));
echo_code($date->format2('DD/MM/YYYY HH.MI.SSTZO (TZC - TZN)'));
echo_code($date->getDate(DATE_FORMAT_ISO));
?>
<h4>Set date to 1st February, 1991:</h4>
<?php
$date->setDate("1991-02-01 01:02:03");
echo_code($date->format('%d/%m/%Y %H.%M.%S'));
echo_code($date->format2('DD/MM/YYYY HH.MI.SS'));
// Display day, month spelled out:
//
echo_code($date->format('%A, %e %B %Y, %H.%M.%S'));
echo_code($date->format2('NPDay, NPDDth Month YYYY, HH.MI.SS'));
?>
<h4>Time without padding (i.e. leading noughts), and with short year:</h4>
<?php
echo_code($date->format('%e/%m/%y %h.%M.%S'));
echo_code($date->format2('NPDD/NPMM/YY NPHH.MI.SS'));
?>
<h4>Conversion to another time zone:</h4>
<?php
$date->convertTZbyID("Asia/Calcutta");
echo_code($date->format2('"Time zone ID:" TZR'));
echo_code($date->format2('"Time zone name:" TZN'));
echo_code($date->format2('"Time zone code:" TZC'));
echo_code($date->format2('"Time zone offset:" TZO'));
echo "<br />\n";
echo_code($date->format2('DD/MM/YYYY HH.MI.SSTZO (TZC)'));
?>
<h4>Addition/Subtraction:</h4>
<?php
$date->addDays(-1);
echo_code($date->format2('DD/MM/YYYY HH.MI.SS'));
$date->addHours(13);
echo_code($date->format2('DD/MM/YYYY HH.MI.SS'));
?>
<h4>12-hour time:</h4>
<?php
echo_code($date->format('%d/%m/%Y %I.%M.%S %p'));
echo_code($date->format2('DD/MM/YYYY HH12.MI.SS am'));
?>
<h4>Display micro-time:</h4>
<?php
$date->setSecond(3.201282);
echo_code($date->format('%d/%m/%Y %I.%M.%s'));
echo_code($date->format2('DD/MM/YYYY HH12.MI.SS.FFFFFF'));
?>
<h4>Convert to Unix time:</h4>
<?php
echo_code($hn_unixtime = $date->format2('U'));
?>
<h4>Convert Unix time back to Date object:</h4>
<?php
$date2 = new Date($hn_unixtime);
echo_code($date2->format2("DD/MM/YYYY HH.MI.SSTZO"));
?>
<h4>Compare two times for equality:</h4>
<?php
if ($date2->before($date)) {
echo "second date is earlier (because Unix time ignores the part-second)<br />\n";
}
$date->trunc(DATE_PRECISION_SECOND);
if ($date2->equals($date)) {
echo "dates are now the same<br />\n";
}
?>
<br/>
<br/>
<br/>
<br/>
</body>
</html>

View File

@ -0,0 +1,225 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 Leandro Lucarella |
// +----------------------------------------------------------------------+
// | This source file is subject to the New BSD license, That is bundled |
// | with this package in the file LICENSE, and is available through |
// | the world-wide-web at |
// | http://www.opensource.org/licenses/bsd-license.php |
// | If you did not receive a copy of the new BSDlicense and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | pear-dev@lists.php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Leandro Lucarella <llucax@php.net> |
// +----------------------------------------------------------------------+
//
// $Id$
//
require_once 'Date.php';
require_once 'Date/Span.php';
require_once 'PHPUnit/Autoload.php';
/**
* Test case for Date_Span
*
* @package Date
* @author Leandro Lucarella <llucax@php.net>
*/
class Date_SpanTest extends PHPUnit_Framework_TestCase
{
public $time;
public function setUp()
{
$this->time = new Date_Span(97531);
}
public function tearDown()
{
unset($this->time);
}
public function testSetFromArray()
{
$this->time->setFromArray(array(5, 48.5, 28.5, 31));
$this->assertEquals(
'7:0:59:1',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromString()
{
$this->time->setFromString('5:00:59:31');
$this->assertEquals(
'5:0:59:31',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromSeconds()
{
$this->time->setFromSeconds(434344);
$this->assertEquals(
'5:0:39:4',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromMinutes()
{
$this->time->setFromMinutes(7860.0166666666);
$this->assertEquals(
'5:11:0:1',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromHours()
{
$this->time->setFromHours(50.12345);
$this->assertEquals(
'2:2:7:24',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromDays()
{
$this->time->setFromDays(pi());
$this->assertEquals(
'3:3:23:54',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetFromDateDiff()
{
$this->time->setFromDateDiff(
new Date('2004-03-10 01:15:59'),
new Date('2003-03-10 00:10:50')
);
$this->assertEquals(
'366:1:5:9',
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testCopy()
{
$time = new Date_Span();
$time->copy($this->time);
$this->assertEquals(
sprintf(
'%d:%d:%d:%d',
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
),
sprintf(
'%d:%d:%d:%d',
$time->day,
$time->hour,
$time->minute,
$time->second
)
);
}
public function testFormat()
{
$codes = array(
'C' => '1, 03:05:31',
'd' => '1.1288310185185',
'D' => '1',
'e' => '27.091944444444',
'f' => '1625.5166666667',
'g' => '97531',
'h' => '3',
'H' => '03',
'i' => '3',
'I' => '03',
'm' => '5',
'M' => '05',
'n' => "\n",
'p' => 'am',
'P' => 'AM',
'r' => '03:05:31 am',
'R' => '03:05',
's' => '31',
'S' => '31',
't' => "\t",
'T' => '03:05:31',
'%' => '%',
);
foreach ($codes as $code => $expected) {
$this->assertEquals(
"$code: $expected",
$this->time->format("$code: %$code")
);
}
}
public function testAdd()
{
$this->time->add(new Date_Span(6000));
$result = $this->time->toSeconds();
$expected = 103531;
$this->assertEquals($expected, $result);
}
public function testSubtract()
{
$this->time->subtract(new Date_Span(6000));
$result = $this->time->toSeconds();
$expected = 91531;
$this->assertEquals($expected, $result);
}
}

View File

@ -0,0 +1,453 @@
<?php
// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 Marshall Roch |
// +----------------------------------------------------------------------+
// | This source file is subject to the New BSD license, That is bundled |
// | with this package in the file LICENSE, and is available through |
// | the world-wide-web at |
// | http://www.opensource.org/licenses/bsd-license.php |
// | If you did not receive a copy of the new BSDlicense and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | pear-dev@lists.php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Marshall Roch <mroch@php.net> |
// +----------------------------------------------------------------------+
//
// $Id$
//
require_once 'Date.php';
require_once 'PHPUnit/Autoload.php';
class myDate extends Date
{
public function myDate($date)
{
$this->Date($date);
}
}
/**
* Test case for Date
*
* @package Date
* @author Marshall Roch <mroch@php.net>
*/
class Date_Test extends PHPUnit_Framework_TestCase
{
public $time;
public function setUp()
{
$this->time = new Date("2003-10-04 14:03:24Z");
}
public function tearDown()
{
unset($this->time);
}
public function testDateNull()
{
$time = new Date();
$this->assertEquals(
date('Y-m-d H:i:s'),
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$time->year,
$time->month,
$time->day,
$time->hour,
$time->minute,
$time->second
)
);
}
public function testAbstraction()
{
$d = new Date();
$my = new myDate($d);
$this->assertEquals($d->getDate(), $my->getDate());
}
public function testDateCopy()
{
$temp = new Date($this->time);
$this->assertEquals($temp, $this->time);
}
public function testDateISO()
{
$temp = new Date("2003-10-04 14:03:24");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateISOBasic()
{
$temp = new Date("20031004T140324");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateISOExtended()
{
$temp = new Date("2003-10-04T14:03:24");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateISOTimestamp()
{
$temp = new Date("20031004140324");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateUnixtime()
{
$temp = new Date();
$temp->setTZbyID("UTC");
$temp->setDate(strtotime("2003-10-04 14:03:24Z"));
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateUnixtime2()
{
$temp = new Date();
$temp->setTZbyID("UTC-05:30");
$temp->setDate(strtotime("2003-10-04 14:03:24Z"));
$temp->convertTZbyID("UTC");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateUnixtime3()
{
$temp = new Date();
$temp->setTZbyID("America/Chicago");
$temp->setDate(strtotime("2003-10-04 14:03:24Z"));
$temp->convertTZbyID("UTC");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testDateUnixtime4()
{
$temp = new Date();
$temp->setTZbyID("Europe/London");
$temp->setDate(strtotime("2003-10-04 14:03:24Z")); // Summer time in London
$temp->setTZbyID("UTC");
$this->assertEquals(
'2003-10-04 15:03:24', // Preserves London local time (15.03)
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$temp->year,
$temp->month,
$temp->day,
$temp->hour,
$temp->minute,
$temp->second
)
);
}
public function testSetDateISO()
{
$this->time->setDate("2003-10-04 14:03:24");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateISOBasic()
{
$this->time->setDate("20031004T140324");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateISOExtended()
{
$this->time->setDate("2003-10-04T14:03:24");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateTimestamp()
{
$this->time->setDate("20031004140324");
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateUnixtime()
{
$this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateUnixtime2()
{
$hs_oldtz = $this->time->getTZID();
$this->time->setTZbyID("UTC-05:30");
$this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
$this->time->convertTZbyID($hs_oldtz);
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testSetDateUnixtime3()
{
$hs_oldtz = $this->time->getTZID();
$this->time->setTZbyID("America/Chicago");
$this->time->setDate(strtotime("2003-10-04 14:03:24Z"));
$this->time->convertTZbyID($hs_oldtz);
$this->assertEquals(
'2003-10-04 14:03:24',
sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$this->time->year,
$this->time->month,
$this->time->day,
$this->time->hour,
$this->time->minute,
$this->time->second
)
);
}
public function testGetDateISO()
{
$date = $this->time->getDate(DATE_FORMAT_ISO);
$this->assertEquals('2003-10-04 14:03:24', $date);
}
public function testGetDateISOBasic()
{
$date = $this->time->getDate(DATE_FORMAT_ISO_BASIC);
$this->assertEquals('20031004T140324Z', $date);
}
public function testGetDateISOExtended()
{
$date = $this->time->getDate(DATE_FORMAT_ISO_EXTENDED);
$this->assertEquals('2003-10-04T14:03:24Z', $date);
}
public function testGetDateTimestamp()
{
$date = $this->time->getDate(DATE_FORMAT_TIMESTAMP);
$this->assertEquals('20031004140324', $date);
}
public function testGetDateUnixtime()
{
$date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
$this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
}
public function testGetDateUnixtime2()
{
$hs_oldtz = $this->time->getTZID();
$this->time->convertTZbyID("UTC-05:30");
$date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
$this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
$this->time->convertTZbyID($hs_oldtz);
}
public function testGetDateUnixtime3()
{
$hs_oldtz = $this->time->getTZID();
$this->time->convertTZbyID("America/Chicago");
$date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
$this->assertEquals(strtotime('2003-10-04 14:03:24Z'), $date);
$this->time->convertTZbyID($hs_oldtz);
}
public function testFormatLikeStrftime()
{
$codes = array(
'a' => 'Sat',
'A' => 'Saturday',
'b' => 'Oct',
'B' => 'October',
'C' => '20',
'd' => '04',
'D' => '10/04/2003',
'e' => '4',
'H' => '14',
'I' => '02',
'j' => '277',
'm' => '10',
'M' => '03',
'n' => "\n",
'O' => '+00:00',
'o' => '+00:00',
'p' => 'pm',
'P' => 'PM',
'r' => '02:03:24 PM',
'R' => '14:03',
'S' => '24',
't' => "\t",
'T' => '14:03:24',
'w' => '6',
'U' => '39',
'y' => '03',
'Y' => '2003',
'%' => '%'
);
foreach ($codes as $code => $expected) {
$this->assertEquals(
"$code: $expected",
$this->time->formatLikeStrftime("$code: %$code")
);
}
}
public function testToUTCbyOffset()
{
$this->time->setTZbyID('EST');
$this->time->toUTC();
$temp = new Date("2003-10-04 14:03:24");
$temp->toUTCbyOffset("-05:00");
$this->assertEquals($temp, $this->time);
}
}

View File

@ -0,0 +1,65 @@
--TEST--
Bug #11313 DST time change not handled correctly
--FILE--
<?php
date_default_timezone_set('Europe/Moscow');
//include_once('debug.php');
require_once 'Date.php';
$date = new Date('2007-03-25 03:00:04');
$tmp = new Date($date);
$PRINT_FORMAT = "%Y-%m-%d %H:%M:%S %Z%O";
//var_dump($date->tz, 'TimeZone');
printf("% 50s: %s\n", "Actual date", $date->format($PRINT_FORMAT));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:00:05'));
printf(
"% 50s: %s\n",
'Subtracting 5 seconds',
$tmp->format($PRINT_FORMAT)
);
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:20:00'));
printf(
"% 50s: %s\n",
"Subtracting 20 minutes",
$tmp->format($PRINT_FORMAT)
);
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:02:30:00'));
printf(
"% 50s: %s\n",
"Subtracting 2 hours 30 minutes",
$tmp->format($PRINT_FORMAT)
);
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:10:00:00'));
printf(
"% 50s: %s\n",
"Subtracting 10 hours",
$tmp->format($PRINT_FORMAT)
);
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:00:00:00'));
printf(
"% 50s: %s\n",
"Subtracting 3 days",
$tmp->format($PRINT_FORMAT)
);
?>
--EXPECT--
Actual date: 2007-03-25 03:00:04 MSD+04:00
Subtracting 5 seconds: 2007-03-25 01:59:59 MSK+03:00
Subtracting 20 minutes: 2007-03-25 01:40:04 MSK+03:00
Subtracting 2 hours 30 minutes: 2007-03-24 23:30:04 MSK+03:00
Subtracting 10 hours: 2007-03-24 16:00:04 MSK+03:00
Subtracting 3 days: 2007-03-22 02:00:04 MSK+03:00

View File

@ -0,0 +1,32 @@
--TEST--
Bug #13376 setFromDateDiff change the source of Date objects
--FILE--
<?php
/*
* Test for: Date_Span
* Part tested: Date_Span::setFromDateDiff()
*
* This test should be tested on both PHP4 and PHP5 to see the different.
*
* $Id$
*/
require_once 'Date.php';
$startDate = new Date('2008-02-29 00:00:00');
$endDate = new Date('2008-03-01 23:30:10');
print 'Days: ' . $startDate->format('%Y-%m-%d') . ' to ' . $endDate->format('%Y-%m-%d') . "\n";
$diff = new Date_Span();
$diff->setFromDateDiff($startDate, $endDate);
// still same instances?
print 'Days: ' . $startDate->format('%Y-%m-%d') . ' to ' . $endDate->format('%Y-%m-%d') . "\n";
// what about diff?
print 'Diff: ' . $diff->format('%D day %H hours %M minutes %S seconds') . "\n";
?>
--EXPECT--
Days: 2008-02-29 to 2008-03-01
Days: 2008-02-29 to 2008-03-01
Diff: 1 day 23 hours 30 minutes 10 seconds

View File

@ -0,0 +1,13 @@
--TEST--
Bug #13545 Date_Span::set() doesn't work when passed an int and format
--FILE--
<?php
require_once 'Date.php';
$span = new Date_Span(1, '%D');
echo $span->format('%D-%S');
?>
--EXPECT--
1-00

View File

@ -0,0 +1,22 @@
--TEST--
Bug #19568 setDate() handles ISO week dates incorrectly
--FILE--
<?php
require_once 'Date.php';
$x = new Date('2012-W49-1');
print $x->year . "\n";
print $x->month . "\n";
print $x->day . "\n";
$y = new Date('2012-W50-1');
print $y->year . "\n";
print $y->month . "\n";
print $y->day . "\n";
--EXPECT--
2012
12
3
2012
12
10

View File

@ -0,0 +1,17 @@
--TEST--
Bug #2378: Date::getDate(DATE_FORMAT_UNIXTIME) doesn't convert to GMT
--FILE--
<?php
require_once "Date.php";
$date =& new Date(1095935549);
echo $date->getTime()."\n";
$date->convertTZbyID('America/Los_Angeles');
echo $date->getTime()."\n";
?>
--EXPECT--
1095935549
1095935549

View File

@ -0,0 +1,104 @@
--TEST--
Bug #2378: Date::getDate(DATE_FORMAT_UNIXTIME) doesn't convert to GMT
--FILE--
<?php
/**
* Test for: Date
* Parts tested: Date::getTime(), Date::getDate(DATE_FORMAT_UNIXTIME)
*/
require_once 'Date.php';
$dates = array(
'1969-12-31T18:30:00-05:30', // 0
'1970-01-01T07:00:00+07:00', // 0
'1970-01-01T00:00:00Z', // 0
'1998-12-31T23:59:59Z', // 915148799
// '1998-12-31T23:59:60Z', // 915148800
'1999-01-01T00:00:00Z', // 915148800 (no leap second)
'2001-09-09T01:46:40Z', // 1000000000
'2004-01-10T13:37:04Z', // 2^30
'2005-03-18T01:58:31Z', // 1111111111
'2006-12-08T01:00:00Z', // 1165539600
'2009-02-13T23:31:30Z', // 1234567890
'2033-05-18T03:33:20Z', // 2000000000
);
$date = new Date();
foreach ($dates as $hs_date) {
$date->setDate($hs_date);
if (PEAR::isError($res = $date->convertTZbyID('UTC'))) {
print_r($res);
exit();
}
$ts = $date->getTime();
echo 'Greenwich = ' . str_pad($ts, 10) . ' - ' . $date->formatLikeSQL('YYYY-MM-DD HH:MI:SSSTZH:TZM') . "\n";
if (PEAR::isError($res = $date->convertTZbyID('Europe/London'))) {
print_r($res);
exit();
}
$ts = $date->getTime();
echo 'London ' . $date->formatLikeSQL('("UTC"NPSTZH)') . " = " . str_pad($ts, 10) . ' - ' . $date->formatLikeSQL('YYYY-MM-DD HH:MI:SSSTZH:TZM') . "\n";
if (PEAR::isError($res = $date->convertTZbyID('Europe/Paris'))) {
print_r($res);
exit();
}
$ts = $date->getTime();
echo 'Paris ' . $date->formatLikeSQL('("UTC"NPSTZH)') . " = " . str_pad($ts, 10) . ' - ' . $date->formatLikeSQL('YYYY-MM-DD HH:MI:SSSTZH:TZM') . "\n";
if (PEAR::isError($res = $date->convertTZbyID('Asia/Jakarta'))) {
print_r($res);
exit();
}
$ts = $date->getTime();
echo 'Jakarta ' . $date->formatLikeSQL('("UTC"NPSTZH)') . " = " . str_pad($ts, 10) . ' - ' . $date->formatLikeSQL('YYYY-MM-DD HH:MI:SSSTZH:TZM') . "\n";
}
?>
--EXPECT--
Greenwich = 0 - 1970-01-01 00:00:00+00:00
London (UTC+0) = 0 - 1970-01-01 00:00:00+00:00
Paris (UTC+1) = 0 - 1970-01-01 01:00:00+01:00
Jakarta (UTC+7) = 0 - 1970-01-01 07:00:00+07:00
Greenwich = 0 - 1970-01-01 00:00:00+00:00
London (UTC+0) = 0 - 1970-01-01 00:00:00+00:00
Paris (UTC+1) = 0 - 1970-01-01 01:00:00+01:00
Jakarta (UTC+7) = 0 - 1970-01-01 07:00:00+07:00
Greenwich = 0 - 1970-01-01 00:00:00+00:00
London (UTC+0) = 0 - 1970-01-01 00:00:00+00:00
Paris (UTC+1) = 0 - 1970-01-01 01:00:00+01:00
Jakarta (UTC+7) = 0 - 1970-01-01 07:00:00+07:00
Greenwich = 915148799 - 1998-12-31 23:59:59+00:00
London (UTC+0) = 915148799 - 1998-12-31 23:59:59+00:00
Paris (UTC+1) = 915148799 - 1999-01-01 00:59:59+01:00
Jakarta (UTC+7) = 915148799 - 1999-01-01 06:59:59+07:00
Greenwich = 915148800 - 1999-01-01 00:00:00+00:00
London (UTC+0) = 915148800 - 1999-01-01 00:00:00+00:00
Paris (UTC+1) = 915148800 - 1999-01-01 01:00:00+01:00
Jakarta (UTC+7) = 915148800 - 1999-01-01 07:00:00+07:00
Greenwich = 1000000000 - 2001-09-09 01:46:40+00:00
London (UTC+1) = 1000000000 - 2001-09-09 02:46:40+01:00
Paris (UTC+2) = 1000000000 - 2001-09-09 03:46:40+02:00
Jakarta (UTC+7) = 1000000000 - 2001-09-09 08:46:40+07:00
Greenwich = 1073741824 - 2004-01-10 13:37:04+00:00
London (UTC+0) = 1073741824 - 2004-01-10 13:37:04+00:00
Paris (UTC+1) = 1073741824 - 2004-01-10 14:37:04+01:00
Jakarta (UTC+7) = 1073741824 - 2004-01-10 20:37:04+07:00
Greenwich = 1111111111 - 2005-03-18 01:58:31+00:00
London (UTC+0) = 1111111111 - 2005-03-18 01:58:31+00:00
Paris (UTC+1) = 1111111111 - 2005-03-18 02:58:31+01:00
Jakarta (UTC+7) = 1111111111 - 2005-03-18 08:58:31+07:00
Greenwich = 1165539600 - 2006-12-08 01:00:00+00:00
London (UTC+0) = 1165539600 - 2006-12-08 01:00:00+00:00
Paris (UTC+1) = 1165539600 - 2006-12-08 02:00:00+01:00
Jakarta (UTC+7) = 1165539600 - 2006-12-08 08:00:00+07:00
Greenwich = 1234567890 - 2009-02-13 23:31:30+00:00
London (UTC+0) = 1234567890 - 2009-02-13 23:31:30+00:00
Paris (UTC+1) = 1234567890 - 2009-02-14 00:31:30+01:00
Jakarta (UTC+7) = 1234567890 - 2009-02-14 06:31:30+07:00
Greenwich = 2000000000 - 2033-05-18 03:33:20+00:00
London (UTC+1) = 2000000000 - 2033-05-18 04:33:20+01:00
Paris (UTC+2) = 2000000000 - 2033-05-18 05:33:20+02:00
Jakarta (UTC+7) = 2000000000 - 2033-05-18 10:33:20+07:00

View File

@ -0,0 +1,22 @@
--TEST--
Bug #445: Date does not handle DATE_FORMAT_ISO_EXTENDED correctly
--FILE--
<?php
/**
* Test for: Date
* Parts tested: DATE_FORMAT_ISO_EXTENDED constant
*/
require_once 'Date.php';
$input = '2003-12-17T10:27:03Z';
$date = new Date('2003-12-17T10:27:03Z');
echo 'Date::getMonth() (via Constructor) = ' . $date->getMonth() . "\n";
$date = new Date();
$date->setDate($input, DATE_FORMAT_ISO_EXTENDED);
echo 'Date::getMonth() (via Date::setDate()) = ' . $date->getMonth() . "\n";
?>
--EXPECT--
Date::getMonth() (via Constructor) = 12
Date::getMonth() (via Date::setDate()) = 12

View File

@ -0,0 +1,104 @@
--TEST--
Bug #6246: Date::inDaylightTime() crashes Apache 2.0.55 with status 3221225477
--FILE--
<?php
/**
* Test for: Date::inDaylightTime()
* Parts tested: Date_TimeZone::inDaylightTime()
*/
require_once 'Date.php';
/**
* In 2007, daylight saving time (DST) was extended in the United States.
* DST started on March 11, 2007, which was three weeks earlier than in
* the past, and it ended on November 4, 2007, one week later than in years
* past. This results in a new DST period that is four weeks longer than in
* previous years.
*
* N.B. the time at which US Summer time starts is 2.00 'Wall-Clock' Time,
* that is, it goes forward at 2.00 in standard time, and goes back at
* 2.00 in Summer time. This is unlike Europe which all switches together
* at 1.00 GMT in both directions, so that in London, for example, the
* clocks go back at 2.00 BST (although at that exact instant, the time
* actually becomes 1.00 GMT).
*
* All countries in Europe except Iceland observe DST and change on the same
* date and time, starting on the last Sunday in March and ending on the last
* Sunday in October. Before 1996, DST ended on the last Sunday in September
* in most European countries; on the British Isles though, DST then ended on
* the fourth (which some years isn't the last) Sunday in October. In the
* West European (UTC), Central European (CET, UTC+1), and East European
* (UTC+2) time zones the change is simultaneous: on both dates the clocks
* are changed everywhere at 01:00 UTC, i.e. from local times of
* 01:00/02:00/03:00 to 02:00/03:00/04:00 in March, and vice versa in October.
*/
$dates_us = array(
'2007-03-11T01:59:59', // standard time
'2007-03-11T01:59:59.999999', // standard time
'2007-03-11T03:00:00', // Summer time
'2007-11-04T00:59:59', // Summer time
'2007-11-04T01:00:00', // ambiguous - could be either (standard time assumed)
'2007-11-04T01:59:59', // ambiguous - could be either (standard time assumed)
'2007-11-04T02:00:00', // standard time
);
$dates_eu = array(
'2007-03-25T00:59:59', // standard time
'2007-03-25T00:59:59.999999', // standard time
'2007-03-25T02:00:00', // Summer time
'2007-10-28T00:59:59', // Summer time
'2007-10-28T01:00:00', // ambiguous - could be either (standard time assumed)
'2007-10-28T01:59:59', // ambiguous - could be either (standard time assumed)
'2007-11-28T02:00:00', // standard time
);
// Date_TimeZone does not yet have historical data, and so 2006
// is treated as in the 2007 rules, and these dates will not
// behave correctly (historically).
//
//$dates_us = array(
// '2006-04-02T02:00:00', // begin of in daylight saving time.
// '2006-10-29T01:59:59', // end of in daylight saving time.
// '2006-10-30T02:00:00', // not in daylight saving time.
//);
$date = new Date;
$date->setTZ($hs_tz = 'America/Chicago'); // N.B. the old name was 'US/Central' (this still works)
foreach ($dates_us as $d) {
$date->setDate($d);
printf(
'%s is in %s daylight saving time? %s' . "\n",
$date->getDate(),
$hs_tz,
($date->inDaylightTime() ? 'true' : 'false')
);
}
$date = new Date;
$date->setTZ($hs_tz = 'Europe/London'); // N.B. the old name was 'US/Central' (this still works)
foreach ($dates_eu as $d) {
$date->setDate($d);
printf(
'%s is in %s Summer time? %s' . "\n",
$date->getDate(),
$hs_tz,
($date->inDaylightTime() ? 'true' : 'false')
);
}
?>
--EXPECT--
2007-03-11 01:59:59 is in America/Chicago daylight saving time? false
2007-03-11 01:59:59 is in America/Chicago daylight saving time? false
2007-03-11 03:00:00 is in America/Chicago daylight saving time? true
2007-11-04 00:59:59 is in America/Chicago daylight saving time? true
2007-11-04 01:00:00 is in America/Chicago daylight saving time? false
2007-11-04 01:59:59 is in America/Chicago daylight saving time? false
2007-11-04 02:00:00 is in America/Chicago daylight saving time? false
2007-03-25 00:59:59 is in Europe/London Summer time? false
2007-03-25 00:59:59 is in Europe/London Summer time? false
2007-03-25 02:00:00 is in Europe/London Summer time? true
2007-10-28 00:59:59 is in Europe/London Summer time? true
2007-10-28 01:00:00 is in Europe/London Summer time? false
2007-10-28 01:59:59 is in Europe/London Summer time? false
2007-11-28 02:00:00 is in Europe/London Summer time? false

View File

@ -0,0 +1,34 @@
--TEST--
Bug #674: strange (wrong?) result of Date_Calc::endOfWeek
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::endOfWeek(), Date_Calc::beginOfWeek(),
* Date_Calc::beginOfNextWeek() and Date_Calc::beginOfPrevWeek().
*/
require_once 'Date.php';
$dates = array(array(2003,3,17), array(2003,3,20), array(2003,3,23));
foreach ($dates as $date) {
echo 'Parameters: ' . implode('-', array_reverse($date)) . "\n";
$bow = Date_Calc::endOfWeek($date[2], $date[1], $date[0]);
$eow = Date_Calc::beginOfWeek($date[2], $date[1], $date[0]);
$bonw = Date_Calc::beginOfNextWeek($date[2], $date[1], $date[0]);
$bopw = Date_Calc::beginOfPrevWeek($date[2], $date[1], $date[0]);
echo 'Begin of week = ' . $bow . ', End of week = ' . $eow . ', ' .
'Begin of next week = ' . $bonw . ', Begin of previous week = ' . $bopw .
"\n\n";
}
?>
--EXPECT--
Parameters: 17-3-2003
Begin of week = 20030323, End of week = 20030317, Begin of next week = 20030324, Begin of previous week = 20030310
Parameters: 20-3-2003
Begin of week = 20030323, End of week = 20030317, Begin of next week = 20030324, Begin of previous week = 20030310
Parameters: 23-3-2003
Begin of week = 20030323, End of week = 20030317, Begin of next week = 20030324, Begin of previous week = 20030310

View File

@ -0,0 +1,52 @@
--TEST--
Bug #727: Date_Calc::weeksInMonth() wrong result
Tests for weeksInMonth, february with 4 weeks
Monday as 1st day of week
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::weeksInMonth()
*/
/**
* Monday as 1st day of week
*/
define('DATE_CALC_BEGIN_WEEKDAY', 1);
require_once "Date/Calc.php";
$tests = array(
array(1999, 2), array(2010, 2), array(2021, 2), array(2027, 2),
array(1937, 2), array(1943, 2), array(1802, 2), array(1813, 2),
array(1819, 2), array(1830, 2), array(1841, 2), array(1847, 2),
array(1858, 2), array(1869, 2), array(1875, 2), array(1886, 2),
array(1897, 2), array(1909, 2), array(1915, 2), array(1926, 2)
);
foreach ($tests as $date) {
list($year, $month) = $date;
echo $year . '/' . $month . ' = ' . Date_Calc::weeksInMonth($month, $year) . ' weeks' . "\n";
}
?>
--EXPECT--
1999/2 = 4 weeks
2010/2 = 4 weeks
2021/2 = 4 weeks
2027/2 = 4 weeks
1937/2 = 4 weeks
1943/2 = 4 weeks
1802/2 = 4 weeks
1813/2 = 4 weeks
1819/2 = 4 weeks
1830/2 = 4 weeks
1841/2 = 4 weeks
1847/2 = 4 weeks
1858/2 = 4 weeks
1869/2 = 4 weeks
1875/2 = 4 weeks
1886/2 = 4 weeks
1897/2 = 4 weeks
1909/2 = 4 weeks
1915/2 = 4 weeks
1926/2 = 4 weeks

View File

@ -0,0 +1,52 @@
--TEST--
Bug #727: Date_Calc::weeksInMonth() wrong result
Tests for weeksInMonth, february with 4 weeks
Sunday as 1st day of week
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::weeksInMonth()
*/
/**
* Sunday as 1st day of week
*/
define('DATE_CALC_BEGIN_WEEKDAY', 0);
require_once "Date/Calc.php";
$tests = array(
array(2009, 2), array(2015, 2), array(2026, 2), array(2037, 2),
array(1931, 2), array(1942, 2), array(1801, 2), array(1807, 2),
array(1818, 2), array(1829, 2), array(1835, 2), array(1846, 2),
array(1857, 2), array(1863, 2), array(1874, 2), array(1885, 2),
array(1891, 2), array(1903, 2), array(1914, 2), array(1925, 2)
);
foreach ($tests as $date) {
list($year, $month) = $date;
echo $year . '/' . $month . ' = ' . Date_Calc::weeksInMonth($month, $year) . ' weeks' . "\n";
}
?>
--EXPECT--
2009/2 = 4 weeks
2015/2 = 4 weeks
2026/2 = 4 weeks
2037/2 = 4 weeks
1931/2 = 4 weeks
1942/2 = 4 weeks
1801/2 = 4 weeks
1807/2 = 4 weeks
1818/2 = 4 weeks
1829/2 = 4 weeks
1835/2 = 4 weeks
1846/2 = 4 weeks
1857/2 = 4 weeks
1863/2 = 4 weeks
1874/2 = 4 weeks
1885/2 = 4 weeks
1891/2 = 4 weeks
1903/2 = 4 weeks
1914/2 = 4 weeks
1925/2 = 4 weeks

View File

@ -0,0 +1,500 @@
--TEST--
Bug #727: Date_Calc::weeksInMonth() wrong result
Tests for weeksInMonth "random"
Sunday as 1st day of week
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::weeksInMonth()
*/
/**
* Sunday as 1st day of week
*/
define('DATE_CALC_BEGIN_WEEKDAY', 0);
require_once "Date/Calc.php";
$tests = array(
array(1999, 12), array(2000, 11), array(2001, 11), array(2002, 12),
array(2003, 12), array(2004, 12), array(2005, 12), array(2006, 11),
array(2007, 11), array(2008, 12), array(2009, 12), array(2010, 12),
array(2011, 12), array(2012, 11), array(2013, 12), array(2014, 12),
array(2015, 12), array(2016, 12), array(2017, 11), array(2018, 11),
array(2019, 12), array(2020, 12), array(2021, 12), array(2022, 12),
array(2023, 11), array(2024, 12), array(2025, 12), array(2026, 12),
array(2027, 12), array(2028, 11), array(2029, 11), array(2030, 12),
array(2031, 12), array(2032, 12), array(2033, 12), array(2034, 11),
array(2035, 11), array(2036, 12), array(2037, 12), array(1930, 12),
array(1931, 12), array(1932, 12), array(1933, 11), array(1934, 11),
array(1935, 12), array(1936, 12), array(1937, 12), array(1938, 12),
array(1939, 11), array(1940, 12), array(1941, 12), array(1942, 12),
array(1943, 12), array(1944, 11), array(1945, 11), array(1946, 12),
array(1947, 12), array(1948, 12), array(1949, 12), array(1800, 12),
array(1801, 12), array(1802, 12), array(1803, 12), array(1804, 11),
array(1805, 12), array(1806, 12), array(1807, 12), array(1808, 12),
array(1809, 11), array(1810, 11), array(1811, 12), array(1812, 12),
array(1813, 12), array(1814, 12), array(1815, 11), array(1816, 12),
array(1817, 12), array(1818, 12), array(1819, 12), array(1820, 11),
array(1821, 11), array(1822, 12), array(1823, 12), array(1824, 12),
array(1825, 12), array(1826, 11), array(1827, 11), array(1828, 12),
array(1829, 12), array(1830, 12), array(1831, 12), array(1832, 11),
array(1833, 12), array(1834, 12), array(1835, 12), array(1836, 12),
array(1837, 11), array(1838, 11), array(1839, 12), array(1840, 12),
array(1841, 12), array(1842, 12), array(1843, 11), array(1844, 12),
array(1845, 12), array(1846, 12), array(1847, 12), array(1848, 11),
array(1849, 11), array(1850, 12), array(1851, 12), array(1852, 12),
array(1853, 12), array(1854, 11), array(1855, 11), array(1856, 12),
array(1857, 12), array(1858, 12), array(1859, 12), array(1860, 11),
array(1861, 12), array(1862, 12), array(1863, 12), array(1864, 12),
array(1865, 11), array(1866, 11), array(1867, 12), array(1868, 12),
array(1869, 12), array(1870, 12), array(1871, 11), array(1872, 12),
array(1873, 12), array(1874, 12), array(1875, 12), array(1876, 11),
array(1877, 11), array(1878, 12), array(1879, 12), array(1880, 12),
array(1881, 12), array(1882, 11), array(1883, 11), array(1884, 12),
array(1885, 12), array(1886, 12), array(1887, 12), array(1888, 11),
array(1889, 12), array(1890, 12), array(1891, 12), array(1892, 12),
array(1893, 11), array(1894, 11), array(1895, 12), array(1896, 12),
array(1897, 12), array(1898, 12), array(1899, 11), array(1900, 11),
array(1901, 12), array(1902, 12), array(1903, 12), array(1904, 12),
array(1905, 11), array(1906, 11), array(1907, 12), array(1908, 12),
array(1909, 12), array(1910, 12), array(1911, 11), array(1912, 12),
array(1913, 12), array(1914, 12), array(1915, 12), array(1916, 11),
array(1917, 11), array(1918, 12), array(1919, 12), array(1920, 12),
array(1921, 12), array(1922, 11), array(1923, 11), array(1924, 12),
array(1925, 12), array(1926, 12), array(1927, 12), array(1928, 11),
array(1929, 12), array(1999, 10), array(2000, 12), array(2001, 12),
array(2002, 6), array(2003, 11), array(2004, 10), array(2005, 10),
array(2006, 12), array(2007, 12), array(2008, 11), array(2009, 8),
array(2010, 10), array(2011, 10), array(2012, 12), array(2013, 6),
array(2014, 11), array(2015, 8), array(2016, 10), array(2017, 12),
array(2018, 12), array(2019, 6), array(2020, 8), array(2021, 10),
array(2022, 10), array(2023, 12), array(2024, 6), array(2025, 11),
array(2026, 8), array(2027, 10), array(2028, 12), array(2029, 12),
array(2030, 6), array(2031, 11), array(2032, 10), array(2033, 10),
array(2034, 12), array(2035, 12), array(2036, 11), array(2037, 8),
array(1930, 11), array(1931, 8), array(1932, 10), array(1933, 12),
array(1934, 12), array(1935, 6), array(1936, 8), array(1937, 10),
array(1938, 10), array(1939, 12), array(1940, 6), array(1941, 11),
array(1942, 8), array(1943, 10), array(1944, 12), array(1945, 12),
array(1946, 6), array(1947, 11), array(1948, 10), array(1949, 10),
array(1800, 11), array(1801, 8), array(1802, 10), array(1803, 10),
array(1804, 12), array(1805, 6), array(1806, 11), array(1807, 8),
array(1808, 10), array(1809, 12), array(1810, 12), array(1811, 6),
array(1812, 8), array(1813, 10), array(1814, 10), array(1815, 12),
array(1816, 6), array(1817, 11), array(1818, 8), array(1819, 10),
array(1820, 12), array(1821, 12), array(1822, 6), array(1823, 11),
array(1824, 10), array(1825, 10), array(1826, 12), array(1827, 12),
array(1828, 11), array(1829, 8), array(1830, 10), array(1831, 10),
array(1832, 12), array(1833, 6), array(1834, 11), array(1835, 8),
array(1836, 10), array(1837, 12), array(1838, 12), array(1839, 6),
array(1840, 8), array(1841, 10), array(1842, 10), array(1843, 12),
array(1844, 6), array(1845, 11), array(1846, 8), array(1847, 10),
array(1848, 12), array(1849, 12), array(1850, 6), array(1851, 11),
array(1852, 10), array(1853, 10), array(1854, 12), array(1855, 12),
array(1856, 11), array(1857, 8), array(1858, 10), array(1859, 10),
array(1860, 12), array(1861, 6), array(1862, 11), array(1863, 8),
array(1864, 10), array(1865, 12), array(1866, 12), array(1867, 6),
array(1868, 8), array(1869, 10), array(1870, 10), array(1871, 12),
array(1872, 6), array(1873, 11), array(1874, 8), array(1875, 10),
array(1876, 12), array(1877, 12), array(1878, 6), array(1879, 11),
array(1880, 10), array(1881, 10), array(1882, 12), array(1883, 12),
array(1884, 11), array(1885, 8), array(1886, 10), array(1887, 10),
array(1888, 12), array(1889, 6), array(1890, 11), array(1891, 8),
array(1892, 10), array(1893, 12), array(1894, 12), array(1895, 6),
array(1896, 8), array(1897, 10), array(1898, 10), array(1899, 12),
array(1900, 12), array(1901, 6), array(1902, 11), array(1903, 8),
array(1904, 10), array(1905, 12), array(1906, 12), array(1907, 6),
array(1908, 8), array(1909, 10), array(1910, 10), array(1911, 12),
array(1912, 6), array(1913, 11), array(1914, 8), array(1915, 10),
array(1916, 12), array(1917, 12), array(1918, 6), array(1919, 11),
array(1920, 10), array(1921, 10), array(1922, 12), array(1923, 12),
array(1924, 11), array(1925, 8), array(1926, 10), array(1927, 10),
array(1928, 12), array(1929, 6)
);
foreach ($tests as $date) {
list($year, $month) = $date;
echo $year . '/' . $month . ' = ' . Date_Calc::weeksInMonth($month, $year) . ' weeks' . "\n";
}
?>
--EXPECT--
1999/12 = 5 weeks
2000/11 = 5 weeks
2001/11 = 5 weeks
2002/12 = 5 weeks
2003/12 = 5 weeks
2004/12 = 5 weeks
2005/12 = 5 weeks
2006/11 = 5 weeks
2007/11 = 5 weeks
2008/12 = 5 weeks
2009/12 = 5 weeks
2010/12 = 5 weeks
2011/12 = 5 weeks
2012/11 = 5 weeks
2013/12 = 5 weeks
2014/12 = 5 weeks
2015/12 = 5 weeks
2016/12 = 5 weeks
2017/11 = 5 weeks
2018/11 = 5 weeks
2019/12 = 5 weeks
2020/12 = 5 weeks
2021/12 = 5 weeks
2022/12 = 5 weeks
2023/11 = 5 weeks
2024/12 = 5 weeks
2025/12 = 5 weeks
2026/12 = 5 weeks
2027/12 = 5 weeks
2028/11 = 5 weeks
2029/11 = 5 weeks
2030/12 = 5 weeks
2031/12 = 5 weeks
2032/12 = 5 weeks
2033/12 = 5 weeks
2034/11 = 5 weeks
2035/11 = 5 weeks
2036/12 = 5 weeks
2037/12 = 5 weeks
1930/12 = 5 weeks
1931/12 = 5 weeks
1932/12 = 5 weeks
1933/11 = 5 weeks
1934/11 = 5 weeks
1935/12 = 5 weeks
1936/12 = 5 weeks
1937/12 = 5 weeks
1938/12 = 5 weeks
1939/11 = 5 weeks
1940/12 = 5 weeks
1941/12 = 5 weeks
1942/12 = 5 weeks
1943/12 = 5 weeks
1944/11 = 5 weeks
1945/11 = 5 weeks
1946/12 = 5 weeks
1947/12 = 5 weeks
1948/12 = 5 weeks
1949/12 = 5 weeks
1800/12 = 5 weeks
1801/12 = 5 weeks
1802/12 = 5 weeks
1803/12 = 5 weeks
1804/11 = 5 weeks
1805/12 = 5 weeks
1806/12 = 5 weeks
1807/12 = 5 weeks
1808/12 = 5 weeks
1809/11 = 5 weeks
1810/11 = 5 weeks
1811/12 = 5 weeks
1812/12 = 5 weeks
1813/12 = 5 weeks
1814/12 = 5 weeks
1815/11 = 5 weeks
1816/12 = 5 weeks
1817/12 = 5 weeks
1818/12 = 5 weeks
1819/12 = 5 weeks
1820/11 = 5 weeks
1821/11 = 5 weeks
1822/12 = 5 weeks
1823/12 = 5 weeks
1824/12 = 5 weeks
1825/12 = 5 weeks
1826/11 = 5 weeks
1827/11 = 5 weeks
1828/12 = 5 weeks
1829/12 = 5 weeks
1830/12 = 5 weeks
1831/12 = 5 weeks
1832/11 = 5 weeks
1833/12 = 5 weeks
1834/12 = 5 weeks
1835/12 = 5 weeks
1836/12 = 5 weeks
1837/11 = 5 weeks
1838/11 = 5 weeks
1839/12 = 5 weeks
1840/12 = 5 weeks
1841/12 = 5 weeks
1842/12 = 5 weeks
1843/11 = 5 weeks
1844/12 = 5 weeks
1845/12 = 5 weeks
1846/12 = 5 weeks
1847/12 = 5 weeks
1848/11 = 5 weeks
1849/11 = 5 weeks
1850/12 = 5 weeks
1851/12 = 5 weeks
1852/12 = 5 weeks
1853/12 = 5 weeks
1854/11 = 5 weeks
1855/11 = 5 weeks
1856/12 = 5 weeks
1857/12 = 5 weeks
1858/12 = 5 weeks
1859/12 = 5 weeks
1860/11 = 5 weeks
1861/12 = 5 weeks
1862/12 = 5 weeks
1863/12 = 5 weeks
1864/12 = 5 weeks
1865/11 = 5 weeks
1866/11 = 5 weeks
1867/12 = 5 weeks
1868/12 = 5 weeks
1869/12 = 5 weeks
1870/12 = 5 weeks
1871/11 = 5 weeks
1872/12 = 5 weeks
1873/12 = 5 weeks
1874/12 = 5 weeks
1875/12 = 5 weeks
1876/11 = 5 weeks
1877/11 = 5 weeks
1878/12 = 5 weeks
1879/12 = 5 weeks
1880/12 = 5 weeks
1881/12 = 5 weeks
1882/11 = 5 weeks
1883/11 = 5 weeks
1884/12 = 5 weeks
1885/12 = 5 weeks
1886/12 = 5 weeks
1887/12 = 5 weeks
1888/11 = 5 weeks
1889/12 = 5 weeks
1890/12 = 5 weeks
1891/12 = 5 weeks
1892/12 = 5 weeks
1893/11 = 5 weeks
1894/11 = 5 weeks
1895/12 = 5 weeks
1896/12 = 5 weeks
1897/12 = 5 weeks
1898/12 = 5 weeks
1899/11 = 5 weeks
1900/11 = 5 weeks
1901/12 = 5 weeks
1902/12 = 5 weeks
1903/12 = 5 weeks
1904/12 = 5 weeks
1905/11 = 5 weeks
1906/11 = 5 weeks
1907/12 = 5 weeks
1908/12 = 5 weeks
1909/12 = 5 weeks
1910/12 = 5 weeks
1911/11 = 5 weeks
1912/12 = 5 weeks
1913/12 = 5 weeks
1914/12 = 5 weeks
1915/12 = 5 weeks
1916/11 = 5 weeks
1917/11 = 5 weeks
1918/12 = 5 weeks
1919/12 = 5 weeks
1920/12 = 5 weeks
1921/12 = 5 weeks
1922/11 = 5 weeks
1923/11 = 5 weeks
1924/12 = 5 weeks
1925/12 = 5 weeks
1926/12 = 5 weeks
1927/12 = 5 weeks
1928/11 = 5 weeks
1929/12 = 5 weeks
1999/10 = 6 weeks
2000/12 = 6 weeks
2001/12 = 6 weeks
2002/6 = 6 weeks
2003/11 = 6 weeks
2004/10 = 6 weeks
2005/10 = 6 weeks
2006/12 = 6 weeks
2007/12 = 6 weeks
2008/11 = 6 weeks
2009/8 = 6 weeks
2010/10 = 6 weeks
2011/10 = 6 weeks
2012/12 = 6 weeks
2013/6 = 6 weeks
2014/11 = 6 weeks
2015/8 = 6 weeks
2016/10 = 6 weeks
2017/12 = 6 weeks
2018/12 = 6 weeks
2019/6 = 6 weeks
2020/8 = 6 weeks
2021/10 = 6 weeks
2022/10 = 6 weeks
2023/12 = 6 weeks
2024/6 = 6 weeks
2025/11 = 6 weeks
2026/8 = 6 weeks
2027/10 = 6 weeks
2028/12 = 6 weeks
2029/12 = 6 weeks
2030/6 = 6 weeks
2031/11 = 6 weeks
2032/10 = 6 weeks
2033/10 = 6 weeks
2034/12 = 6 weeks
2035/12 = 6 weeks
2036/11 = 6 weeks
2037/8 = 6 weeks
1930/11 = 6 weeks
1931/8 = 6 weeks
1932/10 = 6 weeks
1933/12 = 6 weeks
1934/12 = 6 weeks
1935/6 = 6 weeks
1936/8 = 6 weeks
1937/10 = 6 weeks
1938/10 = 6 weeks
1939/12 = 6 weeks
1940/6 = 6 weeks
1941/11 = 6 weeks
1942/8 = 6 weeks
1943/10 = 6 weeks
1944/12 = 6 weeks
1945/12 = 6 weeks
1946/6 = 6 weeks
1947/11 = 6 weeks
1948/10 = 6 weeks
1949/10 = 6 weeks
1800/11 = 6 weeks
1801/8 = 6 weeks
1802/10 = 6 weeks
1803/10 = 6 weeks
1804/12 = 6 weeks
1805/6 = 6 weeks
1806/11 = 6 weeks
1807/8 = 6 weeks
1808/10 = 6 weeks
1809/12 = 6 weeks
1810/12 = 6 weeks
1811/6 = 6 weeks
1812/8 = 6 weeks
1813/10 = 6 weeks
1814/10 = 6 weeks
1815/12 = 6 weeks
1816/6 = 6 weeks
1817/11 = 6 weeks
1818/8 = 6 weeks
1819/10 = 6 weeks
1820/12 = 6 weeks
1821/12 = 6 weeks
1822/6 = 6 weeks
1823/11 = 6 weeks
1824/10 = 6 weeks
1825/10 = 6 weeks
1826/12 = 6 weeks
1827/12 = 6 weeks
1828/11 = 6 weeks
1829/8 = 6 weeks
1830/10 = 6 weeks
1831/10 = 6 weeks
1832/12 = 6 weeks
1833/6 = 6 weeks
1834/11 = 6 weeks
1835/8 = 6 weeks
1836/10 = 6 weeks
1837/12 = 6 weeks
1838/12 = 6 weeks
1839/6 = 6 weeks
1840/8 = 6 weeks
1841/10 = 6 weeks
1842/10 = 6 weeks
1843/12 = 6 weeks
1844/6 = 6 weeks
1845/11 = 6 weeks
1846/8 = 6 weeks
1847/10 = 6 weeks
1848/12 = 6 weeks
1849/12 = 6 weeks
1850/6 = 6 weeks
1851/11 = 6 weeks
1852/10 = 6 weeks
1853/10 = 6 weeks
1854/12 = 6 weeks
1855/12 = 6 weeks
1856/11 = 6 weeks
1857/8 = 6 weeks
1858/10 = 6 weeks
1859/10 = 6 weeks
1860/12 = 6 weeks
1861/6 = 6 weeks
1862/11 = 6 weeks
1863/8 = 6 weeks
1864/10 = 6 weeks
1865/12 = 6 weeks
1866/12 = 6 weeks
1867/6 = 6 weeks
1868/8 = 6 weeks
1869/10 = 6 weeks
1870/10 = 6 weeks
1871/12 = 6 weeks
1872/6 = 6 weeks
1873/11 = 6 weeks
1874/8 = 6 weeks
1875/10 = 6 weeks
1876/12 = 6 weeks
1877/12 = 6 weeks
1878/6 = 6 weeks
1879/11 = 6 weeks
1880/10 = 6 weeks
1881/10 = 6 weeks
1882/12 = 6 weeks
1883/12 = 6 weeks
1884/11 = 6 weeks
1885/8 = 6 weeks
1886/10 = 6 weeks
1887/10 = 6 weeks
1888/12 = 6 weeks
1889/6 = 6 weeks
1890/11 = 6 weeks
1891/8 = 6 weeks
1892/10 = 6 weeks
1893/12 = 6 weeks
1894/12 = 6 weeks
1895/6 = 6 weeks
1896/8 = 6 weeks
1897/10 = 6 weeks
1898/10 = 6 weeks
1899/12 = 6 weeks
1900/12 = 6 weeks
1901/6 = 6 weeks
1902/11 = 6 weeks
1903/8 = 6 weeks
1904/10 = 6 weeks
1905/12 = 6 weeks
1906/12 = 6 weeks
1907/6 = 6 weeks
1908/8 = 6 weeks
1909/10 = 6 weeks
1910/10 = 6 weeks
1911/12 = 6 weeks
1912/6 = 6 weeks
1913/11 = 6 weeks
1914/8 = 6 weeks
1915/10 = 6 weeks
1916/12 = 6 weeks
1917/12 = 6 weeks
1918/6 = 6 weeks
1919/11 = 6 weeks
1920/10 = 6 weeks
1921/10 = 6 weeks
1922/12 = 6 weeks
1923/12 = 6 weeks
1924/11 = 6 weeks
1925/8 = 6 weeks
1926/10 = 6 weeks
1927/10 = 6 weeks
1928/12 = 6 weeks
1929/6 = 6 weeks

View File

@ -0,0 +1,500 @@
--TEST--
Bug #727: Date_Calc::weeksInMonth() wrong result
Tests for weeksInMonth "random"
Monday as 1st day of week
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::weeksInMonth()
*/
/**
* Monday as 1st day of week
*/
define('DATE_CALC_BEGIN_WEEKDAY', 1);
require_once "Date/Calc.php";
$tests = array(
array(1999, 8), array(2000, 10), array(2001, 12), array(2002, 12),
array(2003, 6), array(2004, 8), array(2005, 10), array(2006, 10),
array(2007, 12), array(2008, 6), array(2009, 11), array(2010, 8),
array(2011, 10), array(2012, 12), array(2013, 12), array(2014, 6),
array(2015, 11), array(2016, 10), array(2017, 10), array(2018, 12),
array(2019, 12), array(2020, 11), array(2021, 8), array(2022, 10),
array(2023, 10), array(2024, 12), array(2025, 6), array(2026, 11),
array(2027, 8), array(2028, 10), array(2029, 12), array(2030, 12),
array(2031, 6), array(2032, 8), array(2033, 10), array(2034, 10),
array(2035, 12), array(2036, 6), array(2037, 11), array(1930, 6),
array(1931, 11), array(1932, 10), array(1933, 10), array(1934, 12),
array(1935, 12), array(1936, 11), array(1937, 8), array(1938, 10),
array(1939, 10), array(1940, 12), array(1941, 6), array(1942, 11),
array(1943, 8), array(1944, 10), array(1945, 12), array(1946, 12),
array(1947, 6), array(1948, 8), array(1949, 10), array(1800, 6),
array(1801, 11), array(1802, 8), array(1803, 10), array(1804, 12),
array(1805, 12), array(1806, 6), array(1807, 11), array(1808, 10),
array(1809, 10), array(1810, 12), array(1811, 12), array(1812, 11),
array(1813, 8), array(1814, 10), array(1815, 10), array(1816, 12),
array(1817, 6), array(1818, 11), array(1819, 8), array(1820, 10),
array(1821, 12), array(1822, 12), array(1823, 6), array(1824, 8),
array(1825, 10), array(1826, 10), array(1827, 12), array(1828, 6),
array(1829, 11), array(1830, 8), array(1831, 10), array(1832, 12),
array(1833, 12), array(1834, 6), array(1835, 11), array(1836, 10),
array(1837, 10), array(1838, 12), array(1839, 12), array(1840, 11),
array(1841, 8), array(1842, 10), array(1843, 10), array(1844, 12),
array(1845, 6), array(1846, 11), array(1847, 8), array(1848, 10),
array(1849, 12), array(1850, 12), array(1851, 6), array(1852, 8),
array(1853, 10), array(1854, 10), array(1855, 12), array(1856, 6),
array(1857, 11), array(1858, 8), array(1859, 10), array(1860, 12),
array(1861, 12), array(1862, 6), array(1863, 11), array(1864, 10),
array(1865, 10), array(1866, 12), array(1867, 12), array(1868, 11),
array(1869, 8), array(1870, 10), array(1871, 10), array(1872, 12),
array(1873, 6), array(1874, 11), array(1875, 8), array(1876, 10),
array(1877, 12), array(1878, 12), array(1879, 6), array(1880, 8),
array(1881, 10), array(1882, 10), array(1883, 12), array(1884, 6),
array(1885, 11), array(1886, 8), array(1887, 10), array(1888, 12),
array(1889, 12), array(1890, 6), array(1891, 11), array(1892, 10),
array(1893, 10), array(1894, 12), array(1895, 12), array(1896, 11),
array(1897, 8), array(1898, 10), array(1899, 10), array(1900, 12),
array(1901, 12), array(1902, 6), array(1903, 11), array(1904, 10),
array(1905, 10), array(1906, 12), array(1907, 12), array(1908, 11),
array(1909, 8), array(1910, 10), array(1911, 10), array(1912, 12),
array(1913, 6), array(1914, 11), array(1915, 8), array(1916, 10),
array(1917, 12), array(1918, 12), array(1919, 6), array(1920, 8),
array(1921, 10), array(1922, 10), array(1923, 12), array(1924, 6),
array(1925, 11), array(1926, 8), array(1927, 10), array(1928, 12),
array(1929, 12), array(1999, 12), array(2000, 12), array(2001, 11),
array(2002, 11), array(2003, 12), array(2004, 12), array(2005, 12),
array(2006, 12), array(2007, 11), array(2008, 12), array(2009, 12),
array(2010, 12), array(2011, 12), array(2012, 11), array(2013, 11),
array(2014, 12), array(2015, 12), array(2016, 12), array(2017, 12),
array(2018, 11), array(2019, 11), array(2020, 12), array(2021, 12),
array(2022, 12), array(2023, 12), array(2024, 11), array(2025, 12),
array(2026, 12), array(2027, 12), array(2028, 12), array(2029, 11),
array(2030, 11), array(2031, 12), array(2032, 12), array(2033, 12),
array(2034, 12), array(2035, 11), array(2036, 12), array(2037, 12),
array(1930, 12), array(1931, 12), array(1932, 12), array(1933, 12),
array(1934, 11), array(1935, 11), array(1936, 12), array(1937, 12),
array(1938, 12), array(1939, 12), array(1940, 11), array(1941, 12),
array(1942, 12), array(1943, 12), array(1944, 12), array(1945, 11),
array(1946, 11), array(1947, 12), array(1948, 12), array(1949, 12),
array(1800, 12), array(1801, 12), array(1802, 12), array(1803, 12),
array(1804, 11), array(1805, 11), array(1806, 12), array(1807, 12),
array(1808, 12), array(1809, 12), array(1810, 11), array(1811, 11),
array(1812, 12), array(1813, 12), array(1814, 12), array(1815, 12),
array(1816, 11), array(1817, 12), array(1818, 12), array(1819, 12),
array(1820, 12), array(1821, 11), array(1822, 11), array(1823, 12),
array(1824, 12), array(1825, 12), array(1826, 12), array(1827, 11),
array(1828, 12), array(1829, 12), array(1830, 12), array(1831, 12),
array(1832, 11), array(1833, 11), array(1834, 12), array(1835, 12),
array(1836, 12), array(1837, 12), array(1838, 11), array(1839, 11),
array(1840, 12), array(1841, 12), array(1842, 12), array(1843, 12),
array(1844, 11), array(1845, 12), array(1846, 12), array(1847, 12),
array(1848, 12), array(1849, 11), array(1850, 11), array(1851, 12),
array(1852, 12), array(1853, 12), array(1854, 12), array(1855, 11),
array(1856, 12), array(1857, 12), array(1858, 12), array(1859, 12),
array(1860, 11), array(1861, 11), array(1862, 12), array(1863, 12),
array(1864, 12), array(1865, 12), array(1866, 11), array(1867, 11),
array(1868, 12), array(1869, 12), array(1870, 12), array(1871, 12),
array(1872, 11), array(1873, 12), array(1874, 12), array(1875, 12),
array(1876, 12), array(1877, 11), array(1878, 11), array(1879, 12),
array(1880, 12), array(1881, 12), array(1882, 12), array(1883, 11),
array(1884, 12), array(1885, 12), array(1886, 12), array(1887, 12),
array(1888, 11), array(1889, 11), array(1890, 12), array(1891, 12),
array(1892, 12), array(1893, 12), array(1894, 11), array(1895, 11),
array(1896, 12), array(1897, 12), array(1898, 12), array(1899, 12),
array(1900, 11), array(1901, 11), array(1902, 12), array(1903, 12),
array(1904, 12), array(1905, 12), array(1906, 11), array(1907, 11),
array(1908, 12), array(1909, 12), array(1910, 12), array(1911, 12),
array(1912, 11), array(1913, 12), array(1914, 12), array(1915, 12),
array(1916, 12), array(1917, 11), array(1918, 11), array(1919, 12),
array(1920, 12), array(1921, 12), array(1922, 12), array(1923, 11),
array(1924, 12), array(1925, 12), array(1926, 12), array(1927, 12),
array(1928, 11), array(1929, 11)
);
foreach ($tests as $date) {
list($year, $month) = $date;
echo $year . '/' . $month . ' = ' . Date_Calc::weeksInMonth($month, $year) . ' weeks' . "\n";
}
?>
--EXPECT--
1999/8 = 6 weeks
2000/10 = 6 weeks
2001/12 = 6 weeks
2002/12 = 6 weeks
2003/6 = 6 weeks
2004/8 = 6 weeks
2005/10 = 6 weeks
2006/10 = 6 weeks
2007/12 = 6 weeks
2008/6 = 6 weeks
2009/11 = 6 weeks
2010/8 = 6 weeks
2011/10 = 6 weeks
2012/12 = 6 weeks
2013/12 = 6 weeks
2014/6 = 6 weeks
2015/11 = 6 weeks
2016/10 = 6 weeks
2017/10 = 6 weeks
2018/12 = 6 weeks
2019/12 = 6 weeks
2020/11 = 6 weeks
2021/8 = 6 weeks
2022/10 = 6 weeks
2023/10 = 6 weeks
2024/12 = 6 weeks
2025/6 = 6 weeks
2026/11 = 6 weeks
2027/8 = 6 weeks
2028/10 = 6 weeks
2029/12 = 6 weeks
2030/12 = 6 weeks
2031/6 = 6 weeks
2032/8 = 6 weeks
2033/10 = 6 weeks
2034/10 = 6 weeks
2035/12 = 6 weeks
2036/6 = 6 weeks
2037/11 = 6 weeks
1930/6 = 6 weeks
1931/11 = 6 weeks
1932/10 = 6 weeks
1933/10 = 6 weeks
1934/12 = 6 weeks
1935/12 = 6 weeks
1936/11 = 6 weeks
1937/8 = 6 weeks
1938/10 = 6 weeks
1939/10 = 6 weeks
1940/12 = 6 weeks
1941/6 = 6 weeks
1942/11 = 6 weeks
1943/8 = 6 weeks
1944/10 = 6 weeks
1945/12 = 6 weeks
1946/12 = 6 weeks
1947/6 = 6 weeks
1948/8 = 6 weeks
1949/10 = 6 weeks
1800/6 = 6 weeks
1801/11 = 6 weeks
1802/8 = 6 weeks
1803/10 = 6 weeks
1804/12 = 6 weeks
1805/12 = 6 weeks
1806/6 = 6 weeks
1807/11 = 6 weeks
1808/10 = 6 weeks
1809/10 = 6 weeks
1810/12 = 6 weeks
1811/12 = 6 weeks
1812/11 = 6 weeks
1813/8 = 6 weeks
1814/10 = 6 weeks
1815/10 = 6 weeks
1816/12 = 6 weeks
1817/6 = 6 weeks
1818/11 = 6 weeks
1819/8 = 6 weeks
1820/10 = 6 weeks
1821/12 = 6 weeks
1822/12 = 6 weeks
1823/6 = 6 weeks
1824/8 = 6 weeks
1825/10 = 6 weeks
1826/10 = 6 weeks
1827/12 = 6 weeks
1828/6 = 6 weeks
1829/11 = 6 weeks
1830/8 = 6 weeks
1831/10 = 6 weeks
1832/12 = 6 weeks
1833/12 = 6 weeks
1834/6 = 6 weeks
1835/11 = 6 weeks
1836/10 = 6 weeks
1837/10 = 6 weeks
1838/12 = 6 weeks
1839/12 = 6 weeks
1840/11 = 6 weeks
1841/8 = 6 weeks
1842/10 = 6 weeks
1843/10 = 6 weeks
1844/12 = 6 weeks
1845/6 = 6 weeks
1846/11 = 6 weeks
1847/8 = 6 weeks
1848/10 = 6 weeks
1849/12 = 6 weeks
1850/12 = 6 weeks
1851/6 = 6 weeks
1852/8 = 6 weeks
1853/10 = 6 weeks
1854/10 = 6 weeks
1855/12 = 6 weeks
1856/6 = 6 weeks
1857/11 = 6 weeks
1858/8 = 6 weeks
1859/10 = 6 weeks
1860/12 = 6 weeks
1861/12 = 6 weeks
1862/6 = 6 weeks
1863/11 = 6 weeks
1864/10 = 6 weeks
1865/10 = 6 weeks
1866/12 = 6 weeks
1867/12 = 6 weeks
1868/11 = 6 weeks
1869/8 = 6 weeks
1870/10 = 6 weeks
1871/10 = 6 weeks
1872/12 = 6 weeks
1873/6 = 6 weeks
1874/11 = 6 weeks
1875/8 = 6 weeks
1876/10 = 6 weeks
1877/12 = 6 weeks
1878/12 = 6 weeks
1879/6 = 6 weeks
1880/8 = 6 weeks
1881/10 = 6 weeks
1882/10 = 6 weeks
1883/12 = 6 weeks
1884/6 = 6 weeks
1885/11 = 6 weeks
1886/8 = 6 weeks
1887/10 = 6 weeks
1888/12 = 6 weeks
1889/12 = 6 weeks
1890/6 = 6 weeks
1891/11 = 6 weeks
1892/10 = 6 weeks
1893/10 = 6 weeks
1894/12 = 6 weeks
1895/12 = 6 weeks
1896/11 = 6 weeks
1897/8 = 6 weeks
1898/10 = 6 weeks
1899/10 = 6 weeks
1900/12 = 6 weeks
1901/12 = 6 weeks
1902/6 = 6 weeks
1903/11 = 6 weeks
1904/10 = 6 weeks
1905/10 = 6 weeks
1906/12 = 6 weeks
1907/12 = 6 weeks
1908/11 = 6 weeks
1909/8 = 6 weeks
1910/10 = 6 weeks
1911/10 = 6 weeks
1912/12 = 6 weeks
1913/6 = 6 weeks
1914/11 = 6 weeks
1915/8 = 6 weeks
1916/10 = 6 weeks
1917/12 = 6 weeks
1918/12 = 6 weeks
1919/6 = 6 weeks
1920/8 = 6 weeks
1921/10 = 6 weeks
1922/10 = 6 weeks
1923/12 = 6 weeks
1924/6 = 6 weeks
1925/11 = 6 weeks
1926/8 = 6 weeks
1927/10 = 6 weeks
1928/12 = 6 weeks
1929/12 = 6 weeks
1999/12 = 5 weeks
2000/12 = 5 weeks
2001/11 = 5 weeks
2002/11 = 5 weeks
2003/12 = 5 weeks
2004/12 = 5 weeks
2005/12 = 5 weeks
2006/12 = 5 weeks
2007/11 = 5 weeks
2008/12 = 5 weeks
2009/12 = 5 weeks
2010/12 = 5 weeks
2011/12 = 5 weeks
2012/11 = 5 weeks
2013/11 = 5 weeks
2014/12 = 5 weeks
2015/12 = 5 weeks
2016/12 = 5 weeks
2017/12 = 5 weeks
2018/11 = 5 weeks
2019/11 = 5 weeks
2020/12 = 5 weeks
2021/12 = 5 weeks
2022/12 = 5 weeks
2023/12 = 5 weeks
2024/11 = 5 weeks
2025/12 = 5 weeks
2026/12 = 5 weeks
2027/12 = 5 weeks
2028/12 = 5 weeks
2029/11 = 5 weeks
2030/11 = 5 weeks
2031/12 = 5 weeks
2032/12 = 5 weeks
2033/12 = 5 weeks
2034/12 = 5 weeks
2035/11 = 5 weeks
2036/12 = 5 weeks
2037/12 = 5 weeks
1930/12 = 5 weeks
1931/12 = 5 weeks
1932/12 = 5 weeks
1933/12 = 5 weeks
1934/11 = 5 weeks
1935/11 = 5 weeks
1936/12 = 5 weeks
1937/12 = 5 weeks
1938/12 = 5 weeks
1939/12 = 5 weeks
1940/11 = 5 weeks
1941/12 = 5 weeks
1942/12 = 5 weeks
1943/12 = 5 weeks
1944/12 = 5 weeks
1945/11 = 5 weeks
1946/11 = 5 weeks
1947/12 = 5 weeks
1948/12 = 5 weeks
1949/12 = 5 weeks
1800/12 = 5 weeks
1801/12 = 5 weeks
1802/12 = 5 weeks
1803/12 = 5 weeks
1804/11 = 5 weeks
1805/11 = 5 weeks
1806/12 = 5 weeks
1807/12 = 5 weeks
1808/12 = 5 weeks
1809/12 = 5 weeks
1810/11 = 5 weeks
1811/11 = 5 weeks
1812/12 = 5 weeks
1813/12 = 5 weeks
1814/12 = 5 weeks
1815/12 = 5 weeks
1816/11 = 5 weeks
1817/12 = 5 weeks
1818/12 = 5 weeks
1819/12 = 5 weeks
1820/12 = 5 weeks
1821/11 = 5 weeks
1822/11 = 5 weeks
1823/12 = 5 weeks
1824/12 = 5 weeks
1825/12 = 5 weeks
1826/12 = 5 weeks
1827/11 = 5 weeks
1828/12 = 5 weeks
1829/12 = 5 weeks
1830/12 = 5 weeks
1831/12 = 5 weeks
1832/11 = 5 weeks
1833/11 = 5 weeks
1834/12 = 5 weeks
1835/12 = 5 weeks
1836/12 = 5 weeks
1837/12 = 5 weeks
1838/11 = 5 weeks
1839/11 = 5 weeks
1840/12 = 5 weeks
1841/12 = 5 weeks
1842/12 = 5 weeks
1843/12 = 5 weeks
1844/11 = 5 weeks
1845/12 = 5 weeks
1846/12 = 5 weeks
1847/12 = 5 weeks
1848/12 = 5 weeks
1849/11 = 5 weeks
1850/11 = 5 weeks
1851/12 = 5 weeks
1852/12 = 5 weeks
1853/12 = 5 weeks
1854/12 = 5 weeks
1855/11 = 5 weeks
1856/12 = 5 weeks
1857/12 = 5 weeks
1858/12 = 5 weeks
1859/12 = 5 weeks
1860/11 = 5 weeks
1861/11 = 5 weeks
1862/12 = 5 weeks
1863/12 = 5 weeks
1864/12 = 5 weeks
1865/12 = 5 weeks
1866/11 = 5 weeks
1867/11 = 5 weeks
1868/12 = 5 weeks
1869/12 = 5 weeks
1870/12 = 5 weeks
1871/12 = 5 weeks
1872/11 = 5 weeks
1873/12 = 5 weeks
1874/12 = 5 weeks
1875/12 = 5 weeks
1876/12 = 5 weeks
1877/11 = 5 weeks
1878/11 = 5 weeks
1879/12 = 5 weeks
1880/12 = 5 weeks
1881/12 = 5 weeks
1882/12 = 5 weeks
1883/11 = 5 weeks
1884/12 = 5 weeks
1885/12 = 5 weeks
1886/12 = 5 weeks
1887/12 = 5 weeks
1888/11 = 5 weeks
1889/11 = 5 weeks
1890/12 = 5 weeks
1891/12 = 5 weeks
1892/12 = 5 weeks
1893/12 = 5 weeks
1894/11 = 5 weeks
1895/11 = 5 weeks
1896/12 = 5 weeks
1897/12 = 5 weeks
1898/12 = 5 weeks
1899/12 = 5 weeks
1900/11 = 5 weeks
1901/11 = 5 weeks
1902/12 = 5 weeks
1903/12 = 5 weeks
1904/12 = 5 weeks
1905/12 = 5 weeks
1906/11 = 5 weeks
1907/11 = 5 weeks
1908/12 = 5 weeks
1909/12 = 5 weeks
1910/12 = 5 weeks
1911/12 = 5 weeks
1912/11 = 5 weeks
1913/12 = 5 weeks
1914/12 = 5 weeks
1915/12 = 5 weeks
1916/12 = 5 weeks
1917/11 = 5 weeks
1918/11 = 5 weeks
1919/12 = 5 weeks
1920/12 = 5 weeks
1921/12 = 5 weeks
1922/12 = 5 weeks
1923/11 = 5 weeks
1924/12 = 5 weeks
1925/12 = 5 weeks
1926/12 = 5 weeks
1927/12 = 5 weeks
1928/11 = 5 weeks
1929/11 = 5 weeks

View File

@ -0,0 +1,21 @@
--TEST--
Bug #8518: Date::copy() doest not copy the parts of a second.
--FILE--
<?php
/**
* Test for: Date
* Parts tested: Date::copy()
* $Id$
*/
require_once 'Date.php';
$date = new Date('2006-11-08 10:19:25.9942');
$date->setTZbyID("UTC");
$tmp = new Date;
$tmp->copy($date);
echo $tmp->format('%Y-%m-%d %H:%M:%s%O'."\n");
?>
--EXPECT--
2006-11-08 10:19:25.994200+00:00

View File

@ -0,0 +1,88 @@
--TEST--
Bug #8912: putenv() causes crashes in DateTimeZone::inDaylightTime() under windows
--FILE--
<?php
/**
* Test for: Date_TimeZone
* Parts tested: Date_TimeZone::inDaylightTime()
*/
require_once 'Date.php';
$states = array(
'Australia/Adelaide',
'Australia/Canberra',
'Australia/Darwin',
'Australia/Brisbane',
'Australia/Hobart',
'Australia/Melbourne',
'Australia/Perth',
'Australia/Sydney'
);
$originalTimezone = new Date_TimeZone('Australia/Adelaide');
$d = new Date("2007-08-31 11:59:59Z");
$hn_time = $d->getTime();
foreach ($states as $state) {
$new_date = new Date($hn_time);
print 'Original Time (Australia/Adelaide): ' . $new_date->formatLikeSQL("TZH:TZM") . " " . $new_date->getTime() . "\n";
$timezone = new Date_TimeZone($state);
$new_date->convertTZ($timezone);
print $state . ': ' . ($hn_localtime = $new_date->getTime()) . "\n";
print 'Difference: ' . ($hn_localtime - $hn_time) . "\n";
$new_date->setTZ($originalTimezone);
print $state . ': ' . ($hn_localtime = $new_date->getTime()) . "\n";
print 'Difference: ' . ($hn_localtime - $hn_time) . "\n";
print "\n";
}
?>
--EXPECT--
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Adelaide: 1188561599
Difference: 0
Australia/Adelaide: 1188561599
Difference: 0
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Canberra: 1188561599
Difference: 0
Australia/Canberra: 1188563399
Difference: 1800
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Darwin: 1188561599
Difference: 0
Australia/Darwin: 1188561599
Difference: 0
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Brisbane: 1188561599
Difference: 0
Australia/Brisbane: 1188563399
Difference: 1800
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Hobart: 1188561599
Difference: 0
Australia/Hobart: 1188563399
Difference: 1800
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Melbourne: 1188561599
Difference: 0
Australia/Melbourne: 1188563399
Difference: 1800
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Perth: 1188561599
Difference: 0
Australia/Perth: 1188556199
Difference: -5400
Original Time (Australia/Adelaide): 01:00 1188561599
Australia/Sydney: 1188561599
Difference: 0
Australia/Sydney: 1188563399
Difference: 1800

View File

@ -0,0 +1,22 @@
--TEST--
Bug #9213: Date_Calc doesn't like including Date.php
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: DATE_CALC_FORMAT constant
* $Id$
*/
require_once 'Date.php'; //Uh oh! I break things
require_once 'Date/Calc.php';
$calc = new Date_Calc();
print $calc->beginOfWeek(1, 6, 2006) . "\n";
print $calc->beginOfWeek(1, 6, 2006) . "\n";
print $calc->beginOfNextWeek(1, 6, 2006) . "\n";
?>
--EXPECT--
20060529
20060529
20060605

View File

@ -0,0 +1,26 @@
--TEST--
Bug #9414: Date::addSeconds() fails to work properly with negative numbers
--FILE--
<?php
/**
* Test for: Date
* Parts tested: Date::addSeconds()
*/
require_once 'Date.php';
$date = new Date('2006-11-21');
print "Date is now: " . $date->format("%Y-%m-%d %H:%M") . "\n";
$date->addSeconds(-1 * 86400 * 7); # subtract 1 week (negative value)
print 'After subtracting a week\'s worth of seconds, date is: ' . $date->format("%Y-%m-%d %H:%M") . "\n";
$date->subtractSeconds(-1 * 86400 * 7); # add 1 week (negative value)
print 'After subtracting a week\'s worth of seconds, date is: ' . $date->format("%Y-%m-%d %H:%M") . "\n";
?>
--EXPECT--
Date is now: 2006-11-21 00:00
After subtracting a week's worth of seconds, date is: 2006-11-14 00:00
After subtracting a week's worth of seconds, date is: 2006-11-21 00:00

View File

@ -0,0 +1,99 @@
--TEST--
Bug #9568:
Date_Calc::beginOfMonthBySpan() and Date_Calc::endOfMonthBySpan() -
December was always shifted up one year
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: Date_Calc::beginOfMonthBySpan()
*/
require_once 'Date/Calc.php';
$DateCalc = new Date_Calc();
$month = 1; // January
$year = 2006; // Year
$sequence = 25; // Number of sequence
$out = '';
for ($months = 1; $months <= $sequence; $months++) {
$date = $DateCalc->beginOfMonthBySpan(-$months, $month, $year, '%d.%m.%Y');
$date_ex = explode('.', $date);
$out = sprintf('%d - %s.%s.%s', $months, $date_ex[0], $date_ex[1], $date_ex[2]);
if ($date_ex[1] == 12) {
$out .= ' **';
}
echo $out . "\n";
}
echo "\n";
$out = '';
for ($months = 1; $months <= $sequence; $months++) {
$date = $DateCalc->endOfMonthBySpan(-$months, $month, $year, '%d.%m.%Y');
$date_ex = explode('.', $date);
$out = sprintf('%d - %s.%s.%s', $months, $date_ex[0], $date_ex[1], $date_ex[2]);
if ($date_ex[1] == 12) {
$out .= ' **';
}
echo $out . "\n";
}
?>
--EXPECT--
1 - 01.12.2005 **
2 - 01.11.2005
3 - 01.10.2005
4 - 01.09.2005
5 - 01.08.2005
6 - 01.07.2005
7 - 01.06.2005
8 - 01.05.2005
9 - 01.04.2005
10 - 01.03.2005
11 - 01.02.2005
12 - 01.01.2005
13 - 01.12.2004 **
14 - 01.11.2004
15 - 01.10.2004
16 - 01.09.2004
17 - 01.08.2004
18 - 01.07.2004
19 - 01.06.2004
20 - 01.05.2004
21 - 01.04.2004
22 - 01.03.2004
23 - 01.02.2004
24 - 01.01.2004
25 - 01.12.2003 **
1 - 31.12.2005 **
2 - 30.11.2005
3 - 31.10.2005
4 - 30.09.2005
5 - 31.08.2005
6 - 31.07.2005
7 - 30.06.2005
8 - 31.05.2005
9 - 30.04.2005
10 - 31.03.2005
11 - 28.02.2005
12 - 31.01.2005
13 - 31.12.2004 **
14 - 30.11.2004
15 - 31.10.2004
16 - 30.09.2004
17 - 31.08.2004
18 - 31.07.2004
19 - 30.06.2004
20 - 31.05.2004
21 - 30.04.2004
22 - 31.03.2004
23 - 29.02.2004
24 - 31.01.2004
25 - 31.12.2003 **

View File

@ -0,0 +1,27 @@
--TEST--
Bug #967: Date_TimeZone uses a bad global variable
--FILE--
<?php
/**
* Test for: Date_TimeZone
* Parts tested: Date_TimeZone::setDefault() and Date_TimeZone::getDefault()
*/
require_once 'Date/TimeZone.php';
// Sets default timezone via a global variable.
$_DATE_TIMEZONE_DEFAULT = 'Pacific/Chatham';
$tz = Date_TimeZone::getDefault();
echo 'Date_TimeZone::$id = ' . $tz->id . "\n";
// Sets default timezone via Date_TimeZone::setDefault().
Date_TimeZone::setDefault('CST');
$default = 'EST';
$tz = Date_TimeZone::getDefault();
echo 'Date_TimeZone::$id = ' . $tz->id . "\n";
echo '$GLOBALS[\'_DATE_TIMEZONE_DEFAULT\'] = ' . $_DATE_TIMEZONE_DEFAULT . "\n";
?>
--EXPECT--
Date_TimeZone::$id = Pacific/Chatham
Date_TimeZone::$id = CST
$GLOBALS['_DATE_TIMEZONE_DEFAULT'] = CST

View File

@ -0,0 +1,27 @@
--TEST--
Bug #9801: Date::compare() modify params on PHP5
--FILE--
<?php
/**
* Test for: Date class
* Parts tested: Date::compare()
*/
require_once 'Date.php';
// $GLOBALS['_DATE_TIMEZONE_DEFAULT'] = 'Canada/Eastern';
$d1 = new Date();
$d2 = new Date();
$d1->setTZbyID('Canada/Eastern');
$d2->setTZbyID('Canada/Eastern');
echo 'Timezone (before): ' . $d1->tz->getId() . "\n";
Date::compare($d1, $d2);
echo 'Timezone (after): ' . $d1->tz->getId() . "\n";
?>
--EXPECT--
Timezone (before): Canada/Eastern
Timezone (after): Canada/Eastern

408
extlib/Date/tests/calc.php Executable file
View File

@ -0,0 +1,408 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests for the Date_Calc class
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date_Calc. Otherwise, use the local development
* copy of Date_Calc.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 1997-2005 Daniel Convissor <danielc@php.net>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author Daniel Convissor <danielc@php.net>
* @copyright Copyright (c) 1997-2005 Daniel Convissor <danielc@php.net>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/Date
* @since File available since Release 1.5
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date/Calc.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect != $actual) {
echo "$test_name failed. Expect: $expect. Actual: $actual\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
compare('20001122', Date_Calc::dateFormat(22, 11, 2000, '%Y%m%d'), 'dateFormat');
compare('20001122', Date_Calc::dateFormat('22', '11', '2000', '%Y%m%d'), 'dateFormat str');
compare('2001', Date_Calc::defaultCentury('1'), 'defaultCentury 1 str');
compare('2001', Date_Calc::defaultCentury(1), 'defaultCentury 1');
compare('1960', Date_Calc::defaultCentury(60), 'defaultCentury 2');
compare('2010', Date_Calc::defaultCentury(10), 'defaultCentury 3');
compare(2451871, Date_Calc::dateToDays('22', '11', '2000'), 'dateToDays str');
compare(2451871, Date_Calc::dateToDays(22, 11, 2000), 'dateToDays');
compare('20001122', Date_Calc::daysToDate(2451871), 'daysToDate');
compare('2000-47-3', Date_Calc::gregorianToISO('22', '11', '2000'), 'gregorianToISO str');
compare('2000-47-3', Date_Calc::gregorianToISO(22, 11, 2000), 'gregorianToISO');
compare(2451716.56767, Date_Calc::dateSeason('SUMMERSOLSTICE', 2000), 'dateSeason');
compare(date('Ymd'), Date_Calc::dateNow(), 'dateNow');
compare(date('Y'), Date_Calc::getYear(), 'getYear');
compare(date('m'), Date_Calc::getMonth(), 'getMonth');
compare(date('d'), Date_Calc::getDay(), 'getDay');
compare(327, Date_Calc::dayOfYear(22, 11, 2000), 'dayOfYear');
compare('November', Date_Calc::getMonthFullname(11), 'getMonthFullname');
compare('Nov', Date_Calc::getMonthAbbrname(11), 'getMonthAbbrname');
compare('Saturday', Date_Calc::getWeekdayFullname(1, 1, 2005), 'getWeekdayFullname');
compare('Sat', Date_Calc::getWeekdayAbbrname(1, 1, 2005), 'getWeekdayAbbrname');
compare(11, Date_Calc::getMonthFromFullName('November'), 'getMonthFromFullName');
compare(327, Date_Calc::dayOfYear('22', '11', '2000'), 'dayOfYear str');
compare('November', Date_Calc::getMonthFullname('11'), 'getMonthFullname str');
compare('Nov', Date_Calc::getMonthAbbrname('11'), 'getMonthAbbrname str');
compare('Saturday', Date_Calc::getWeekdayFullname('01', '01', '2005'), 'getWeekdayFullname str');
compare('Sat', Date_Calc::getWeekdayAbbrname('01', '01', '2005'), 'getWeekdayAbbrname str');
$exp = array(
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);
compare($exp, Date_Calc::getMonthNames(), 'getMonthNames');
$exp = array(
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
);
compare($exp, Date_Calc::getWeekDays(), 'getWeekDays');
compare(3, Date_Calc::dayOfWeek(22, 11, 2000), 'dayOfWeek');
compare(47, Date_Calc::weekOfYear(22, 11, 2000), 'weekOfYear');
compare(4, Date_Calc::quarterOfYear(22, 11, 2000), 'quarterOfYear');
compare(3, Date_Calc::dayOfWeek('22', '11', '2000'), 'dayOfWeek str');
compare(47, Date_Calc::weekOfYear('22', '11', '2000'), 'weekOfYear str');
compare(4, Date_Calc::quarterOfYear('22', '11', '2000'), 'quarterOfYear str');
compare(28, Date_Calc::daysInMonth(2, 1900), 'daysInMonth 1');
compare(29, Date_Calc::daysInMonth(2, 1996), 'daysInMonth 2');
compare(29, Date_Calc::daysInMonth(2, 2000), 'daysInMonth 3');
compare(28, Date_Calc::daysInMonth(2, 2001), 'daysInMonth 4');
compare(30, Date_Calc::daysInMonth(11, 2000), 'daysInMonth 5');
compare(28, Date_Calc::daysInMonth('02', 1900), 'daysInMonth 1 str');
compare(29, Date_Calc::daysInMonth('02', 1996), 'daysInMonth 2 str');
compare(29, Date_Calc::daysInMonth('02', 2000), 'daysInMonth 3 str');
compare(28, Date_Calc::daysInMonth('02', 2001), 'daysInMonth 4 str');
compare(30, Date_Calc::daysInMonth('11', '2000'), 'daysInMonth 5 str');
compare(5, Date_Calc::weeksInMonth(11, 2000), 'weeksInMonth');
compare(5, Date_Calc::weeksInMonth('11', '2000'), 'weeksInMonth str');
$exp = array(
'19000226',
'19000227',
'19000228',
'19000301',
'19000302',
'19000303',
'19000304',
);
compare($exp, Date_Calc::getCalendarWeek(27, 2, 1900), 'getCalendarWeek 1');
$exp = array(
'20000228',
'20000229',
'20000301',
'20000302',
'20000303',
'20000304',
'20000305',
);
compare($exp, Date_Calc::getCalendarWeek(28, 2, 2000), 'getCalendarWeek 2');
$exp = array(
'20001127',
'20001128',
'20001129',
'20001130',
'20001201',
'20001202',
'20001203'
);
compare($exp, Date_Calc::getCalendarWeek(27, 11, 2000), 'getCalendarWeek 3');
compare($exp, Date_Calc::getCalendarWeek('27', '11', '2000'), 'getCalendarWeek 3 str');
$exp = array(
array(
'20001030',
'20001031',
'20001101',
'20001102',
'20001103',
'20001104',
),
array(
'20001105',
'20001106',
'20001107',
'20001108',
'20001109',
'20001110',
'20001111',
),
array(
'20001112',
'20001113',
'20001114',
'20001115',
'20001116',
'20001117',
'20001118',
),
array(
'20001119',
'20001121',
'20001122',
'20001123',
'20001124',
'20001125',
'20001126',
),
array(
'20001127',
'20001128',
'20001129',
'20001130',
'20001201',
'20001202',
'20001203'
)
);
compare($exp, Date_Calc::getCalendarMonth(11, 2000), 'getCalendarMonth');
compare($exp, Date_Calc::getCalendarMonth('11', '2000'), 'getCalendarMonth str');
// I don't feel like dealing with this right now...
//compare('', Date_Calc::getCalendarYear(2000), 'getCalendarYear');
compare('20001121', Date_Calc::prevDay(22, 11, 2000), 'prevDay');
compare('20001123', Date_Calc::nextDay(22, 11, 2000), 'nextDay');
compare('20001121', Date_Calc::prevDay(22, 11, 2000), 'prevDay str');
compare('20001123', Date_Calc::nextDay('22', '11', '2000'), 'nextDay str');
compare('20001117', Date_Calc::prevWeekday('19', '11', '2000'), 'prevWeekday 1 str');
compare('20001117', Date_Calc::prevWeekday(19, 11, 2000), 'prevWeekday 1');
compare('20001121', Date_Calc::prevWeekday(22, 11, 2000), 'prevWeekday 2');
compare('20001123', Date_Calc::nextWeekday(22, 11, 2000), 'nextWeekday 1');
compare('20001127', Date_Calc::nextWeekday(24, 11, 2000), 'nextWeekday 2');
compare('20001127', Date_Calc::nextWeekday('24', '11', '2000'), 'nextWeekday 2 str');
compare('20001121', Date_Calc::prevDayOfWeek('2', '22', '11', '2000'), 'prevDayOfWeek 1 str');
compare('20001121', Date_Calc::prevDayOfWeek(2, 22, 11, 2000), 'prevDayOfWeek 1');
compare('20001115', Date_Calc::prevDayOfWeek(3, 22, 11, 2000), 'prevDayOfWeek 2');
compare('20001122', Date_Calc::prevDayOfWeek(3, 22, 11, 2000, '%Y%m%d', true), 'prevDayOfWeek 3');
compare('20001122', Date_Calc::nextDayOfWeek(3, 22, 11, 2000, '%Y%m%d', true), 'nextDayOfWeek 1');
compare('20001129', Date_Calc::nextDayOfWeek(3, 22, 11, 2000), 'nextDayOfWeek 2');
compare('20001123', Date_Calc::nextDayOfWeek(4, 22, 11, 2000), 'nextDayOfWeek 3');
compare('20001123', Date_Calc::nextDayOfWeek('4', '22', '11', '2000'), 'nextDayOfWeek 3 str');
compare('20001121', Date_Calc::prevDayOfWeekOnOrBefore('2', '22', '11', '2000'), 'prevDayOfWeekOnOrBefore 1 str');
compare('20001121', Date_Calc::prevDayOfWeekOnOrBefore(2, 22, 11, 2000), 'prevDayOfWeekOnOrBefore 1');
compare('20001122', Date_Calc::prevDayOfWeekOnOrBefore(3, 22, 11, 2000), 'prevDayOfWeekOnOrBefore 2');
compare('20001122', Date_Calc::nextDayOfWeekOnOrAfter(3, 22, 11, 2000), 'nextDayOfWeekOnOrAfter 1');
compare('20001123', Date_Calc::nextDayOfWeekOnOrAfter(4, 22, 11, 2000), 'nextDayOfWeekOnOrAfter 2');
compare('20001123', Date_Calc::nextDayOfWeekOnOrAfter('4', '22', '11', '2000'), 'nextDayOfWeekOnOrAfter 2 str');
compare('20001120', Date_Calc::beginOfWeek('22', '11', '2000'), 'beginOfWeek str');
compare('20001120', Date_Calc::beginOfWeek(22, 11, 2000), 'beginOfWeek');
compare('20001126', Date_Calc::endOfWeek(22, 11, 2000), 'endOfWeek');
compare('20001126', Date_Calc::endOfWeek('22', '11', '2000'), 'endOfWeek str');
compare('20001113', Date_Calc::beginOfPrevWeek(22, 11, 2000), 'beginOfPrevWeek');
compare('20001127', Date_Calc::beginOfNextWeek(22, 11, 2000), 'beginOfNextWeek');
compare('20001113', Date_Calc::beginOfPrevWeek('22', '11', '2000'), 'beginOfPrevWeek str');
compare('20001127', Date_Calc::beginOfNextWeek('22', '11', '2000'), 'beginOfNextWeek str');
compare('20001101', Date_Calc::beginOfMonth(11, 2000), 'beginOfMonth');
compare('20001101', Date_Calc::beginOfMonth('11', '2000'), 'beginOfMonth str');
compare('20001001', Date_Calc::beginOfPrevMonth(22, 11, 2000), 'beginOfPrevMonth');
compare('20001031', Date_Calc::endOfPrevMonth(22, 11, 2000), 'endOfPrevMonth');
compare('20001001', Date_Calc::beginOfPrevMonth('22', '11', '2000'), 'beginOfPrevMonth str');
compare('20001031', Date_Calc::endOfPrevMonth('22', '11', '2000'), 'endOfPrevMonth str');
compare('20001201', Date_Calc::beginOfNextMonth(22, 11, 2000), 'beginOfNextMonth');
compare('20001231', Date_Calc::endOfNextMonth(22, 11, 2000), 'endOfNextMonth');
compare('20001201', Date_Calc::beginOfNextMonth('22', '11', '2000'), 'beginOfNextMonth str');
compare('20001231', Date_Calc::endOfNextMonth('22', '11', '2000'), 'endOfNextMonth str');
compare('19991001', Date_Calc::beginOfMonthBySpan(-13, 11, 2000), 'beginOfMonthBySpan 1');
compare('20001001', Date_Calc::beginOfMonthBySpan(-1, 11, 2000), 'beginOfMonthBySpan 2');
compare('20001101', Date_Calc::beginOfMonthBySpan(0, 11, 2000), 'beginOfMonthBySpan 3');
compare('20001201', Date_Calc::beginOfMonthBySpan(1, 11, 2000), 'beginOfMonthBySpan 4');
compare('20011201', Date_Calc::beginOfMonthBySpan(13, 11, 2000), 'beginOfMonthBySpan 5');
compare('19990101', Date_Calc::beginOfMonthBySpan('-13', '02', '2000'), 'beginOfMonthBySpan 6 str');
compare('19990101', Date_Calc::beginOfMonthBySpan(-13, 2, 2000), 'beginOfMonthBySpan 6');
compare('20000101', Date_Calc::beginOfMonthBySpan(-1, 2, 2000), 'beginOfMonthBySpan 7');
compare('20000201', Date_Calc::beginOfMonthBySpan(0, 2, 2000), 'beginOfMonthBySpan 8');
compare('20000301', Date_Calc::beginOfMonthBySpan(1, 2, 2000), 'beginOfMonthBySpan 9');
compare('20010301', Date_Calc::beginOfMonthBySpan(13, 2, 2000), 'beginOfMonthBySpan 10');
compare('20010301', Date_Calc::beginOfMonthBySpan('13', '02', '2000'), 'beginOfMonthBySpan 10 str');
compare('19991031', Date_Calc::endOfMonthBySpan(-13, 11, 2000), 'endOfMonthBySpan 1');
compare('20001031', Date_Calc::endOfMonthBySpan(-1, 11, 2000), 'endOfMonthBySpan 2');
compare('20001130', Date_Calc::endOfMonthBySpan(0, 11, 2000), 'endOfMonthBySpan 3');
compare('20001231', Date_Calc::endOfMonthBySpan(1, 11, 2000), 'endOfMonthBySpan 4');
compare('20011231', Date_Calc::endOfMonthBySpan(13, 11, 2000), 'endOfMonthBySpan 5');
compare('19990131', Date_Calc::endOfMonthBySpan('-13', '02', '2000'), 'endOfMonthBySpan 6 str');
compare('19990131', Date_Calc::endOfMonthBySpan(-13, 2, 2000), 'endOfMonthBySpan 6');
compare('20000131', Date_Calc::endOfMonthBySpan(-1, 2, 2000), 'endOfMonthBySpan 7');
compare('20000229', Date_Calc::endOfMonthBySpan(0, 2, 2000), 'endOfMonthBySpan 8');
compare('20000331', Date_Calc::endOfMonthBySpan(1, 2, 2000), 'endOfMonthBySpan 9');
compare('20010331', Date_Calc::endOfMonthBySpan(13, 2, 2000), 'endOfMonthBySpan 10');
compare('20010331', Date_Calc::endOfMonthBySpan('13', '02', '2000'), 'endOfMonthBySpan 10 str');
compare(3, Date_Calc::firstOfMonthWeekday(11, 2000), 'firstOfMonthWeekday');
compare(3, Date_Calc::firstOfMonthWeekday('11', '2000'), 'firstOfMonthWeekday str');
compare('20050101', Date_Calc::NWeekdayOfMonth(1, 6, 1, 2005), 'NWeekdayOfMonth 161');
compare('20050102', Date_Calc::NWeekdayOfMonth(1, 0, 1, 2005), 'NWeekdayOfMonth 101');
compare('20050103', Date_Calc::NWeekdayOfMonth(1, 1, 1, 2005), 'NWeekdayOfMonth 111');
compare('20050104', Date_Calc::NWeekdayOfMonth(1, 2, 1, 2005), 'NWeekdayOfMonth 121');
compare('20050105', Date_Calc::NWeekdayOfMonth(1, 3, 1, 2005), 'NWeekdayOfMonth 131');
compare('20050106', Date_Calc::NWeekdayOfMonth(1, 4, 1, 2005), 'NWeekdayOfMonth 141');
compare('20050107', Date_Calc::NWeekdayOfMonth(1, 5, 1, 2005), 'NWeekdayOfMonth 151');
compare('20050108', Date_Calc::NWeekdayOfMonth('2', '6', '01', '2005'), 'NWeekdayOfMonth 261');
compare('20050109', Date_Calc::NWeekdayOfMonth('2', '0', '01', '2005'), 'NWeekdayOfMonth 201');
compare('20050110', Date_Calc::NWeekdayOfMonth('2', '1', '01', '2005'), 'NWeekdayOfMonth 211');
compare('20050111', Date_Calc::NWeekdayOfMonth('2', '2', '01', '2005'), 'NWeekdayOfMonth 221');
compare('20050112', Date_Calc::NWeekdayOfMonth('2', '3', '01', '2005'), 'NWeekdayOfMonth 231');
compare('20050113', Date_Calc::NWeekdayOfMonth('2', '4', '01', '2005'), 'NWeekdayOfMonth 241');
compare('20050114', Date_Calc::NWeekdayOfMonth('2', '5', '01', '2005'), 'NWeekdayOfMonth 251');
compare('20050131', Date_Calc::NWeekdayOfMonth('last', 1, 1, 2005), 'NWeekdayOfMonth l11');
compare('20050130', Date_Calc::NWeekdayOfMonth('last', 0, 1, 2005), 'NWeekdayOfMonth l01');
compare('20050129', Date_Calc::NWeekdayOfMonth('last', 6, 1, 2005), 'NWeekdayOfMonth l61');
compare('20050128', Date_Calc::NWeekdayOfMonth('last', 5, 1, 2005), 'NWeekdayOfMonth l51');
compare('20050127', Date_Calc::NWeekdayOfMonth('last', 4, 1, 2005), 'NWeekdayOfMonth l41');
compare('20050126', Date_Calc::NWeekdayOfMonth('last', 3, 1, 2005), 'NWeekdayOfMonth l31');
compare('20050125', Date_Calc::NWeekdayOfMonth('last', 2, 1, 2005), 'NWeekdayOfMonth l21');
compare('20050331', Date_Calc::NWeekdayOfMonth('last', 4, 3, 2005), 'NWeekdayOfMonth l43');
compare('20050330', Date_Calc::NWeekdayOfMonth('last', 3, 3, 2005), 'NWeekdayOfMonth l33');
compare('20050329', Date_Calc::NWeekdayOfMonth('last', 2, 3, 2005), 'NWeekdayOfMonth l23');
compare('20050328', Date_Calc::NWeekdayOfMonth('last', 1, 3, 2005), 'NWeekdayOfMonth l13');
compare('20050327', Date_Calc::NWeekdayOfMonth('last', 0, 3, 2005), 'NWeekdayOfMonth l03');
compare('20050326', Date_Calc::NWeekdayOfMonth('last', 6, 3, 2005), 'NWeekdayOfMonth l63');
compare('20050325', Date_Calc::NWeekdayOfMonth('last', 5, 3, 2005), 'NWeekdayOfMonth l53');
compare(false, Date_Calc::isValidDate(29, 2, 1900), 'isValidDate 1');
compare(true, Date_Calc::isValidDate(29, 2, 2000), 'isValidDate 2');
compare(true, Date_Calc::isValidDate('29', '02', '2000'), 'isValidDate 2 str');
compare(false, Date_Calc::isLeapYear(1900), 'isLeapYear 1');
compare(true, Date_Calc::isLeapYear(1996), 'isLeapYear 2');
compare(true, Date_Calc::isLeapYear(2000), 'isLeapYear 3');
compare(false, Date_Calc::isLeapYear(2001), 'isLeapYear 4');
compare(false, Date_Calc::isLeapYear('2001'), 'isLeapYear 4 str');
compare(false, Date_Calc::isFutureDate('22', '11', '2000'), 'isFutureDate 1 str');
compare(false, Date_Calc::isFutureDate(22, 11, 2000), 'isFutureDate 1');
compare(true, Date_Calc::isFutureDate(22, 11, date('Y') + 1), 'isFutureDate 2');
compare(false, Date_Calc::isPastDate(22, 11, date('Y') + 1), 'isPastDate 1');
compare(true, Date_Calc::isPastDate(22, 11, 2000), 'isPastDate 2');
compare(true, Date_Calc::isPastDate('22', '11', '2000'), 'isPastDate 2 str');
compare(10, Date_Calc::dateDiff(22, 11, 2000, 12, 11, 2000), 'dateDiff 1');
compare(10, Date_Calc::dateDiff(12, 11, 2000, 22, 11, 2000), 'dateDiff 2');
compare(61, Date_Calc::dateDiff(22, 11, 2000, 22, 1, 2001), 'dateDiff 3');
compare(61, Date_Calc::dateDiff('22', '11', '2000', '22', '01', '2001'), 'dateDiff 3 str');
compare(-1, Date_Calc::compareDates(12, 11, 2000, 22, 11, 2000), 'compareDates 1');
compare(0, Date_Calc::compareDates(22, 11, 2000, 22, 11, 2000), 'compareDates 2');
compare(1, Date_Calc::compareDates(22, 11, 2000, 12, 11, 2000), 'compareDates 3');
compare(1, Date_Calc::compareDates('22', '11', '2000', '12', '11', '2000'), 'compareDates 3 str');

View File

@ -0,0 +1,447 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests for the Date_Calc::addSeconds() function
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date. Otherwise, use the local development
* copy of Date.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author C.A. Woodcock <c01234@netcomuk.co.uk>
* @copyright Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @link http://pear.php.net/package/Date
* @since [next version]
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect !== $actual) {
echo "'$test_name' failed. Expect: '$expect' Actual: '$actual'\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
$date = new Date(
"1972-07-01 00:59:58.987654",
true
); // count leap seconds
$date->setTZbyID("Europe/London");
$datetest = new Date($date);
$datetest->addSeconds(1, true);
compare("01/07/1972 00.59.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1");
$datetest = new Date($date);
$datetest->addSeconds(2, true);
compare("01/07/1972 00.59.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "2"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(3, true);
compare("01/07/1972 01.00.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3");
$datetest = new Date($date);
$datetest->addSeconds(4, true);
compare("01/07/1972 01.00.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "4");
$datetest = new Date($date);
$datetest->addSeconds(5, true);
compare("01/07/1972 01.00.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "5");
$datetest = new Date($date);
$datetest->addSeconds(6, true);
compare("01/07/1972 01.00.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "6");
$datetest = new Date($date);
$datetest->addSeconds(7, true);
compare("01/07/1972 01.00.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7");
$datetest = new Date($date);
$datetest->addSeconds(8, true);
compare("01/07/1972 01.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8");
$datetest = new Date($date);
$datetest->addSeconds(9, true);
compare("01/07/1972 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "9");
$datetest = new Date($date);
$datetest->addSeconds(10, true);
compare("01/07/1972 01.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "10");
$datetest = new Date($date);
$datetest->addSeconds(60, true);
compare("01/07/1972 01.00.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "60");
$datetest = new Date($date);
$datetest->addSeconds(3599, true);
compare("01/07/1972 01.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3599");
$datetest = new Date($date);
$datetest->addSeconds(3600, true);
compare("01/07/1972 01.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3600");
$datetest = new Date($date);
$datetest->addSeconds(3601, true);
compare("01/07/1972 01.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3601");
$datetest = new Date($date);
$datetest->addSeconds(7199, true);
compare("01/07/1972 02.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7199");
$datetest = new Date($date);
$datetest->addSeconds(7200, true);
compare("01/07/1972 02.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7200");
$datetest = new Date($date);
$datetest->addSeconds(7201, true);
compare("01/07/1972 02.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7201");
$datetest = new Date($date);
$datetest->addSeconds(86400, true);
compare("02/07/1972 00.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "86400");
$datetest = new Date($date);
$datetest->addSeconds(864000, true);
compare("11/07/1972 00.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "864000");
$datetest = new Date($date);
$datetest->addSeconds(8640000, true);
compare("09/10/1972 00.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8640000");
$datetest = new Date($date);
$datetest->addSeconds(31622400, true);
compare("02/07/1973 00.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "31622400"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(63244800, true);
compare("03/07/1974 00.59.55.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "63244800"); // 3 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(94867200, true);
compare("04/07/1975 00.59.54.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "94867200"); // 4 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(126489600, true);
compare("04/07/1976 00.59.53.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "126489600"); // etc.
$datetest = new Date($date);
$datetest->addSeconds(158112000, true);
compare("05/07/1977 00.59.52.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "158112000");
$datetest = new Date($date);
$datetest->addSeconds(189734400, true);
compare("06/07/1978 00.59.51.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "189734400");
$datetest = new Date($date);
$datetest->addSeconds(221356800, true);
compare("07/07/1979 00.59.50.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "221356800");
$datetest = new Date($date);
$datetest->addSeconds(252979200, true);
compare("07/07/1980 00.59.49.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "252979200");
$datetest = new Date($date);
$datetest->addSeconds(284601600, true);
compare("08/07/1981 00.59.48.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "284601600"); // leap second in June 1981
$datetest = new Date($date);
$datetest->addSeconds(316224000, true);
compare("09/07/1982 00.59.47.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "316224000");
$datetest = new Date($date);
$datetest->addSeconds(347846400, true);
compare("10/07/1983 00.59.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "347846400");
$datetest = new Date($date);
$datetest->addSeconds(379468800, true);
compare("10/07/1984 00.59.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "379468800"); // no leap second in 1984
$datetest = new Date($date);
$datetest->addSeconds(411091200, true);
compare("11/07/1985 00.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "411091200"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(442713600, true);
compare("12/07/1986 00.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "442713600"); // no leap second in 1986
$datetest = new Date($date);
$datetest->addSeconds(474336000, true);
compare("13/07/1987 00.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "474336000");
$datetest = new Date($date);
$datetest->addSeconds(505958400, true);
compare("13/07/1988 00.59.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "505958400"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(537580800, true);
compare("14/07/1989 00.59.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "537580800");
$datetest = new Date($date);
$datetest->addSeconds(569203200, true);
compare("15/07/1990 00.59.43.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "569203200");
$datetest = new Date($date);
$datetest->addSeconds(600825600, true);
compare("16/07/1991 00.59.42.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "600825600");
$datetest = new Date($date);
$datetest->addSeconds(632448000, true);
compare("16/07/1992 00.59.41.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "632448000");
$datetest = new Date($date);
$datetest->addSeconds(664070400, true);
compare("17/07/1993 00.59.40.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "664070400");
$datetest = new Date($date);
$datetest->addSeconds(695692800, true);
compare("18/07/1994 00.59.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "695692800");
$datetest = new Date($date);
$datetest->addSeconds(727315200, true);
compare("19/07/1995 00.59.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "727315200");
$datetest = new Date($date);
$datetest->addSeconds(758937600, true);
compare("19/07/1996 00.59.38.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "758937600");
$datetest = new Date($date);
$datetest->addSeconds(790560000, true);
compare("20/07/1997 00.59.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "790560000");
$datetest = new Date($date);
$datetest->addSeconds(822182400, true);
compare("21/07/1998 00.59.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "822182400");
$datetest = new Date($date);
$datetest->addSeconds(853804800, true);
compare("22/07/1999 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "853804800");
$datetest = new Date($date);
$datetest->addSeconds(885427200, true);
compare("22/07/2000 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "885427200");
$datetest = new Date($date);
$datetest->addSeconds(917049600, true);
compare("23/07/2001 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "917049600");
$datetest = new Date($date);
$datetest->addSeconds(948672000, true);
compare("24/07/2002 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "948672000");
$datetest = new Date($date);
$datetest->addSeconds(980294400, true);
compare("25/07/2003 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "980294400");
$datetest = new Date($date);
$datetest->addSeconds(1011916800, true);
compare("25/07/2004 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1011916800");
$datetest = new Date($date);
$datetest->addSeconds(1043539200, true);
compare("26/07/2005 00.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1043539200");
$datetest = new Date($date);
$datetest->addSeconds(1075161600, true);
compare("27/07/2006 00.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1075161600"); // 23rd leap second in Dec 2005
$datetest = new Date($date);
$datetest->addSeconds(1106784000, true);
compare("28/07/2007 00.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1106784000");
$datetest = new Date($date);
$datetest->addSeconds(1138406400, true);
compare("28/07/2008 00.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1138406400");
$datetest = new Date($date);
$datetest->addSeconds(1170028800, true);
compare("29/07/2009 00.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1170028800");
$date->setDate("2006-01-01 00:00:05.987654");
$datetest = new Date($date);
$datetest->addSeconds(-1, true);
compare("01/01/2006 00.00.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1");
$datetest = new Date($date);
$datetest->addSeconds(-2, true);
compare("01/01/2006 00.00.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-2");
$datetest = new Date($date);
$datetest->addSeconds(-3, true);
compare("01/01/2006 00.00.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3");
$datetest = new Date($date);
$datetest->addSeconds(-4, true);
compare("01/01/2006 00.00.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-4");
$datetest = new Date($date);
$datetest->addSeconds(-5, true);
compare("01/01/2006 00.00.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-5");
$datetest = new Date($date);
$datetest->addSeconds(-6, true);
compare("31/12/2005 23.59.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-6"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(-7, true);
compare("31/12/2005 23.59.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7");
$datetest = new Date($date);
$datetest->addSeconds(-8, true);
compare("31/12/2005 23.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8");
$datetest = new Date($date);
$datetest->addSeconds(-9, true);
compare("31/12/2005 23.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-9");
$datetest = new Date($date);
$datetest->addSeconds(-10, true);
compare("31/12/2005 23.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-10");
$datetest = new Date($date);
$datetest->addSeconds(-60, true);
compare("31/12/2005 23.59.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-60");
$datetest = new Date($date);
$datetest->addSeconds(-3599, true);
compare("31/12/2005 23.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3599");
$datetest = new Date($date);
$datetest->addSeconds(-3600, true);
compare("31/12/2005 23.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3600");
$datetest = new Date($date);
$datetest->addSeconds(-3601, true);
compare("31/12/2005 23.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3601");
$datetest = new Date($date);
$datetest->addSeconds(-7199, true);
compare("31/12/2005 22.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7199");
$datetest = new Date($date);
$datetest->addSeconds(-7200, true);
compare("31/12/2005 22.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7200");
$datetest = new Date($date);
$datetest->addSeconds(-7201, true);
compare("31/12/2005 22.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7201");
$datetest = new Date($date);
$datetest->addSeconds(-86400, true);
compare("31/12/2005 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-86400");
$datetest = new Date($date);
$datetest->addSeconds(-864000, true);
compare("22/12/2005 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-864000");
$datetest = new Date($date);
$datetest->addSeconds(-8640000, true);
compare("23/09/2005 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8640000");
$datetest = new Date($date);
$datetest->addSeconds(-31622400, true);
compare("31/12/2004 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-31622400");
$datetest = new Date($date);
$datetest->addSeconds(-63244800, true);
compare("31/12/2003 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-63244800");
$datetest = new Date($date);
$datetest->addSeconds(-94867200, true);
compare("30/12/2002 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-94867200");
$datetest = new Date($date);
$datetest->addSeconds(-126489600, true);
compare("29/12/2001 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-126489600");
$datetest = new Date($date);
$datetest->addSeconds(-158112000, true);
compare("28/12/2000 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-158112000");
$datetest = new Date($date);
$datetest->addSeconds(-189734400, true);
compare("28/12/1999 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-189734400");
$datetest = new Date($date);
$datetest->addSeconds(-221356800, true);
compare("27/12/1998 00.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-221356800"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-252979200, true);
compare("26/12/1997 00.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-252979200");
$datetest = new Date($date);
$datetest->addSeconds(-284601600, true);
compare("25/12/1996 00.00.08.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-284601600"); // leap second in June 1997
$datetest = new Date($date);
$datetest->addSeconds(-316224000, true);
compare("25/12/1995 00.00.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-316224000"); // leap second in Dec 1995
$datetest = new Date($date);
$datetest->addSeconds(-347846400, true);
compare("24/12/1994 00.00.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-347846400");
$datetest = new Date($date);
$datetest->addSeconds(-379468800, true);
compare("23/12/1993 00.00.10.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-379468800"); // leap second in June 1994
$datetest = new Date($date);
$datetest->addSeconds(-411091200, true);
compare("22/12/1992 00.00.11.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-411091200"); // leap second in June 1993
$datetest = new Date($date);
$datetest->addSeconds(-442713600, true);
compare("22/12/1991 00.00.12.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-442713600"); // leap second in June 1992
$datetest = new Date($date);
$datetest->addSeconds(-474336000, true);
compare("21/12/1990 00.00.13.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-474336000"); // leap second in Dec 1990
$datetest = new Date($date);
$datetest->addSeconds(-505958400, true);
compare("20/12/1989 00.00.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-505958400"); // leap second in Dec 1989
$datetest = new Date($date);
$datetest->addSeconds(-537580800, true);
compare("19/12/1988 00.00.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-537580800");
$datetest = new Date($date);
$datetest->addSeconds(-569203200, true);
compare("19/12/1987 00.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-569203200"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(-600825600, true);
compare("18/12/1986 00.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-600825600");
$datetest = new Date($date);
$datetest->addSeconds(-632448000, true);
compare("17/12/1985 00.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-632448000");
$datetest = new Date($date);
$datetest->addSeconds(-664070400, true);
compare("16/12/1984 00.00.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-664070400"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(-695692800, true);
compare("16/12/1983 00.00.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-695692800");
$datetest = new Date($date);
$datetest->addSeconds(-727315200, true);
compare("15/12/1982 00.00.17.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-727315200");
$datetest = new Date($date);
$datetest->addSeconds(-758937600, true);
compare("14/12/1981 00.00.18.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-758937600");
$datetest = new Date($date);
$datetest->addSeconds(-790560000, true);
compare("13/12/1980 00.00.19.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-790560000");
$datetest = new Date($date);
$datetest->addSeconds(-822182400, true);
compare("13/12/1979 00.00.20.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-822182400");
$datetest = new Date($date);
$datetest->addSeconds(-853804800, true);
compare("12/12/1978 00.00.21.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-853804800");
$datetest = new Date($date);
$datetest->addSeconds(-885427200, true);
compare("11/12/1977 00.00.22.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-885427200");
$datetest = new Date($date);
$datetest->addSeconds(-917049600, true);
compare("10/12/1976 00.00.23.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-917049600");
$datetest = new Date($date);
$datetest->addSeconds(-948672000, true);
compare("10/12/1975 00.00.24.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-948672000");
$datetest = new Date($date);
$datetest->addSeconds(-980294400, true);
compare("09/12/1974 00.00.25.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-980294400");
$datetest = new Date($date);
$datetest->addSeconds(-1011916800, true);
compare("08/12/1973 00.00.26.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1011916800");
$datetest = new Date($date);
$datetest->addSeconds(-1043539200, true);
compare("07/12/1972 00.00.27.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1043539200");
$datetest = new Date($date);
$datetest->addSeconds(-1075161600, true);
compare("07/12/1971 00.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1075161600"); // 23 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-1106784000, true);
compare("06/12/1970 00.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1106784000");
$datetest = new Date($date);
$datetest->addSeconds(-1138406400, true);
compare("05/12/1969 00.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1138406400");
$datetest = new Date($date);
$datetest->addSeconds(-1170028800, true);
compare("04/12/1968 00.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1170028800");

View File

@ -0,0 +1,447 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests for the Date_Calc::addSeconds() function
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date. Otherwise, use the local development
* copy of Date.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author C.A. Woodcock <c01234@netcomuk.co.uk>
* @copyright Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @link http://pear.php.net/package/Date
* @since [next version]
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect !== $actual) {
echo "'$test_name' failed. Expect: '$expect' Actual: '$actual'\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
$date = new Date(
"1972-07-01 05:29:58.987654",
true
); // count leap seconds
$date->setTZbyID("Asia/Calcutta");
$datetest = new Date($date);
$datetest->addSeconds(1, true);
compare("01/07/1972 05.29.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1");
$datetest = new Date($date);
$datetest->addSeconds(2, true);
compare("01/07/1972 05.29.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "2"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(3, true);
compare("01/07/1972 05.30.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3");
$datetest = new Date($date);
$datetest->addSeconds(4, true);
compare("01/07/1972 05.30.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "4");
$datetest = new Date($date);
$datetest->addSeconds(5, true);
compare("01/07/1972 05.30.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "5");
$datetest = new Date($date);
$datetest->addSeconds(6, true);
compare("01/07/1972 05.30.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "6");
$datetest = new Date($date);
$datetest->addSeconds(7, true);
compare("01/07/1972 05.30.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7");
$datetest = new Date($date);
$datetest->addSeconds(8, true);
compare("01/07/1972 05.30.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8");
$datetest = new Date($date);
$datetest->addSeconds(9, true);
compare("01/07/1972 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "9");
$datetest = new Date($date);
$datetest->addSeconds(10, true);
compare("01/07/1972 05.30.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "10");
$datetest = new Date($date);
$datetest->addSeconds(60, true);
compare("01/07/1972 05.30.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "60");
$datetest = new Date($date);
$datetest->addSeconds(3599, true);
compare("01/07/1972 06.29.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3599");
$datetest = new Date($date);
$datetest->addSeconds(3600, true);
compare("01/07/1972 06.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3600");
$datetest = new Date($date);
$datetest->addSeconds(3601, true);
compare("01/07/1972 06.29.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3601");
$datetest = new Date($date);
$datetest->addSeconds(7199, true);
compare("01/07/1972 07.29.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7199");
$datetest = new Date($date);
$datetest->addSeconds(7200, true);
compare("01/07/1972 07.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7200");
$datetest = new Date($date);
$datetest->addSeconds(7201, true);
compare("01/07/1972 07.29.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7201");
$datetest = new Date($date);
$datetest->addSeconds(86400, true);
compare("02/07/1972 05.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "86400");
$datetest = new Date($date);
$datetest->addSeconds(864000, true);
compare("11/07/1972 05.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "864000");
$datetest = new Date($date);
$datetest->addSeconds(8640000, true);
compare("09/10/1972 05.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8640000");
$datetest = new Date($date);
$datetest->addSeconds(31622400, true);
compare("02/07/1973 05.29.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "31622400"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(63244800, true);
compare("03/07/1974 05.29.55.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "63244800"); // 3 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(94867200, true);
compare("04/07/1975 05.29.54.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "94867200"); // 4 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(126489600, true);
compare("04/07/1976 05.29.53.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "126489600"); // etc.
$datetest = new Date($date);
$datetest->addSeconds(158112000, true);
compare("05/07/1977 05.29.52.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "158112000");
$datetest = new Date($date);
$datetest->addSeconds(189734400, true);
compare("06/07/1978 05.29.51.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "189734400");
$datetest = new Date($date);
$datetest->addSeconds(221356800, true);
compare("07/07/1979 05.29.50.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "221356800");
$datetest = new Date($date);
$datetest->addSeconds(252979200, true);
compare("07/07/1980 05.29.49.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "252979200");
$datetest = new Date($date);
$datetest->addSeconds(284601600, true);
compare("08/07/1981 05.29.48.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "284601600"); // leap second in June 1981
$datetest = new Date($date);
$datetest->addSeconds(316224000, true);
compare("09/07/1982 05.29.47.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "316224000");
$datetest = new Date($date);
$datetest->addSeconds(347846400, true);
compare("10/07/1983 05.29.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "347846400");
$datetest = new Date($date);
$datetest->addSeconds(379468800, true);
compare("10/07/1984 05.29.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "379468800"); // no leap second in 1984
$datetest = new Date($date);
$datetest->addSeconds(411091200, true);
compare("11/07/1985 05.29.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "411091200"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(442713600, true);
compare("12/07/1986 05.29.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "442713600"); // no leap second in 1986
$datetest = new Date($date);
$datetest->addSeconds(474336000, true);
compare("13/07/1987 05.29.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "474336000");
$datetest = new Date($date);
$datetest->addSeconds(505958400, true);
compare("13/07/1988 05.29.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "505958400"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(537580800, true);
compare("14/07/1989 05.29.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "537580800");
$datetest = new Date($date);
$datetest->addSeconds(569203200, true);
compare("15/07/1990 05.29.43.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "569203200");
$datetest = new Date($date);
$datetest->addSeconds(600825600, true);
compare("16/07/1991 05.29.42.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "600825600");
$datetest = new Date($date);
$datetest->addSeconds(632448000, true);
compare("16/07/1992 05.29.41.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "632448000");
$datetest = new Date($date);
$datetest->addSeconds(664070400, true);
compare("17/07/1993 05.29.40.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "664070400");
$datetest = new Date($date);
$datetest->addSeconds(695692800, true);
compare("18/07/1994 05.29.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "695692800");
$datetest = new Date($date);
$datetest->addSeconds(727315200, true);
compare("19/07/1995 05.29.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "727315200");
$datetest = new Date($date);
$datetest->addSeconds(758937600, true);
compare("19/07/1996 05.29.38.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "758937600");
$datetest = new Date($date);
$datetest->addSeconds(790560000, true);
compare("20/07/1997 05.29.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "790560000");
$datetest = new Date($date);
$datetest->addSeconds(822182400, true);
compare("21/07/1998 05.29.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "822182400");
$datetest = new Date($date);
$datetest->addSeconds(853804800, true);
compare("22/07/1999 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "853804800");
$datetest = new Date($date);
$datetest->addSeconds(885427200, true);
compare("22/07/2000 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "885427200");
$datetest = new Date($date);
$datetest->addSeconds(917049600, true);
compare("23/07/2001 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "917049600");
$datetest = new Date($date);
$datetest->addSeconds(948672000, true);
compare("24/07/2002 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "948672000");
$datetest = new Date($date);
$datetest->addSeconds(980294400, true);
compare("25/07/2003 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "980294400");
$datetest = new Date($date);
$datetest->addSeconds(1011916800, true);
compare("25/07/2004 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1011916800");
$datetest = new Date($date);
$datetest->addSeconds(1043539200, true);
compare("26/07/2005 05.29.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1043539200");
$datetest = new Date($date);
$datetest->addSeconds(1075161600, true);
compare("27/07/2006 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1075161600"); // 23rd leap second in Dec 2005
$datetest = new Date($date);
$datetest->addSeconds(1106784000, true);
compare("28/07/2007 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1106784000");
$datetest = new Date($date);
$datetest->addSeconds(1138406400, true);
compare("28/07/2008 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1138406400");
$datetest = new Date($date);
$datetest->addSeconds(1170028800, true);
compare("29/07/2009 05.29.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1170028800");
$date->setDate("2006-01-01 05:30:05.987654");
$datetest = new Date($date);
$datetest->addSeconds(-1, true);
compare("01/01/2006 05.30.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1");
$datetest = new Date($date);
$datetest->addSeconds(-2, true);
compare("01/01/2006 05.30.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-2");
$datetest = new Date($date);
$datetest->addSeconds(-3, true);
compare("01/01/2006 05.30.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3");
$datetest = new Date($date);
$datetest->addSeconds(-4, true);
compare("01/01/2006 05.30.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-4");
$datetest = new Date($date);
$datetest->addSeconds(-5, true);
compare("01/01/2006 05.30.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-5");
$datetest = new Date($date);
$datetest->addSeconds(-6, true);
compare("01/01/2006 05.29.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-6"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(-7, true);
compare("01/01/2006 05.29.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7");
$datetest = new Date($date);
$datetest->addSeconds(-8, true);
compare("01/01/2006 05.29.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8");
$datetest = new Date($date);
$datetest->addSeconds(-9, true);
compare("01/01/2006 05.29.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-9");
$datetest = new Date($date);
$datetest->addSeconds(-10, true);
compare("01/01/2006 05.29.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-10");
$datetest = new Date($date);
$datetest->addSeconds(-60, true);
compare("01/01/2006 05.29.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-60");
$datetest = new Date($date);
$datetest->addSeconds(-3599, true);
compare("01/01/2006 04.30.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3599");
$datetest = new Date($date);
$datetest->addSeconds(-3600, true);
compare("01/01/2006 04.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3600");
$datetest = new Date($date);
$datetest->addSeconds(-3601, true);
compare("01/01/2006 04.30.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3601");
$datetest = new Date($date);
$datetest->addSeconds(-7199, true);
compare("01/01/2006 03.30.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7199");
$datetest = new Date($date);
$datetest->addSeconds(-7200, true);
compare("01/01/2006 03.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7200");
$datetest = new Date($date);
$datetest->addSeconds(-7201, true);
compare("01/01/2006 03.30.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7201");
$datetest = new Date($date);
$datetest->addSeconds(-86400, true);
compare("31/12/2005 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-86400");
$datetest = new Date($date);
$datetest->addSeconds(-864000, true);
compare("22/12/2005 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-864000");
$datetest = new Date($date);
$datetest->addSeconds(-8640000, true);
compare("23/09/2005 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8640000");
$datetest = new Date($date);
$datetest->addSeconds(-31622400, true);
compare("31/12/2004 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-31622400");
$datetest = new Date($date);
$datetest->addSeconds(-63244800, true);
compare("31/12/2003 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-63244800");
$datetest = new Date($date);
$datetest->addSeconds(-94867200, true);
compare("30/12/2002 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-94867200");
$datetest = new Date($date);
$datetest->addSeconds(-126489600, true);
compare("29/12/2001 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-126489600");
$datetest = new Date($date);
$datetest->addSeconds(-158112000, true);
compare("28/12/2000 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-158112000");
$datetest = new Date($date);
$datetest->addSeconds(-189734400, true);
compare("28/12/1999 05.30.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-189734400");
$datetest = new Date($date);
$datetest->addSeconds(-221356800, true);
compare("27/12/1998 05.30.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-221356800"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-252979200, true);
compare("26/12/1997 05.30.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-252979200");
$datetest = new Date($date);
$datetest->addSeconds(-284601600, true);
compare("25/12/1996 05.30.08.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-284601600"); // leap second in June 1997
$datetest = new Date($date);
$datetest->addSeconds(-316224000, true);
compare("25/12/1995 05.30.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-316224000"); // leap second in Dec 1995
$datetest = new Date($date);
$datetest->addSeconds(-347846400, true);
compare("24/12/1994 05.30.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-347846400");
$datetest = new Date($date);
$datetest->addSeconds(-379468800, true);
compare("23/12/1993 05.30.10.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-379468800"); // leap second in June 1994
$datetest = new Date($date);
$datetest->addSeconds(-411091200, true);
compare("22/12/1992 05.30.11.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-411091200"); // leap second in June 1993
$datetest = new Date($date);
$datetest->addSeconds(-442713600, true);
compare("22/12/1991 05.30.12.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-442713600"); // leap second in June 1992
$datetest = new Date($date);
$datetest->addSeconds(-474336000, true);
compare("21/12/1990 05.30.13.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-474336000"); // leap second in Dec 1990
$datetest = new Date($date);
$datetest->addSeconds(-505958400, true);
compare("20/12/1989 05.30.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-505958400"); // leap second in Dec 1989
$datetest = new Date($date);
$datetest->addSeconds(-537580800, true);
compare("19/12/1988 05.30.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-537580800");
$datetest = new Date($date);
$datetest->addSeconds(-569203200, true);
compare("19/12/1987 05.30.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-569203200"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(-600825600, true);
compare("18/12/1986 05.30.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-600825600");
$datetest = new Date($date);
$datetest->addSeconds(-632448000, true);
compare("17/12/1985 05.30.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-632448000");
$datetest = new Date($date);
$datetest->addSeconds(-664070400, true);
compare("16/12/1984 05.30.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-664070400"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(-695692800, true);
compare("16/12/1983 05.30.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-695692800");
$datetest = new Date($date);
$datetest->addSeconds(-727315200, true);
compare("15/12/1982 05.30.17.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-727315200");
$datetest = new Date($date);
$datetest->addSeconds(-758937600, true);
compare("14/12/1981 05.30.18.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-758937600");
$datetest = new Date($date);
$datetest->addSeconds(-790560000, true);
compare("13/12/1980 05.30.19.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-790560000");
$datetest = new Date($date);
$datetest->addSeconds(-822182400, true);
compare("13/12/1979 05.30.20.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-822182400");
$datetest = new Date($date);
$datetest->addSeconds(-853804800, true);
compare("12/12/1978 05.30.21.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-853804800");
$datetest = new Date($date);
$datetest->addSeconds(-885427200, true);
compare("11/12/1977 05.30.22.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-885427200");
$datetest = new Date($date);
$datetest->addSeconds(-917049600, true);
compare("10/12/1976 05.30.23.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-917049600");
$datetest = new Date($date);
$datetest->addSeconds(-948672000, true);
compare("10/12/1975 05.30.24.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-948672000");
$datetest = new Date($date);
$datetest->addSeconds(-980294400, true);
compare("09/12/1974 05.30.25.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-980294400");
$datetest = new Date($date);
$datetest->addSeconds(-1011916800, true);
compare("08/12/1973 05.30.26.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1011916800");
$datetest = new Date($date);
$datetest->addSeconds(-1043539200, true);
compare("07/12/1972 05.30.27.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1043539200");
$datetest = new Date($date);
$datetest->addSeconds(-1075161600, true);
compare("07/12/1971 05.30.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1075161600"); // 23 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-1106784000, true);
compare("06/12/1970 05.30.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1106784000");
$datetest = new Date($date);
$datetest->addSeconds(-1138406400, true);
compare("05/12/1969 05.30.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1138406400");
$datetest = new Date($date);
$datetest->addSeconds(-1170028800, true);
compare("04/12/1968 05.30.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1170028800");

View File

@ -0,0 +1,447 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests for the Date_Calc::addSeconds() function
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date. Otherwise, use the local development
* copy of Date.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author C.A. Woodcock <c01234@netcomuk.co.uk>
* @copyright Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @link http://pear.php.net/package/Date
* @since [next version]
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect !== $actual) {
echo "'$test_name' failed. Expect: '$expect' Actual: '$actual'\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
$date = new Date(
"1972-07-01 01:59:58.987654",
true
); // count leap seconds
$date->setTZbyID("Europe/Paris");
$datetest = new Date($date);
$datetest->addSeconds(1, true);
compare("01/07/1972 01.59.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1");
$datetest = new Date($date);
$datetest->addSeconds(2, true);
compare("01/07/1972 01.59.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "2"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(3, true);
compare("01/07/1972 02.00.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3");
$datetest = new Date($date);
$datetest->addSeconds(4, true);
compare("01/07/1972 02.00.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "4");
$datetest = new Date($date);
$datetest->addSeconds(5, true);
compare("01/07/1972 02.00.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "5");
$datetest = new Date($date);
$datetest->addSeconds(6, true);
compare("01/07/1972 02.00.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "6");
$datetest = new Date($date);
$datetest->addSeconds(7, true);
compare("01/07/1972 02.00.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7");
$datetest = new Date($date);
$datetest->addSeconds(8, true);
compare("01/07/1972 02.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8");
$datetest = new Date($date);
$datetest->addSeconds(9, true);
compare("01/07/1972 02.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "9");
$datetest = new Date($date);
$datetest->addSeconds(10, true);
compare("01/07/1972 02.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "10");
$datetest = new Date($date);
$datetest->addSeconds(60, true);
compare("01/07/1972 02.00.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "60");
$datetest = new Date($date);
$datetest->addSeconds(3599, true);
compare("01/07/1972 02.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3599");
$datetest = new Date($date);
$datetest->addSeconds(3600, true);
compare("01/07/1972 02.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3600");
$datetest = new Date($date);
$datetest->addSeconds(3601, true);
compare("01/07/1972 02.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "3601");
$datetest = new Date($date);
$datetest->addSeconds(7199, true);
compare("01/07/1972 03.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7199");
$datetest = new Date($date);
$datetest->addSeconds(7200, true);
compare("01/07/1972 03.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7200");
$datetest = new Date($date);
$datetest->addSeconds(7201, true);
compare("01/07/1972 03.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "7201");
$datetest = new Date($date);
$datetest->addSeconds(86400, true);
compare("02/07/1972 01.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "86400");
$datetest = new Date($date);
$datetest->addSeconds(864000, true);
compare("11/07/1972 01.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "864000");
$datetest = new Date($date);
$datetest->addSeconds(8640000, true);
compare("09/10/1972 01.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "8640000");
$datetest = new Date($date);
$datetest->addSeconds(31622400, true);
compare("02/07/1973 01.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "31622400"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(63244800, true);
compare("03/07/1974 01.59.55.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "63244800"); // 3 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(94867200, true);
compare("04/07/1975 01.59.54.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "94867200"); // 4 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(126489600, true);
compare("04/07/1976 01.59.53.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "126489600"); // etc.
$datetest = new Date($date);
$datetest->addSeconds(158112000, true);
compare("05/07/1977 01.59.52.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "158112000");
$datetest = new Date($date);
$datetest->addSeconds(189734400, true);
compare("06/07/1978 01.59.51.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "189734400");
$datetest = new Date($date);
$datetest->addSeconds(221356800, true);
compare("07/07/1979 01.59.50.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "221356800");
$datetest = new Date($date);
$datetest->addSeconds(252979200, true);
compare("07/07/1980 01.59.49.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "252979200");
$datetest = new Date($date);
$datetest->addSeconds(284601600, true);
compare("08/07/1981 01.59.48.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "284601600"); // leap second in June 1981
$datetest = new Date($date);
$datetest->addSeconds(316224000, true);
compare("09/07/1982 01.59.47.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "316224000");
$datetest = new Date($date);
$datetest->addSeconds(347846400, true);
compare("10/07/1983 01.59.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "347846400");
$datetest = new Date($date);
$datetest->addSeconds(379468800, true);
compare("10/07/1984 01.59.46.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "379468800"); // no leap second in 1984
$datetest = new Date($date);
$datetest->addSeconds(411091200, true);
compare("11/07/1985 01.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "411091200"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(442713600, true);
compare("12/07/1986 01.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "442713600"); // no leap second in 1986
$datetest = new Date($date);
$datetest->addSeconds(474336000, true);
compare("13/07/1987 01.59.45.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "474336000");
$datetest = new Date($date);
$datetest->addSeconds(505958400, true);
compare("13/07/1988 01.59.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "505958400"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(537580800, true);
compare("14/07/1989 01.59.44.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "537580800");
$datetest = new Date($date);
$datetest->addSeconds(569203200, true);
compare("15/07/1990 01.59.43.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "569203200");
$datetest = new Date($date);
$datetest->addSeconds(600825600, true);
compare("16/07/1991 01.59.42.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "600825600");
$datetest = new Date($date);
$datetest->addSeconds(632448000, true);
compare("16/07/1992 01.59.41.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "632448000");
$datetest = new Date($date);
$datetest->addSeconds(664070400, true);
compare("17/07/1993 01.59.40.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "664070400");
$datetest = new Date($date);
$datetest->addSeconds(695692800, true);
compare("18/07/1994 01.59.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "695692800");
$datetest = new Date($date);
$datetest->addSeconds(727315200, true);
compare("19/07/1995 01.59.39.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "727315200");
$datetest = new Date($date);
$datetest->addSeconds(758937600, true);
compare("19/07/1996 01.59.38.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "758937600");
$datetest = new Date($date);
$datetest->addSeconds(790560000, true);
compare("20/07/1997 01.59.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "790560000");
$datetest = new Date($date);
$datetest->addSeconds(822182400, true);
compare("21/07/1998 01.59.37.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "822182400");
$datetest = new Date($date);
$datetest->addSeconds(853804800, true);
compare("22/07/1999 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "853804800");
$datetest = new Date($date);
$datetest->addSeconds(885427200, true);
compare("22/07/2000 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "885427200");
$datetest = new Date($date);
$datetest->addSeconds(917049600, true);
compare("23/07/2001 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "917049600");
$datetest = new Date($date);
$datetest->addSeconds(948672000, true);
compare("24/07/2002 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "948672000");
$datetest = new Date($date);
$datetest->addSeconds(980294400, true);
compare("25/07/2003 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "980294400");
$datetest = new Date($date);
$datetest->addSeconds(1011916800, true);
compare("25/07/2004 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1011916800");
$datetest = new Date($date);
$datetest->addSeconds(1043539200, true);
compare("26/07/2005 01.59.36.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1043539200");
$datetest = new Date($date);
$datetest->addSeconds(1075161600, true);
compare("27/07/2006 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1075161600"); // 23rd leap second in Dec 2005
$datetest = new Date($date);
$datetest->addSeconds(1106784000, true);
compare("28/07/2007 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1106784000");
$datetest = new Date($date);
$datetest->addSeconds(1138406400, true);
compare("28/07/2008 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1138406400");
$datetest = new Date($date);
$datetest->addSeconds(1170028800, true);
compare("29/07/2009 01.59.35.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "1170028800");
$date->setDate("2006-01-01 01:00:05.987654");
$datetest = new Date($date);
$datetest->addSeconds(-1, true);
compare("01/01/2006 01.00.04.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1");
$datetest = new Date($date);
$datetest->addSeconds(-2, true);
compare("01/01/2006 01.00.03.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-2");
$datetest = new Date($date);
$datetest->addSeconds(-3, true);
compare("01/01/2006 01.00.02.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3");
$datetest = new Date($date);
$datetest->addSeconds(-4, true);
compare("01/01/2006 01.00.01.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-4");
$datetest = new Date($date);
$datetest->addSeconds(-5, true);
compare("01/01/2006 01.00.00.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-5");
$datetest = new Date($date);
$datetest->addSeconds(-6, true);
compare("01/01/2006 00.59.60.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-6"); // leap second
$datetest = new Date($date);
$datetest->addSeconds(-7, true);
compare("01/01/2006 00.59.59.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7");
$datetest = new Date($date);
$datetest->addSeconds(-8, true);
compare("01/01/2006 00.59.58.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8");
$datetest = new Date($date);
$datetest->addSeconds(-9, true);
compare("01/01/2006 00.59.57.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-9");
$datetest = new Date($date);
$datetest->addSeconds(-10, true);
compare("01/01/2006 00.59.56.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-10");
$datetest = new Date($date);
$datetest->addSeconds(-60, true);
compare("01/01/2006 00.59.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-60");
$datetest = new Date($date);
$datetest->addSeconds(-3599, true);
compare("01/01/2006 00.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3599");
$datetest = new Date($date);
$datetest->addSeconds(-3600, true);
compare("01/01/2006 00.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3600");
$datetest = new Date($date);
$datetest->addSeconds(-3601, true);
compare("01/01/2006 00.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-3601");
$datetest = new Date($date);
$datetest->addSeconds(-7199, true);
compare("31/12/2005 23.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7199");
$datetest = new Date($date);
$datetest->addSeconds(-7200, true);
compare("31/12/2005 23.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7200");
$datetest = new Date($date);
$datetest->addSeconds(-7201, true);
compare("31/12/2005 23.00.05.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-7201");
$datetest = new Date($date);
$datetest->addSeconds(-86400, true);
compare("31/12/2005 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-86400");
$datetest = new Date($date);
$datetest->addSeconds(-864000, true);
compare("22/12/2005 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-864000");
$datetest = new Date($date);
$datetest->addSeconds(-8640000, true);
compare("23/09/2005 02.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-8640000");
$datetest = new Date($date);
$datetest->addSeconds(-31622400, true);
compare("31/12/2004 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-31622400");
$datetest = new Date($date);
$datetest->addSeconds(-63244800, true);
compare("31/12/2003 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-63244800");
$datetest = new Date($date);
$datetest->addSeconds(-94867200, true);
compare("30/12/2002 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-94867200");
$datetest = new Date($date);
$datetest->addSeconds(-126489600, true);
compare("29/12/2001 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-126489600");
$datetest = new Date($date);
$datetest->addSeconds(-158112000, true);
compare("28/12/2000 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-158112000");
$datetest = new Date($date);
$datetest->addSeconds(-189734400, true);
compare("28/12/1999 01.00.06.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-189734400");
$datetest = new Date($date);
$datetest->addSeconds(-221356800, true);
compare("27/12/1998 01.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-221356800"); // 2 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-252979200, true);
compare("26/12/1997 01.00.07.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-252979200");
$datetest = new Date($date);
$datetest->addSeconds(-284601600, true);
compare("25/12/1996 01.00.08.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-284601600"); // leap second in June 1997
$datetest = new Date($date);
$datetest->addSeconds(-316224000, true);
compare("25/12/1995 01.00.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-316224000"); // leap second in Dec 1995
$datetest = new Date($date);
$datetest->addSeconds(-347846400, true);
compare("24/12/1994 01.00.09.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-347846400");
$datetest = new Date($date);
$datetest->addSeconds(-379468800, true);
compare("23/12/1993 01.00.10.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-379468800"); // leap second in June 1994
$datetest = new Date($date);
$datetest->addSeconds(-411091200, true);
compare("22/12/1992 01.00.11.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-411091200"); // leap second in June 1993
$datetest = new Date($date);
$datetest->addSeconds(-442713600, true);
compare("22/12/1991 01.00.12.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-442713600"); // leap second in June 1992
$datetest = new Date($date);
$datetest->addSeconds(-474336000, true);
compare("21/12/1990 01.00.13.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-474336000"); // leap second in Dec 1990
$datetest = new Date($date);
$datetest->addSeconds(-505958400, true);
compare("20/12/1989 01.00.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-505958400"); // leap second in Dec 1989
$datetest = new Date($date);
$datetest->addSeconds(-537580800, true);
compare("19/12/1988 01.00.14.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-537580800");
$datetest = new Date($date);
$datetest->addSeconds(-569203200, true);
compare("19/12/1987 01.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-569203200"); // leap second in Dec 1987
$datetest = new Date($date);
$datetest->addSeconds(-600825600, true);
compare("18/12/1986 01.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-600825600");
$datetest = new Date($date);
$datetest->addSeconds(-632448000, true);
compare("17/12/1985 01.00.15.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-632448000");
$datetest = new Date($date);
$datetest->addSeconds(-664070400, true);
compare("16/12/1984 01.00.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-664070400"); // leap second in June 1985
$datetest = new Date($date);
$datetest->addSeconds(-695692800, true);
compare("16/12/1983 01.00.16.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-695692800");
$datetest = new Date($date);
$datetest->addSeconds(-727315200, true);
compare("15/12/1982 01.00.17.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-727315200");
$datetest = new Date($date);
$datetest->addSeconds(-758937600, true);
compare("14/12/1981 01.00.18.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-758937600");
$datetest = new Date($date);
$datetest->addSeconds(-790560000, true);
compare("13/12/1980 01.00.19.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-790560000");
$datetest = new Date($date);
$datetest->addSeconds(-822182400, true);
compare("13/12/1979 01.00.20.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-822182400");
$datetest = new Date($date);
$datetest->addSeconds(-853804800, true);
compare("12/12/1978 01.00.21.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-853804800");
$datetest = new Date($date);
$datetest->addSeconds(-885427200, true);
compare("11/12/1977 01.00.22.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-885427200");
$datetest = new Date($date);
$datetest->addSeconds(-917049600, true);
compare("10/12/1976 01.00.23.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-917049600");
$datetest = new Date($date);
$datetest->addSeconds(-948672000, true);
compare("10/12/1975 01.00.24.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-948672000");
$datetest = new Date($date);
$datetest->addSeconds(-980294400, true);
compare("09/12/1974 01.00.25.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-980294400");
$datetest = new Date($date);
$datetest->addSeconds(-1011916800, true);
compare("08/12/1973 01.00.26.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1011916800");
$datetest = new Date($date);
$datetest->addSeconds(-1043539200, true);
compare("07/12/1972 01.00.27.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1043539200");
$datetest = new Date($date);
$datetest->addSeconds(-1075161600, true);
compare("07/12/1971 01.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1075161600"); // 23 leap seconds
$datetest = new Date($date);
$datetest->addSeconds(-1106784000, true);
compare("06/12/1970 01.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1106784000");
$datetest = new Date($date);
$datetest->addSeconds(-1138406400, true);
compare("05/12/1969 01.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1138406400");
$datetest = new Date($date);
$datetest->addSeconds(-1170028800, true);
compare("04/12/1968 01.00.28.98765", $datetest->formatLikeSQL("DD/MM/YYYY HH.MI.SS.FFFFF"), "-1170028800");

View File

@ -0,0 +1,50 @@
<?php
require_once "Date/Calc.php";
/**
* Test dates from 1970 to 2029
* Data from: http://www.merlyn.demon.co.uk/wknotest.txt
* [N.B. this link is now broken, although the web-site still exists]
* Others usefull datas available from:
* http://www.merlyn.demon.co.uk/#dat
*/
// 'wknotest.txt' is missing and no longer available on the web, and so this
// test is disabled for this reason (it was copyright anyway).
//
$failed_test_data = false;
// $wkno = file('wknotest.txt');
// $cnt = sizeof($wkno);
// for( $i=0;$i<$cnt;$i++ ){
// $parts = explode(':',$wkno[$i]);
// $weeksno[$parts[0]] = str_replace("\n",'',$parts[1]);
// }
// unset($wkno);
// foreach($weeksno as $date=>$iso){
// $year = substr($date,0,4);
// $month = substr($date,4,2);
// $day = substr($date,6);
// $iso9601 = Date_Calc::gregorianToISO($day,$month,$year);
// if($iso9601!=$iso){
// $failed_test_data = true;
// echo $date . '(' . $iso . ') =>' . $year.'-'.$month.'-'.$day .'=>' . $iso9601 . " : failed\n";
// }
// }
/**
* Bugs #19788
*/
$failed_test_19788 = false;
$pass1 = array(1998, 2, 1) == Date_Calc::isoWeekDate(5, 1, 1998) ? true : false;
$pass2 = array(1998, 2, 2) == Date_Calc::isoWeekDate(6, 1, 1998) ? true : false;
$pass3 = array(2004, 2, 1) == Date_Calc::isoWeekDate(5, 1, 2004) ? true : false;
$pass4 = array(2004, 2, 2) == Date_Calc::isoWeekDate(6, 1, 2004) ? true : false;
if (!($pass1 && $pass2 && $pass3 && $pass4)) {
$failed_test_19788 = true;
}
if ($failed_test_19788 || $failed_test_data) {
echo "Bug #19788: failed\n";
} else {
echo "Bug #19788: OK\n";
}

View File

@ -0,0 +1,68 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Leandro Lucarella |
// +----------------------------------------------------------------------+
// | This source file is subject to the New BSD license, That is bundled |
// | with this package in the file LICENSE, and is available through |
// | the world-wide-web at |
// | http://www.opensource.org/licenses/bsd-license.php |
// | If you did not receive a copy of the new BSDlicense and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | pear-dev@lists.php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Leandro Lucarella <llucax@php.net> |
// +----------------------------------------------------------------------+
//
// $Id$
//
require_once 'Date.php';
require_once 'Date/Span.php';
$date = new Date();
$tmp = new Date($date);
printf("Actual date: %s\n", $date->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:00:05'));
printf("Subtracting 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:00:20:00'));
printf("Subtracting 20 minutes: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('0:10:00:00'));
printf("Subtracting 10 hours: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:00:00:00'));
printf("Subtracting 3 days: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->subtractSpan(new Date_Span('3:10:20:05'));
printf("Subtracting 3 days, 10 hours, 20 minutes and 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:00:05'));
printf("Adding 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:00:20:00'));
printf("Adding 20 minutes: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('0:10:00:00'));
printf("Adding 10 hours: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:00:00:00'));
printf("Adding 3 days: %s\n", $tmp->getDate(DATE_FORMAT_ISO));
$tmp->copy($date);
$tmp->addSpan(new Date_Span('3:10:20:05'));
printf("Adding 3 days, 10 hours, 20 minutes and 5 seconds: %s\n", $tmp->getDate(DATE_FORMAT_ISO));

View File

@ -0,0 +1,526 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests for the Date::formatLikeStrftime(), Date::formatLikeSQL(),
* and Date::formatLikeDate()
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date. Otherwise, use the local development
* copy of Date.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author C.A. Woodcock <c01234@netcomuk.co.uk>
* @copyright Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @link http://pear.php.net/package/Date
* @since [next version]
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect !== $actual) {
echo "'$test_name' failed. Expect: '$expect' Actual: '$actual'\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
$date = new Date("2007-11-29T23:13:46.09002");
$date->setTZbyID("Europe/Amsterdam");
compare('Thu', $date->formatLikeStrftime('%a'), '%a');
compare('Thursday', $date->formatLikeStrftime('%A'), '%A');
compare('Nov', $date->formatLikeStrftime('%b'), '%b');
compare('November', $date->formatLikeStrftime('%B'), '%B');
compare('20', $date->formatLikeStrftime('%C'), '%C');
compare('29', $date->formatLikeStrftime('%d'), '%d');
compare('11/29/2007', $date->formatLikeStrftime('%D'), '%D');
compare('29', $date->formatLikeStrftime('%e'), '%e');
compare('2454434', $date->formatLikeStrftime('%E'), '%E');
compare('07', $date->formatLikeStrftime('%g'), '%g');
compare('2007', $date->formatLikeStrftime('%G'), '%G');
compare('23', $date->formatLikeStrftime('%h'), '%h');
compare('23', $date->formatLikeStrftime('%H'), '%H');
compare('11', $date->formatLikeStrftime('%i'), '%i');
compare('11', $date->formatLikeStrftime('%I'), '%I');
compare('333', $date->formatLikeStrftime('%j'), '%j');
compare('11', $date->formatLikeStrftime('%m'), '%m');
compare('13', $date->formatLikeStrftime('%M'), '%M');
compare("\n", $date->formatLikeStrftime('%n'), '%n');
compare('+01:00', $date->formatLikeStrftime('%o'), '%o');
compare('+01:00', $date->formatLikeStrftime('%O'), '%O');
compare('pm', $date->formatLikeStrftime('%p'), '%p');
compare('PM', $date->formatLikeStrftime('%P'), '%P');
compare('11:13:46 PM', $date->formatLikeStrftime('%r'), '%r');
compare('23:13', $date->formatLikeStrftime('%R'), '%R');
compare('46.090020', $date->formatLikeStrftime('%s'), '%s');
compare('46', $date->formatLikeStrftime('%S'), '%S');
compare("\t", $date->formatLikeStrftime('%t'), '%t');
compare('23:13:46', $date->formatLikeStrftime('%T'), '%T');
compare('4', $date->formatLikeStrftime('%u'), '%u');
compare('47', $date->formatLikeStrftime('%U'), '%U');
compare('48', $date->formatLikeStrftime('%V'), '%V');
compare('4', $date->formatLikeStrftime('%w'), '%w');
compare('48', $date->formatLikeStrftime('%W'), '%W');
compare('07', $date->formatLikeStrftime('%y'), '%y');
compare('2007', $date->formatLikeStrftime('%Y'), '%Y');
compare('CET', $date->formatLikeStrftime('%Z'), '%Z');
compare('%', $date->formatLikeStrftime('%%'), '%%');
// Invalid character:
//
compare('x', $date->formatLikeStrftime('x'), 'x');
compare(' <20>!<21>$%^&*()_+{}:@~<>?[];\'#,./-=`\\|', $date->formatLikeSQL(' <20>!<21>$%^&*()_+{}:@~<>?[];\'#,./-=`\\|'), ' <20>!<21>$%^&*()_+{}:@~<>?[];\'#,./-=`\\|');
compare('text " \\', $date->formatLikeSQL('"text \" \\\\"'), '"text \" \\\\"');
compare('AD', $date->formatLikeSQL('AD'), 'AD');
compare('A.D.', $date->formatLikeSQL('A.D.'), 'A.D.');
compare('ad', $date->formatLikeSQL('ad'), 'ad');
compare('a.d.', $date->formatLikeSQL('a.d.'), 'a.d.');
compare('PM', $date->formatLikeSQL('AM'), 'AM');
compare('P.M.', $date->formatLikeSQL('A.M.'), 'A.M.');
compare('pm', $date->formatLikeSQL('am'), 'am');
compare('p.m.', $date->formatLikeSQL('a.m.'), 'a.m.');
compare('AD', $date->formatLikeSQL('BC'), 'BC');
compare('A.D.', $date->formatLikeSQL('B.C.'), 'B.C.');
compare('ad', $date->formatLikeSQL('bc'), 'bc');
compare('a.d.', $date->formatLikeSQL('b.c.'), 'b.c.');
compare('0', $date->formatLikeSQL('C'), 'C');
compare('20', $date->formatLikeSQL('CC'), 'CC');
compare('020', $date->formatLikeSQL('CCC'), 'CCC');
compare('0020', $date->formatLikeSQL('CCCC'), 'CCCC');
compare(' 0', $date->formatLikeSQL('SC'), 'SC');
compare(' 20', $date->formatLikeSQL('SCC'), 'SCC');
compare(' 020', $date->formatLikeSQL('SCCC'), 'SCCC');
compare(' 0020', $date->formatLikeSQL('SCCCC'), 'SCCCC');
compare('0', $date->formatLikeSQL('NPC'), 'NPC');
compare('20', $date->formatLikeSQL('NPCC'), 'NPCC');
compare('20', $date->formatLikeSQL('NPCCC'), 'NPCCC');
compare('20', $date->formatLikeSQL('NPCCCC'), 'NPCCCC');
compare('0', $date->formatLikeSQL('NPSC'), 'NPSC');
compare('20', $date->formatLikeSQL('NPSCC'), 'NPSCC');
compare('20', $date->formatLikeSQL('NPSCCC'), 'NPSCCC');
compare('20', $date->formatLikeSQL('NPSCCCC'), 'NPSCCCC');
compare('CE ', $date->formatLikeSQL('BCE'), 'BCE');
compare('C.E. ', $date->formatLikeSQL('B.C.E.'), 'B.C.E.');
compare('ce ', $date->formatLikeSQL('bce'), 'bce');
compare('c.e. ', $date->formatLikeSQL('b.c.e.'), 'b.c.e.');
compare('CE', $date->formatLikeSQL('NPBCE'), 'NPBCE');
compare('C.E.', $date->formatLikeSQL('NPB.C.E.'), 'NPB.C.E.');
compare('ce', $date->formatLikeSQL('NPbce'), 'NPbce');
compare('c.e.', $date->formatLikeSQL('NPb.c.e.'), 'NPb.c.e.');
compare('4', $date->formatLikeSQL('D'), 'D');
compare('4TH', $date->formatLikeSQL('DTH'), 'DTH');
compare('4th', $date->formatLikeSQL('Dth'), 'Dth');
compare('FOUR', $date->formatLikeSQL('DSP'), 'DSP');
compare('FOURTH', $date->formatLikeSQL('DSPTH'), 'DSPTH');
compare('FOURTH', $date->formatLikeSQL('DTHSP'), 'DTHSP');
compare('four', $date->formatLikeSQL('Dsp'), 'Dsp');
compare('fourth', $date->formatLikeSQL('Dspth'), 'Dspth');
compare('fourth', $date->formatLikeSQL('Dthsp'), 'Dthsp');
compare('THURSDAY ', $date->formatLikeSQL('DAY'), 'DAY');
compare('Thursday ', $date->formatLikeSQL('Day'), 'Day');
compare('thursday ', $date->formatLikeSQL('day'), 'day');
compare('THURSDAY', $date->formatLikeSQL('NPDAY'), 'NPDAY');
compare('Thursday', $date->formatLikeSQL('NPDay'), 'NPDay');
compare('thursday', $date->formatLikeSQL('NPday'), 'NPday');
compare('29', $date->formatLikeSQL('DD'), 'DD');
compare('29TH', $date->formatLikeSQL('DDTH'), 'DDTH');
compare('29th', $date->formatLikeSQL('DDth'), 'DDth');
compare('TWENTY-NINE', $date->formatLikeSQL('DDSP'), 'DDSP');
compare('TWENTY-NINTH', $date->formatLikeSQL('DDSPTH'), 'DDSPTH');
compare('TWENTY-NINTH', $date->formatLikeSQL('DDTHSP'), 'DDTHSP');
compare('twenty-nine', $date->formatLikeSQL('DDsp'), 'DDsp');
compare('twenty-ninth', $date->formatLikeSQL('DDspth'), 'DDspth');
compare('twenty-ninth', $date->formatLikeSQL('DDthsp'), 'DDthsp');
compare('333', $date->formatLikeSQL('DDD'), 'DDD');
compare('333RD', $date->formatLikeSQL('DDDTH'), 'DDDTH');
compare('333rd', $date->formatLikeSQL('DDDth'), 'DDDth');
compare('THREE HUNDRED THIRTY-THREE', $date->formatLikeSQL('DDDSP'), 'DDDSP');
compare('THREE HUNDRED THIRTY-THIRD', $date->formatLikeSQL('DDDSPTH'), 'DDDSPTH');
compare('THREE HUNDRED THIRTY-THIRD', $date->formatLikeSQL('DDDTHSP'), 'DDDTHSP');
compare('three hundred thirty-three', $date->formatLikeSQL('DDDsp'), 'DDDsp');
compare('three hundred thirty-third', $date->formatLikeSQL('DDDspth'), 'DDDspth');
compare('three hundred thirty-third', $date->formatLikeSQL('DDDthsp'), 'DDDthsp');
compare('THU', $date->formatLikeSQL('DY'), 'DY');
compare('Thu', $date->formatLikeSQL('Dy'), 'Dy');
compare('thu', $date->formatLikeSQL('dy'), 'dy');
compare('0', $date->formatLikeSQL('F'), 'F');
compare('09', $date->formatLikeSQL('FF'), 'FF');
compare('090', $date->formatLikeSQL('FFF'), 'FFF');
compare('0900', $date->formatLikeSQL('FFFF'), 'FFFF');
compare('09002', $date->formatLikeSQL('FFFFF'), 'FFFFF');
compare('090020', $date->formatLikeSQL('FFFFFF'), 'FFFFFF');
compare('0900200', $date->formatLikeSQL('FFFFFFF'), 'FFFFFFF');
compare('09002000', $date->formatLikeSQL('FFFFFFFF'), 'FFFFFFFF');
compare('090020000', $date->formatLikeSQL('FFFFFFFFF'), 'FFFFFFFFF');
compare('0900200000', $date->formatLikeSQL('FFFFFFFFFF'), 'FFFFFFFFFF');
compare('0', $date->formatLikeSQL('F1'), 'F1');
compare('09', $date->formatLikeSQL('F2'), 'F2');
compare('090', $date->formatLikeSQL('F3'), 'F3');
compare('0900', $date->formatLikeSQL('F4'), 'F4');
compare('09002', $date->formatLikeSQL('F5'), 'F5');
compare('090020', $date->formatLikeSQL('F6'), 'F6');
compare('0900200', $date->formatLikeSQL('F7'), 'F7');
compare('09002000', $date->formatLikeSQL('F8'), 'F8');
compare('090020000', $date->formatLikeSQL('F9'), 'F9');
compare('0900200000', $date->formatLikeSQL('F10'), 'F10');
compare('09002000000', $date->formatLikeSQL('F11'), 'F11');
compare('090020000000', $date->formatLikeSQL('F12'), 'F12');
compare('0900200000000', $date->formatLikeSQL('F13'), 'F13');
compare('09002000000000', $date->formatLikeSQL('F14'), 'F14');
compare('09002' . str_repeat("0", 39), $date->formatLikeSQL('F44'), 'F44');
compare('23', $date->formatLikeSQL('HH'), 'HH');
compare('11', $date->formatLikeSQL('HH12'), 'HH12');
compare('23', $date->formatLikeSQL('HH24'), 'HH24');
compare('4', $date->formatLikeSQL('ID'), 'ID');
compare('48', $date->formatLikeSQL('IW'), 'IW');
compare('7', $date->formatLikeSQL('I'), 'I');
compare('07', $date->formatLikeSQL('IY'), 'IY');
compare('007', $date->formatLikeSQL('IYY'), 'IYY');
compare('2007', $date->formatLikeSQL('IYYY'), 'IYYY');
compare('02007', $date->formatLikeSQL('IYYYY'), 'IYYYY');
compare('002007', $date->formatLikeSQL('IYYYYY'), 'IYYYYY');
compare('7', $date->formatLikeSQL('NPSI'), 'NPSI');
compare('7', $date->formatLikeSQL('NPSIY'), 'NPSIY');
compare('7', $date->formatLikeSQL('NPSIYY'), 'NPSIYY');
compare('2007', $date->formatLikeSQL('NPSIYYY'), 'NPSIYYY');
compare('2007', $date->formatLikeSQL('NPSIYYYY'), 'NPSIYYYY');
compare('2007', $date->formatLikeSQL('NPSIYYYYY'), 'NPSIYYYYY');
compare(' 7', $date->formatLikeSQL('SI'), 'SI');
compare(' 07', $date->formatLikeSQL('SIY'), 'SIY');
compare(' 007', $date->formatLikeSQL('SIYY'), 'SIYY');
compare(' 2007', $date->formatLikeSQL('SIYYY'), 'SIYYY');
compare(' 02007', $date->formatLikeSQL('SIYYYY'), 'SIYYYY');
compare(' 002007', $date->formatLikeSQL('SIYYYYY'), 'SIYYYYY');
compare('7', $date->formatLikeSQL('NPIYY'), 'NPIYY');
compare('2007', $date->formatLikeSQL('NPIYYYYY'), 'NPIYYYYY');
compare('TWO THOUSAND SEVEN', $date->formatLikeSQL('NPIYYYYYSP'), 'NPIYYYYYSP');
compare('two thousand seventh', $date->formatLikeSQL('NPIYYYYYTHsp'), 'NPIYYYYYTHsp');
compare('2454434', $date->formatLikeSQL('J'), 'J');
compare('Two Million Four Hundred Fifty-four Thousand Four Hundred Thirty-four', $date->formatLikeSQL('JSp'), 'JSp');
compare('Two Million Four Hundred Fifty-four Thousand Four Hundred Thirty-fourth', $date->formatLikeSQL('JSpth'), 'JSpth');
compare('13', $date->formatLikeSQL('MI'), 'MI');
compare('thirteen', $date->formatLikeSQL('MIsP'), 'MIsP');
compare('13th', $date->formatLikeSQL('MItH'), 'MItH');
compare('13TH', $date->formatLikeSQL('MITh'), 'MITh');
compare('thirteenth', $date->formatLikeSQL('MIsPTH'), 'MIsPTH');
compare('Thirteenth', $date->formatLikeSQL('MISpth'), 'MISpth');
compare('THIRTEENTH', $date->formatLikeSQL('MISPth'), 'MISPth');
compare('11', $date->formatLikeSQL('MM'), 'MM');
compare('11', $date->formatLikeSQL('MM'), 'MM');
compare('ELEVEN', $date->formatLikeSQL('MMSP'), 'MMSP');
compare('ELEVENTH', $date->formatLikeSQL('MMSPTH'), 'MMSPTH');
compare('ELEVENTH', $date->formatLikeSQL('MMTHSP'), 'MMTHSP');
compare('Eleven', $date->formatLikeSQL('MMSp'), 'MMSp');
compare('Eleventh', $date->formatLikeSQL('MMSpTH'), 'MMSpTH');
compare('Eleventh', $date->formatLikeSQL('MMTHSp'), 'MMTHSp');
compare('eleven', $date->formatLikeSQL('MMsp'), 'MMsp');
compare('eleventh', $date->formatLikeSQL('MMspTH'), 'MMspTH');
compare('eleventh', $date->formatLikeSQL('MMTHsp'), 'MMTHsp');
compare('NOV', $date->formatLikeSQL('MON'), 'MON');
compare('Nov', $date->formatLikeSQL('Mon'), 'Mon');
compare('nov', $date->formatLikeSQL('mon'), 'mon');
compare('NOVEMBER ', $date->formatLikeSQL('MONTH'), 'MONTH');
compare('November ', $date->formatLikeSQL('Month'), 'Month');
compare('november ', $date->formatLikeSQL('month'), 'month');
compare('NOVEMBER', $date->formatLikeSQL('NPMONTH'), 'NPMONTH');
compare('November', $date->formatLikeSQL('NPMonth'), 'NPMonth');
compare('november', $date->formatLikeSQL('NPmonth'), 'NPmonth');
compare('PM', $date->formatLikeSQL('PM'), 'PM');
compare('P.M.', $date->formatLikeSQL('P.M.'), 'P.M.');
compare('pm', $date->formatLikeSQL('pm'), 'pm');
compare('p.m.', $date->formatLikeSQL('p.m.'), 'p.m.');
compare('4', $date->formatLikeSQL('Q'), 'Q');
compare('FOUR', $date->formatLikeSQL('QSP'), 'QSP');
compare('fourth', $date->formatLikeSQL('QTHsp'), 'QTHsp');
compare(' xi', $date->formatLikeSQL('rm'), 'rm');
compare(' XI', $date->formatLikeSQL('RM'), 'RM');
compare('xi', $date->formatLikeSQL('NPrm'), 'NPrm');
compare('XI', $date->formatLikeSQL('NPRM'), 'NPRM');
compare('46', $date->formatLikeSQL('SS'), 'SS');
compare('83626', $date->formatLikeSQL('SSSSS'), 'SSSSS');
compare('CET', $date->formatLikeSQL('TZC'), 'TZC');
compare('01', $date->formatLikeSQL('TZH'), 'TZH');
compare('+01', $date->formatLikeSQL('STZH'), 'STZH');
compare('1', $date->formatLikeSQL('NPTZH'), 'NPTZH');
compare('+1', $date->formatLikeSQL('NPSTZH'), 'NPSTZH');
compare('+One', $date->formatLikeSQL('NPSTZHSp'), 'NPSTZHSp');
compare('+First', $date->formatLikeSQL('NPSTZHSpth'), 'NPSTZHSpth');
compare('0', $date->formatLikeSQL('TZI'), 'TZI');
compare('00', $date->formatLikeSQL('TZM'), 'TZM');
compare('0', $date->formatLikeSQL('NPTZM'), 'NPTZM');
compare('Central European Time', $date->formatLikeSQL('TZN'), 'TZN');
compare('+01:00', $date->formatLikeSQL('TZO'), 'TZO');
compare('+01:00', $date->formatLikeSQL('NPTZO'), 'NPTZO');
compare('03600', $date->formatLikeSQL('TZS'), 'TZS');
compare(' 03600', $date->formatLikeSQL('STZS'), 'STZS');
compare('3600', $date->formatLikeSQL('NPTZS'), 'NPTZS');
compare('3600', $date->formatLikeSQL('NPSTZS'), 'NPSTZS');
compare('THREE THOUSAND SIX HUNDRED', $date->formatLikeSQL('TZSSP'), 'TZSSP');
compare('THREE THOUSAND SIX HUNDRED', $date->formatLikeSQL('NPSTZSSP'), 'NPSTZSSP');
compare('Europe/Amsterdam', $date->formatLikeSQL('TZR'), 'TZR');
$date2 = new Date($date);
$date2->setTZbyID("America/Chicago");
compare('CST', $date2->formatLikeSQL('TZC'), 'TZC (2)');
compare('06', $date2->formatLikeSQL('TZH'), 'TZH (2)');
compare('-06', $date2->formatLikeSQL('STZH'), 'STZH (2)');
compare('6', $date2->formatLikeSQL('NPTZH'), 'NPTZH (2)');
compare('-6', $date2->formatLikeSQL('NPSTZH'), 'NPSTZH (2)');
compare('-six', $date2->formatLikeSQL('NPSTZHsp'), 'NPSTZHsp (2)');
compare('-sixth', $date2->formatLikeSQL('NPSTZHspth'), 'NPSTZHspth (2)');
compare('0', $date2->formatLikeSQL('TZI'), 'TZI (2)');
compare('00', $date2->formatLikeSQL('TZM'), 'TZM (2)');
compare('0', $date2->formatLikeSQL('NPTZM'), 'NPTZM (2)');
compare('Central Standard Time', $date2->formatLikeSQL('TZN'), 'TZN (2)');
compare('-06:00', $date2->formatLikeSQL('TZO'), 'TZO (2)');
compare('-06:00', $date2->formatLikeSQL('NPTZO'), 'NPTZO (2)');
compare('21600', $date2->formatLikeSQL('TZS'), 'TZS (2)');
compare('-21600', $date2->formatLikeSQL('STZS'), 'STZS (2)');
compare('21600', $date2->formatLikeSQL('NPTZS'), 'NPTZS (2)');
compare('-21600', $date2->formatLikeSQL('NPSTZS'), 'NPSTZS (2)');
compare('TWENTY-ONE THOUSAND SIX HUNDRED', $date2->formatLikeSQL('TZSSP'), 'TZSSP (2)');
compare('MINUS TWENTY-ONE THOUSAND SIX HUNDRED', $date2->formatLikeSQL('NPSTZSSP'), 'NPSTZSSP (2)');
compare('America/Chicago', $date2->formatLikeSQL('TZR'), 'TZR (2)');
$date3 = new Date($date);
$date3->setTZbyID("UTC");
compare('UTC', $date3->formatLikeSQL('TZC'), 'TZC (formatLikeDate)');
compare('00', $date3->formatLikeSQL('TZH'), 'TZH (formatLikeDate)');
compare('+00', $date3->formatLikeSQL('STZH'), 'STZH (formatLikeDate)');
compare('0', $date3->formatLikeSQL('NPTZH'), 'NPTZH (formatLikeDate)');
compare('+0', $date3->formatLikeSQL('NPSTZH'), 'NPSTZH (formatLikeDate)');
compare('ZERO', $date3->formatLikeSQL('NPTZHSP'), 'NPTZHSP (formatLikeDate)');
compare('+ZEROTH', $date3->formatLikeSQL('NPSTZHSPTH'), 'NPSTZHSPTH (formatLikeDate)');
compare('0', $date3->formatLikeSQL('TZI'), 'TZI (formatLikeDate)');
compare('00', $date3->formatLikeSQL('TZM'), 'TZM (formatLikeDate)');
compare('0', $date3->formatLikeSQL('NPTZM'), 'NPTZM (formatLikeDate)');
compare('Coordinated Universal Time', $date3->formatLikeSQL('TZN'), 'TZN (formatLikeDate)');
compare('00000', $date3->formatLikeSQL('TZS'), 'TZS (formatLikeDate)');
compare(' 00000', $date3->formatLikeSQL('STZS'), 'STZS (formatLikeDate)');
compare('0', $date3->formatLikeSQL('NPTZS'), 'NPTZS (formatLikeDate)');
compare('0', $date3->formatLikeSQL('NPSTZS'), 'NPSTZS (formatLikeDate)');
compare('zero', $date3->formatLikeSQL('TZSsp'), 'NPSTZSsp (formatLikeDate)');
compare('Zero', $date3->formatLikeSQL('NPSTZSSp'), 'NPSTZSSp (formatLikeDate)');
compare('Z ', $date3->formatLikeSQL('TZO'), 'TZO (formatLikeDate)');
compare('Z', $date3->formatLikeSQL('NPTZO'), 'NPTZO (formatLikeDate)');
compare('UTC', $date3->formatLikeSQL('TZR'), 'TZR (formatLikeDate)');
compare('1196374426', $date->formatLikeSQL('U'), 'U');
compare('5', $date->formatLikeSQL('W'), 'W');
compare('5', $date->formatLikeSQL('W'), 'W');
// N.B. For 2007 all the week numbers match because the
// year starts on a Monday:
//
compare('48', $date->formatLikeSQL('W1'), 'W1');
compare('48', $date->formatLikeSQL('NPW1'), 'W1');
compare('48', $date->formatLikeSQL('W4'), 'W4');
compare('48', $date->formatLikeSQL('NPW4'), 'W4');
compare('48', $date->formatLikeSQL('W7'), 'W7');
compare('48', $date->formatLikeSQL('NPW7'), 'W7');
compare('48', $date->formatLikeSQL('WW'), 'WW');
compare('48', $date->formatLikeSQL('NPWW'), 'WW');
compare('TWO THOUSAND SEVEN', $date->formatLikeSQL('YEAR'), 'YEAR');
compare('Two Thousand Seven', $date->formatLikeSQL('Year'), 'Year');
compare('two thousand seven', $date->formatLikeSQL('year'), 'year');
compare('TWO THOUSAND SEVEN', $date->formatLikeSQL('NPSYEAR'), 'NPSYEAR');
compare('TWO THOUSAND SEVEN', $date->formatLikeSQL('NPSYEAR'), 'NPSYEAR');
compare('7', $date->formatLikeSQL('Y'), 'Y');
compare('07', $date->formatLikeSQL('YY'), 'YY');
compare('007', $date->formatLikeSQL('YYY'), 'YYY');
compare('2007', $date->formatLikeSQL('YYYY'), 'YYYY');
compare('02007', $date->formatLikeSQL('YYYYY'), 'YYYYY');
compare('002007', $date->formatLikeSQL('YYYYYY'), 'YYYYYY');
compare(' 7', $date->formatLikeSQL('SY'), 'SY');
compare(' 07', $date->formatLikeSQL('SYY'), 'SYY');
compare(' 007', $date->formatLikeSQL('SYYY'), 'SYYY');
compare(' 2007', $date->formatLikeSQL('SYYYY'), 'SYYYY');
compare(' 02007', $date->formatLikeSQL('SYYYYY'), 'SYYYYY');
compare(' 002007', $date->formatLikeSQL('SYYYYYY'), 'SYYYYYY');
compare('7', $date->formatLikeSQL('NPSY'), 'NPSY');
compare('7', $date->formatLikeSQL('NPSYY'), 'NPSYY');
compare('7', $date->formatLikeSQL('NPSYYY'), 'NPSYYY');
compare('2007', $date->formatLikeSQL('NPSYYYY'), 'NPSYYYY');
compare('2007', $date->formatLikeSQL('NPSYYYYY'), 'NPSYYYYY');
compare('2007', $date->formatLikeSQL('NPSYYYYYY'), 'NPSYYYYYY');
compare('TWO THOUSAND SEVEN', $date->formatLikeSQL('NPSYYYYYYSP'), 'NPSYYYYYYSP');
compare('Two Thousand Seven', $date->formatLikeSQL('NPSYYYYYYSp'), 'NPSYYYYYYSp');
compare('two thousand seven', $date->formatLikeSQL('NPSYYYYYYsp'), 'NPSYYYYYYsp');
compare('TWO THOUSAND SEVENTH', $date->formatLikeSQL('NPSYYYYYYSPth'), 'NPSYYYYYYSPth');
compare('Two Thousand Seventh', $date->formatLikeSQL('NPSYYYYYYSpth'), 'NPSYYYYYYSpth');
compare('two thousand seventh', $date->formatLikeSQL('NPSYYYYYYthsp'), 'NPSYYYYYYthsp');
compare('2007th', $date->formatLikeSQL('NPSYYYYYYth'), 'NPSYYYYYYth');
compare('2007TH', $date->formatLikeSQL('NPSYYYYYYTH'), 'NPSYYYYYYTH');
compare('7', $date->formatLikeSQL('Y'), 'Y');
compare('07', $date->formatLikeSQL('YY'), 'YY');
compare('007', $date->formatLikeSQL('YYY'), 'YYY');
compare('2,007', $date->formatLikeSQL('Y,YYY'), 'Y,YYY');
compare('02.007', $date->formatLikeSQL('YY.YYY'), 'YY.YYY');
compare('002<30>007', $date->formatLikeSQL('YYY<59>YYY'), 'YYY<59>YYY');
compare(' 7', $date->formatLikeSQL('SY'), 'SY');
compare(' 07', $date->formatLikeSQL('SYY'), 'SYY');
compare(' 007', $date->formatLikeSQL('SYYY'), 'SYYY');
compare(' 2\'007', $date->formatLikeSQL('SY\'YYY'), 'SY\'YYY');
compare(' 02 007', $date->formatLikeSQL('SYY YYY'), 'SYY YYY');
// The semi-colon (':') is an invalid separator:
//
compare(' 007:007', $date->formatLikeSQL('SYYY:YYY'), 'SYYY:YYY');
compare('2,007', $date->formatLikeSQL('NPSYYY,YYY,YYY'), 'NPSYYY,YYY,YYY');
compare('29', $date->formatLikeDate('d'), 'd (formatLikeDate)');
compare('Thu', $date->formatLikeDate('D'), 'D (formatLikeDate)');
compare('29', $date->formatLikeDate('j'), 'j (formatLikeDate)');
compare('Thursday', $date->formatLikeDate('l'), 'l (formatLikeDate)');
compare('4', $date->formatLikeDate('N'), 'N (formatLikeDate)');
compare('29th', $date->formatLikeDate('dS'), 'dS (formatLikeDate)');
compare('4', $date->formatLikeDate('w'), 'w (formatLikeDate)');
compare('332', $date->formatLikeDate('z'), 'z (formatLikeDate)');
compare('48', $date->formatLikeDate('W'), 'W (formatLikeDate)');
compare('November', $date->formatLikeDate('F'), 'F (formatLikeDate)');
compare('11', $date->formatLikeDate('m'), 'm (formatLikeDate)');
compare('Nov', $date->formatLikeDate('M'), 'M (formatLikeDate)');
compare('11', $date->formatLikeDate('n'), 'n (formatLikeDate)');
compare('30', $date->formatLikeDate('t'), 't (formatLikeDate)');
compare('0', $date->formatLikeDate('L'), 'L (formatLikeDate)');
compare('2007', $date->formatLikeDate('o'), 'o (formatLikeDate)');
compare('2007', $date->formatLikeDate('Y'), 'Y (formatLikeDate)');
compare('07', $date->formatLikeDate('y'), 'y (formatLikeDate)');
compare("pm", $date->formatLikeDate('a'), 'a (formatLikeDate)');
compare('PM', $date->formatLikeDate('A'), 'A (formatLikeDate)');
compare('11', $date->formatLikeDate('g'), 'g (formatLikeDate)');
compare('23', $date->formatLikeDate('G'), 'G (formatLikeDate)');
compare('11', $date->formatLikeDate('h'), 'h (formatLikeDate)');
compare('23', $date->formatLikeDate('H'), 'H (formatLikeDate)');
compare('13', $date->formatLikeDate('i'), 'i (formatLikeDate)');
compare('46', $date->formatLikeDate('s'), 's (formatLikeDate)');
compare('46090', $date->formatLikeDate('u'), 'u (formatLikeDate)');
compare("Europe/Amsterdam", $date->formatLikeDate('e'), 'e (formatLikeDate)');
compare('0', $date->formatLikeDate('I'), 'I (formatLikeDate)');
compare('+0100', $date->formatLikeDate('O'), 'O (formatLikeDate)');
compare('+01:00', $date->formatLikeDate('P'), 'P (formatLikeDate)');
compare('CET', $date->formatLikeDate('T'), 'T (formatLikeDate)');
compare('03600', $date->formatLikeDate('Z'), 'Z (formatLikeDate)');
compare('2007-11-29T23:13:46+01:00', $date->formatLikeDate('c'), 'c (formatLikeDate)');
compare('Thu, 29 Nov 2007 23:13:46 +0100', $date->formatLikeDate('r'), 'r (formatLikeDate)');
compare('1196374426', $date->formatLikeDate('U'), 'U (formatLikeDate)');
compare('text\\', $date->formatLikeDate('\t\e\x\t\\\\'), '\\t\\e\\x\\t\\\\ (formatLikeDate)');
compare('"', $date->formatLikeDate('"'), '" (formatLikeDate)');
compare(' ', $date->formatLikeDate(' '), 'blank space (formatLikeDate)');
compare('2007-11-29T23:13:46+01:00', $date->formatLikeDate(DATE_ATOM), 'DATE_ATOM [' . DATE_ATOM . '] (formatLikeDate)');
compare('Thursday, 29-Nov-07 23:13:46 CET', $date->formatLikeDate(DATE_COOKIE), 'DATE_COOKIE [' . DATE_COOKIE . '] (formatLikeDate)');
compare('2007-11-29T23:13:46+0100', $date->formatLikeDate(DATE_ISO8601), 'DATE_ISO8601 [' . DATE_ISO8601 . '] (formatLikeDate)');
compare('Thu, 29 Nov 07 23:13:46 +0100', $date->formatLikeDate(DATE_RFC822), 'DATE_RFC822 [' . DATE_RFC822 . '] (formatLikeDate)');
compare('Thursday, 29-Nov-07 23:13:46 CET', $date->formatLikeDate(DATE_RFC850), 'DATE_RFC850 [' . DATE_RFC850 . '] (formatLikeDate)');
compare('Thu, 29 Nov 07 23:13:46 +0100', $date->formatLikeDate(DATE_RFC1036), 'DATE_RFC1036 [' . DATE_RFC1036 . '] (formatLikeDate)');
compare('Thu, 29 Nov 2007 23:13:46 +0100', $date->formatLikeDate(DATE_RFC1123), 'DATE_RFC1123 [' . DATE_RFC1123 . '] (formatLikeDate)');
compare('Thu, 29 Nov 2007 23:13:46 +0100', $date->formatLikeDate(DATE_RFC2822), 'DATE_RFC2822 [' . DATE_RFC2822 . '] (formatLikeDate)');
compare('2007-11-29T23:13:46+01:00', $date->formatLikeDate(DATE_RFC3339), 'DATE_RFC3339 [' . DATE_RFC3339 . '] (formatLikeDate)');
compare('Thu, 29 Nov 2007 23:13:46 +0100', $date->formatLikeDate(DATE_RSS), 'DATE_RSS [' . DATE_RSS . '] (formatLikeDate)');
compare('2007-11-29T23:13:46+01:00', $date->formatLikeDate(DATE_W3C), 'DATE_W3C [' . DATE_W3C . '] (formatLikeDate)');

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,231 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Tests Date:round() and Date::trunc()
*
* Any individual tests that fail will have their name, expected result
* and actual result printed out. So seeing no output when executing
* this file is a good thing.
*
* Can be run via CLI or a web server.
*
* This test senses whether it is from an installation of PEAR::Date or if
* it's from CVS or a .tar file. If it's an installed version, use the
* installed version of Date. Otherwise, use the local development
* copy of Date.
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* All rights reserved.
*
* This source file is subject to the New BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/bsd-license.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to pear-dev@lists.php.net so we can send you a copy immediately.
*
* @category Date and Time
* @package Date
* @author C.A. Woodcock <c01234@netcomuk.co.uk>
* @copyright Copyright (c) 2007 C.A. Woodcock <c01234@netcomuk.co.uk>
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @link http://pear.php.net/package/Date
* @since [next version]
*/
if ('@include_path@' != '@' . 'include_path' . '@') {
ini_set(
'include_path',
ini_get('include_path')
. PATH_SEPARATOR . '.'
);
} else {
ini_set(
'include_path',
realpath(dirname(__FILE__) . '/../')
. PATH_SEPARATOR . '.' . PATH_SEPARATOR
. ini_get('include_path')
);
}
/**
* Get the needed class
*/
require_once 'Date.php';
/**
* Compare the test result to the expected result
*
* If the test fails, echo out the results.
*
* @param mixed $expect the scalar or array you expect from the test
* @param mixed $actual the scalar or array results from the test
* @param string $test_name the name of the test
*
* @return void
*/
function compare($expect, $actual, $test_name)
{
if (is_array($expect)) {
if (count(array_diff($actual, $expect))) {
echo "$test_name failed. Expect:\n";
print_r($expect);
echo "Actual:\n";
print_r($actual);
}
} else {
if ($expect !== $actual) {
echo "'$test_name' failed. Expect: '$expect' Actual: '$actual'\n";
}
}
}
if (php_sapi_name() != 'cli') {
echo "<pre>\n";
}
$date = new Date("19871109T16:12:24.171878000");
$od = new Date($date);
$od->round(-6);
compare('0000-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-6 (1)');
$od = new Date($date);
$od->round(-5);
compare('2000-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-5 (1)');
$od = new Date($date);
$od->round(-4);
compare('2000-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-4 (1)');
$od = new Date($date);
$od->round(-3);
compare('1990-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-3 (1)');
$od = new Date($date);
$od->round(-2);
compare('1988-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-2 (1)');
$od = new Date($date);
$od->round(-1);
compare('1987-11-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-1 (1)');
$od = new Date($date);
$od->round(0);
compare('1987-11-10 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '0 (1)');
$od = new Date($date);
$od->round(1);
compare('1987-11-09 16.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '1 (1)');
$od = new Date($date);
$od->round(2);
compare('1987-11-09 16.10.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '2 (1)');
$od = new Date($date);
$od->round(3);
compare('1987-11-09 16.12.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '3 (1)');
$od = new Date($date);
$od->round(4);
compare('1987-11-09 16.12.20.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '4 (1)');
$od = new Date($date);
$od->round(5);
compare('1987-11-09 16.12.24.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '5 (1)');
$od = new Date($date);
$od->round(6);
compare('1987-11-09 16.12.24.200000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '6 (1)');
$od = new Date($date);
$od->round(7);
compare('1987-11-09 16.12.24.170000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '7 (1)');
$od = new Date($date);
$od->round(8);
compare('1987-11-09 16.12.24.172000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '8 (1)');
$od = new Date($date);
$od->round(9);
compare('1987-11-09 16.12.24.171900000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '9 (1)');
$od = new Date($date);
$od->round(10);
compare('1987-11-09 16.12.24.171880000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '10 (1)');
$od = new Date($date);
$od->round(11);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '11 (1)');
$od = new Date($date);
$od->round(12);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '12 (1)');
$od = new Date($date);
$od->round(13);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '13 (1)');
$od = new Date($date);
$od->round(14);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '14 (1)');
$od = new Date($date);
$od->trunc(-6);
compare('0000-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-6 (1)');
$od = new Date($date);
$od->trunc(-5);
compare('1000-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-5 (1)');
$od = new Date($date);
$od->trunc(-4);
compare('1900-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-4 (1)');
$od = new Date($date);
$od->trunc(-3);
compare('1980-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-3 (1)');
$od = new Date($date);
$od->trunc(-2);
compare('1987-00-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-2 (1)');
$od = new Date($date);
$od->trunc(-1);
compare('1987-11-00 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '-1 (1)');
$od = new Date($date);
$od->trunc(0);
compare('1987-11-09 00.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '0 (1)');
$od = new Date($date);
$od->trunc(1);
compare('1987-11-09 16.00.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '1 (1)');
$od = new Date($date);
$od->trunc(2);
compare('1987-11-09 16.10.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '2 (1)');
$od = new Date($date);
$od->trunc(3);
compare('1987-11-09 16.12.00.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '3 (1)');
$od = new Date($date);
$od->trunc(4);
compare('1987-11-09 16.12.20.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '4 (1)');
$od = new Date($date);
$od->trunc(5);
compare('1987-11-09 16.12.24.000000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '5 (1)');
$od = new Date($date);
$od->trunc(6);
compare('1987-11-09 16.12.24.100000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '6 (1)');
$od = new Date($date);
$od->trunc(7);
compare('1987-11-09 16.12.24.170000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '7 (1)');
$od = new Date($date);
$od->trunc(8);
compare('1987-11-09 16.12.24.171000000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '8 (1)');
$od = new Date($date);
$od->trunc(9);
compare('1987-11-09 16.12.24.171800000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '9 (1)');
$od = new Date($date);
$od->trunc(10);
compare('1987-11-09 16.12.24.171870000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '10 (1)');
$od = new Date($date);
$od->trunc(11);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '11 (1)');
$od = new Date($date);
$od->trunc(12);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '12 (1)');
$od = new Date($date);
$od->trunc(13);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '13 (1)');
$od = new Date($date);
$od->trunc(14);
compare('1987-11-09 16.12.24.171878000', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS.FFFFFFFFF'), '14 (1)');
$od = new Date("19870709T12:00:00");
$od->round(DATE_PRECISION_DAY);
compare('1987-07-10 00.00.00', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS'), 'Midday test 1');
$od = new Date("19870709T11:59:59.999999");
$od->round(DATE_PRECISION_DAY);
compare('1987-07-09 00.00.00', $od->formatLikeSQL('YYYY-MM-DD HH.MI.SS'), 'Midday test 2');

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,100 +0,0 @@
<?php
// {{{ license
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
//
// +----------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU Lesser General Public License as |
// | published by the Free Software Foundation; either version 2.1 of the |
// | License, or (at your option) any later version. |
// | |
// | This library is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | Lesser General Public License for more details. |
// | |
// | You should have received a copy of the GNU Lesser General Public |
// | License along with this library; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
// | USA. |
// +----------------------------------------------------------------------+
//
// }}}
/**
* Encode/decode Internationalized Domain Names.
* Factory class to get correct implementation either for php4 or php5.
*
* @author Markus Nix <mnix@docuverse.de>
* @author Matthias Sommerfeld <mso@phlylabs.de>
* @package Net
* @version $Id: IDNA.php 284681 2009-07-24 04:24:27Z clockwerx $
*/
class Net_IDNA
{
// {{{ factory
/**
* Attempts to return a concrete IDNA instance for either php4 or php5.
*
* @param array $params Set of paramaters
* @return object IDNA The newly created concrete Log instance, or an
* false on an error.
* @access public
*/
function getInstance($params = array())
{
$version = explode( '.', phpversion() );
$handler = ((int)$version[0] > 4) ? 'php5' : 'php4';
$class = 'Net_IDNA_' . $handler;
$classfile = 'Net/IDNA/' . $handler . '.php';
/*
* Attempt to include our version of the named class, but don't treat
* a failure as fatal. The caller may have already included their own
* version of the named class.
*/
@include_once $classfile;
/* If the class exists, return a new instance of it. */
if (class_exists($class)) {
return new $class($params);
}
return false;
}
// }}}
// {{{ singleton
/**
* Attempts to return a concrete IDNA instance for either php4 or php5,
* only creating a new instance if no IDNA instance with the same
* parameters currently exists.
*
* @param array $params Set of paramaters
* @return object IDNA The newly created concrete Log instance, or an
* false on an error.
* @access public
*/
function singleton($params = array())
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$signature = serialize($params);
if (!isset($instances[$signature])) {
$instances[$signature] = Net_IDNA::getInstance($params);
}
return $instances[$signature];
}
// }}}
}
?>

File diff suppressed because it is too large Load Diff

3411
extlib/Net/IDNA2.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
<?php
class Net_IDNA2_Exception extends Exception
{
}

View File

@ -0,0 +1,6 @@
<?php
require_once 'Net/IDNA2/Exception.php';
class Net_IDNA2_Exception_Nameprep extends Net_IDNA2_Exception
{
}

View File

@ -0,0 +1,67 @@
<?php
require_once 'Net/IDNA2.php';
class Net_IDNA2Test extends PHPUnit_Framework_TestCase
{
/**
* Initialise tests
*
* @return void
*/
public function setUp()
{
$this->idn = new Net_IDNA2();
}
/**
* Test if a complete URL consisting also of port-number etc. will be decoded just fine, test 1
*
* @return void
*/
public function testShouldDecodePortNumbersFragmentsAndUrisCorrectly1()
{
$result = $this->idn->decode('http://www.xn--ml-6kctd8d6a.org:8080/test.php?arg1=1&arg2=2#fragment');
$this->assertSame("http://www.\xD0\xB5\xD1\x85\xD0\xB0m\xD1\x80l\xD0\xB5.org:8080/test.php?arg1=1&arg2=2#fragment", $result);
}
/**
* Test if a complete URL consisting also of port-number etc. will be decoded just fine, test 2
*
* @return void
*/
public function testShouldDecodePortNumbersFragmentsAndUrisCorrectly2()
{
$result = $this->idn->decode('http://xn--tst-qla.example.com:8080/test.php?arg1=1&arg2=2#fragment');
$this->assertSame("http://täst.example.com:8080/test.php?arg1=1&arg2=2#fragment", $result);
}
/**
* Test encoding of German letter Eszett according to the original standard (IDNA2003)
*
* @return void
*/
public function testEncodingForGermanEszettUsingIDNA2003()
{
// make sure to use 2003-encoding
$this->idn->setParams('version', '2003');
$result = $this->idn->encode('http://www.straße.example.com/');
$this->assertSame("http://www.strasse.example.com/", $result);
}
/**
* Test encoding of German letter Eszett according to the "new" standard (IDNA2005/IDNAbis)
*
* @return void
*/
public function testEncodingForGermanEszettUsingIDNA2008()
{
// make sure to use 2008-encoding
$this->idn->setParams('version', '2008');
$result = $this->idn->encode('http://www.straße.example.com/');
// switch back for other testcases
$this->idn->setParams('version', '2003');
$this->assertSame("http://www.xn--strae-oqa.example.com/", $result);
}
}

View File

@ -0,0 +1,486 @@
<?php
require_once 'Net/IDNA2.php';
// Test cases from https://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
define('IDNA_ACE_PREFIX', 'xn--');
class IDNATest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->idn = new Net_IDNA2();
}
public static function unichr($chr)
{
return mb_convert_encoding('&#' . intval($chr) . ';', 'UTF-8', 'HTML-ENTITIES');
}
private function hexarray2string($arr)
{
return implode('', array_map(array('self', 'unichr'), $arr));
}
public function testDecode1()
{
// Arabic (Egyptian)
$expected = $this->hexarray2string(array(
0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643,
0x0644, 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A,
0x061F
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "egbpdaj6bu4bxfgehfvwxn");
$this->assertSame($expected, $result);
}
public function testDecode2()
{
// Chinese (simplified)
$expected = $this->hexarray2string(array(
0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "ihqwcrb4cv8a8dqg056pqjye");
$this->assertSame($expected, $result);
}
public function testDecode3()
{
// Chinese (traditional)
$expected = $this->hexarray2string(array(
0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "ihqwctvzc91f659drss3x8bo0yb");
$this->assertSame($expected, $result);
}
public function testDecode4()
{
// Czech
$expected = $this->hexarray2string(array(
0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073,
0x0074, 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076,
0x00ED, 0x010D, 0x0065, 0x0073, 0x006B, 0x0079
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "Proprostnemluvesky-uyb24dma41a");
$this->assertSame($expected, $result);
}
public function testDecode5()
{
// Hebrew
$expected = $this->hexarray2string(array(
0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5,
0x05D8, 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9,
0x05DD, 0x05E2, 0x05D1, 0x05E8, 0x05D9, 0x05EA
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "4dbcagdahymbxekheh6e0a7fei0b");
$this->assertSame($expected, $result);
}
public function testDecode6()
{
// Hindi (Devanagari)
$expected = $this->hexarray2string(array(
0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928,
0x094D, 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902,
0x0928, 0x0939, 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938,
0x0915, 0x0924, 0x0947, 0x0939, 0x0948, 0x0902
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd");
$this->assertSame($expected, $result);
}
public function testDecode7()
{
// Japanese (kanji and hiragana)
$expected = $this->hexarray2string(array(
0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E,
0x3092, 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044,
0x306E, 0x304B
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa");
$this->assertSame($expected, $result);
}
public function testDecode8()
{
// Russian (Cyrillic)
$expected = $this->hexarray2string(array(
0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435,
0x043E, 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432,
0x043E, 0x0440, 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443,
0x0441, 0x0441, 0x043A, 0x0438
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "b1abfaaepdrnnbgefbadotcwatmq2g4l");
$this->assertSame($expected, $result);
}
public function testDecode9()
{
// Spanish
$expected = $this->hexarray2string(array(
0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F,
0x0070, 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069,
0x006D, 0x0070, 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074,
0x0065, 0x0068, 0x0061, 0x0062, 0x006C, 0x0061, 0x0072, 0x0065,
0x006E, 0x0045, 0x0073, 0x0070, 0x0061, 0x00F1, 0x006F, 0x006C
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "PorqunopuedensimplementehablarenEspaol-fmd56a");
$this->assertSame($expected, $result);
}
public function testDecode10()
{
// Vietnamese
$expected = $this->hexarray2string(array(
0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD,
0x006B, 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3,
0x0063, 0x0068, 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069,
0x1EBF, 0x006E, 0x0067, 0x0056, 0x0069, 0x1EC7, 0x0074
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g");
$this->assertSame($expected, $result);
}
public function testDecode11()
{
// Japanese
$expected = $this->hexarray2string(array(
0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "3B-ww4c5e180e575a65lsy2b");
$this->assertSame($expected, $result);
}
public function testDecode12()
{
// Japanese
$expected = $this->hexarray2string(array(
0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069,
0x0074, 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052,
0x002D, 0x004D, 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");
$this->assertSame($expected, $result);
}
public function testDecode13()
{
// Japanese
$expected = $this->hexarray2string(array(
0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E,
0x006F, 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061,
0x0079, 0x002D, 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834,
0x6240
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "Hello-Another-Way--fc4qua05auwb3674vfr0b");
$this->assertSame($expected, $result);
}
public function testDecode14()
{
// Japanese
$expected = $this->hexarray2string(array(
0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "2-u9tlzr9756bt3uc0v");
$this->assertSame($expected, $result);
}
public function testDecode15()
{
// Japanese
$expected = $this->hexarray2string(array(
0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069,
0x3059, 0x308B, 0x0035, 0x79D2, 0x524D
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "MajiKoi5-783gue6qz075azm5e");
$this->assertSame($expected, $result);
}
public function testDecode16()
{
// Japanese
$expected = $this->hexarray2string(array(
0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "de-jg4avhby1noc0d");
$this->assertSame($expected, $result);
}
public function testDecode17()
{
// Japanese
$expected = $this->hexarray2string(array(
0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "d9juau41awczczp");
$this->assertSame($expected, $result);
}
public function testDecode18()
{
// Greek
$expected = $this->hexarray2string(array(
0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "hxargifdar");
$this->assertSame($expected, $result);
}
public function testDecode19()
{
// Maltese (Malti)
$expected = $this->hexarray2string(array(
0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
0x0127, 0x0061
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "bonusaa-5bb1da");
$this->assertSame($expected, $result);
}
public function testDecode20()
{
// Russian (Cyrillic)
$expected = $this->hexarray2string(array(
0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
0x0441, 0x0441, 0x043a, 0x0438
));
$result = $this->idn->decode(IDNA_ACE_PREFIX . "b1abfaaepdrnnbgefbadotcwatmq2g4l");
$this->assertSame($expected, $result);
}
public function testEncode1()
{
// Arabic (Egyptian)
$idna = $this->hexarray2string(array(
0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643,
0x0644, 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A,
0x061F
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "egbpdaj6bu4bxfgehfvwxn", $result);
}
public function testEncode2()
{
// Chinese (simplified)
$idna = $this->hexarray2string(array(
0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "ihqwcrb4cv8a8dqg056pqjye", $result);
}
public function testEncode3()
{
// Chinese (traditional)
$idna = $this->hexarray2string(array(
0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "ihqwctvzc91f659drss3x8bo0yb", $result);
}
public function testEncode4()
{
// Czech
$idna = $this->hexarray2string(array(
0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073,
0x0074, 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076,
0x00ED, 0x010D, 0x0065, 0x0073, 0x006B, 0x0079
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "proprostnemluvesky-uyb24dma41a", $result);
}
public function testEncode5()
{
// Hebrew
$idna = $this->hexarray2string(array(
0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5,
0x05D8, 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9,
0x05DD, 0x05E2, 0x05D1, 0x05E8, 0x05D9, 0x05EA
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "4dbcagdahymbxekheh6e0a7fei0b", $result);
}
public function testEncode6()
{
// Hindi (Devanagari)
$idna = $this->hexarray2string(array(
0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928,
0x094D, 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902,
0x0928, 0x0939, 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938,
0x0915, 0x0924, 0x0947, 0x0939, 0x0948, 0x0902
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd", $result);
}
public function testEncode7()
{
// Japanese (kanji and hiragana)
$idna = $this->hexarray2string(array(
0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E,
0x3092, 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044,
0x306E, 0x304B
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa", $result);
}
public function testEncode8()
{
// Russian (Cyrillic)
$idna = $this->hexarray2string(array(
0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435,
0x043E, 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432,
0x043E, 0x0440, 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443,
0x0441, 0x0441, 0x043A, 0x0438
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "b1abfaaepdrnnbgefbadotcwatmq2g4l", $result);
}
public function testEncode9()
{
// Spanish
$idna = $this->hexarray2string(array(
0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F,
0x0070, 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069,
0x006D, 0x0070, 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074,
0x0065, 0x0068, 0x0061, 0x0062, 0x006C, 0x0061, 0x0072, 0x0065,
0x006E, 0x0045, 0x0073, 0x0070, 0x0061, 0x00F1, 0x006F, 0x006C
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "porqunopuedensimplementehablarenespaol-fmd56a", $result);
}
public function testEncode10()
{
// Vietnamese
$idna = $this->hexarray2string(array(
0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD,
0x006B, 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3,
0x0063, 0x0068, 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069,
0x1EBF, 0x006E, 0x0067, 0x0056, 0x0069, 0x1EC7, 0x0074
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "tisaohkhngthchnitingvit-kjcr8268qyxafd2f1b9g", $result);
}
public function testEncode11()
{
// Japanese
$idna = $this->hexarray2string(array(
0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "3b-ww4c5e180e575a65lsy2b", $result);
}
public function testEncode12()
{
// Japanese
$idna = $this->hexarray2string(array(
0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069,
0x0074, 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052,
0x002D, 0x004D, 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "-with-super-monkeys-pc58ag80a8qai00g7n9n", $result);
}
public function testEncode13()
{
// Japanese
$idna = $this->hexarray2string(array(
0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E,
0x006F, 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061,
0x0079, 0x002D, 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834,
0x6240
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "hello-another-way--fc4qua05auwb3674vfr0b", $result);
}
public function testEncode14()
{
// Japanese
$idna = $this->hexarray2string(array(
0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "2-u9tlzr9756bt3uc0v", $result);
}
public function testEncode15()
{
// Japanese
$idna = $this->hexarray2string(array(
0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069,
0x3059, 0x308B, 0x0035, 0x79D2, 0x524D
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "majikoi5-783gue6qz075azm5e", $result);
}
public function testEncode16()
{
// Japanese
$idna = $this->hexarray2string(array(
0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "de-jg4avhby1noc0d", $result);
}
public function testEncode17()
{
// Japanese
$idna = $this->hexarray2string(array(
0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "d9juau41awczczp", $result);
}
public function testEncode18()
{
// Greek
$idna = $this->hexarray2string(array(
0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "hxargifdar", $result);
}
public function testEncode19()
{
// Maltese (Malti)
$idna = $this->hexarray2string(array(
0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
0x0127, 0x0061
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "bonusaa-5bb1da", $result);
}
public function testEncode20()
{
// Russian (Cyrillic)
$idna = $this->hexarray2string(array(
0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
0x0441, 0x0441, 0x043a, 0x0438
));
$result = $this->idn->encode($idna);
$this->assertSame(IDNA_ACE_PREFIX . "b1abfaaepdrnnbgefbadotcwatmq2g4l", $result);
}
}

View File

@ -74,6 +74,7 @@ define('VALIDATE_ALL_EMAILS', 8);
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Pierre-Alain Joye <pajoye@php.net>
* @author Amir Mohammad Saied <amir@php.net>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @copyright 1997-2006 Pierre-Alain Joye,Tomas V.V.Cox,Amir Mohammad Saied
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
@ -91,10 +92,10 @@ class Validate
* @access protected
* @var array $_iTld (International top-level domains)
*/
var $_itld = array(
public $_itld = [
'arpa',
'root',
);
];
/**
* Generic top-level domain
@ -105,7 +106,7 @@ class Validate
* @access protected
* @var array $_gTld (Generic top-level domains)
*/
var $_gtld = array(
public $_gtld = [
'aero',
'biz',
'cat',
@ -128,7 +129,7 @@ class Validate
'post',
'tel',
'geo',
);
];
/**
* Country code top-level domains
@ -139,72 +140,72 @@ class Validate
* @access protected
* @var array $_ccTld (Country Code Top-Level Domain)
*/
var $_cctld = array(
public $_cctld = [
'ac',
'ad','ae','af','ag',
'ai','al','am','an',
'ao','aq','ar','as',
'at','au','aw','ax',
'az','ba','bb','bd',
'be','bf','bg','bh',
'bi','bj','bm','bn',
'bo','br','bs','bt',
'bu','bv','bw','by',
'bz','ca','cc','cd',
'cf','cg','ch','ci',
'ck','cl','cm','cn',
'co','cr','cs','cu',
'cv','cx','cy','cz',
'de','dj','dk','dm',
'do','dz','ec','ee',
'eg','eh','er','es',
'et','eu','fi','fj',
'fk','fm','fo','fr',
'ga','gb','gd','ge',
'gf','gg','gh','gi',
'gl','gm','gn','gp',
'gq','gr','gs','gt',
'gu','gw','gy','hk',
'hm','hn','hr','ht',
'hu','id','ie','il',
'im','in','io','iq',
'ir','is','it','je',
'jm','jo','jp','ke',
'kg','kh','ki','km',
'kn','kp','kr','kw',
'ky','kz','la','lb',
'lc','li','lk','lr',
'ls','lt','lu','lv',
'ly','ma','mc','md',
'me','mg','mh','mk',
'ml','mm','mn','mo',
'mp','mq','mr','ms',
'mt','mu','mv','mw',
'mx','my','mz','na',
'nc','ne','nf','ng',
'ni','nl','no','np',
'nr','nu','nz','om',
'pa','pe','pf','pg',
'ph','pk','pl','pm',
'pn','pr','ps','pt',
'pw','py','qa','re',
'ro','rs','ru','rw',
'sa','sb','sc','sd',
'se','sg','sh','si',
'sj','sk','sl','sm',
'sn','so','sr','st',
'su','sv','sy','sz',
'tc','td','tf','tg',
'th','tj','tk','tl',
'tm','tn','to','tp',
'tr','tt','tv','tw',
'tz','ua','ug','uk',
'us','uy','uz','va',
'vc','ve','vg','vi',
'vn','vu','wf','ws',
'ye','yt','yu','za',
'zm','zw',
);
'ad', 'ae', 'af', 'ag',
'ai', 'al', 'am', 'an',
'ao', 'aq', 'ar', 'as',
'at', 'au', 'aw', 'ax',
'az', 'ba', 'bb', 'bd',
'be', 'bf', 'bg', 'bh',
'bi', 'bj', 'bm', 'bn',
'bo', 'br', 'bs', 'bt',
'bu', 'bv', 'bw', 'by',
'bz', 'ca', 'cc', 'cd',
'cf', 'cg', 'ch', 'ci',
'ck', 'cl', 'cm', 'cn',
'co', 'cr', 'cs', 'cu',
'cv', 'cx', 'cy', 'cz',
'de', 'dj', 'dk', 'dm',
'do', 'dz', 'ec', 'ee',
'eg', 'eh', 'er', 'es',
'et', 'eu', 'fi', 'fj',
'fk', 'fm', 'fo', 'fr',
'ga', 'gb', 'gd', 'ge',
'gf', 'gg', 'gh', 'gi',
'gl', 'gm', 'gn', 'gp',
'gq', 'gr', 'gs', 'gt',
'gu', 'gw', 'gy', 'hk',
'hm', 'hn', 'hr', 'ht',
'hu', 'id', 'ie', 'il',
'im', 'in', 'io', 'iq',
'ir', 'is', 'it', 'je',
'jm', 'jo', 'jp', 'ke',
'kg', 'kh', 'ki', 'km',
'kn', 'kp', 'kr', 'kw',
'ky', 'kz', 'la', 'lb',
'lc', 'li', 'lk', 'lr',
'ls', 'lt', 'lu', 'lv',
'ly', 'ma', 'mc', 'md',
'me', 'mg', 'mh', 'mk',
'ml', 'mm', 'mn', 'mo',
'mp', 'mq', 'mr', 'ms',
'mt', 'mu', 'mv', 'mw',
'mx', 'my', 'mz', 'na',
'nc', 'ne', 'nf', 'ng',
'ni', 'nl', 'no', 'np',
'nr', 'nu', 'nz', 'om',
'pa', 'pe', 'pf', 'pg',
'ph', 'pk', 'pl', 'pm',
'pn', 'pr', 'ps', 'pt',
'pw', 'py', 'qa', 're',
'ro', 'rs', 'ru', 'rw',
'sa', 'sb', 'sc', 'sd',
'se', 'sg', 'sh', 'si',
'sj', 'sk', 'sl', 'sm',
'sn', 'so', 'sr', 'st',
'su', 'sv', 'sy', 'sz',
'tc', 'td', 'tf', 'tg',
'th', 'tj', 'tk', 'tl',
'tm', 'tn', 'to', 'tp',
'tr', 'tt', 'tv', 'tw',
'tz', 'ua', 'ug', 'uk',
'us', 'uy', 'uz', 'va',
'vc', 've', 'vg', 'vi',
'vn', 'vu', 'wf', 'ws',
'ye', 'yt', 'yu', 'za',
'zm', 'zw',
];
// }}}
/**
@ -212,15 +213,19 @@ class Validate
*
* @param string $uri tag URI to validate
*
* @return boolean true if valid tag URI, false if not
* @return bool true if valid tag URI, false if not
*
* @access private
* @throws Exception
*/
function __uriRFC4151($uri)
private function __uriRFC4151(string $uri): bool
{
$datevalid = false;
if (preg_match(
'/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/', $uri, $matches)) {
'/^tag:(?<name>.*),(?<date>\d{4}-?\d{0,2}-?\d{0,2}):(?<specific>.*)(.*:)*$/',
$uri,
$matches
)) {
$date = $matches['date'];
$date6 = strtotime($date);
if ((strlen($date) == 4) && $date <= date('Y')) {
@ -253,11 +258,11 @@ class Validate
* 'min' minimum value
* 'max' maximum value
*
* @return boolean true if valid number, false if not
* @return bool true if valid number, false if not
*
* @access public
*/
function number($number, $options = array())
public function number($number, array $options = []): bool
{
$decimal = $dec_prec = $min = $max = null;
if (is_array($options)) {
@ -295,17 +300,17 @@ class Validate
*
* @access private
*/
function __stringToUtf7($string)
public function __stringToUtf7(string $string): string
{
$return = '';
$utf7 = array(
$utf7 = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', '+', ','
);
];
$state = 0;
@ -337,7 +342,7 @@ class Validate
$return .= '-';
$state = 0;
} else {
switch($state) {
switch ($state) {
case 1:
$return .= $utf7[ord($char) >> 2];
$residue = (ord($char) & 0x03) << 4;
@ -369,11 +374,11 @@ class Validate
* will return the address for optional dns validation
* @param array $options email() options
*
* @return boolean true if valid email, false if not
* @return bool true if valid email, false if not
*
* @access private
*/
function __emailRFC822(&$email, &$options)
private function __emailRFC822(string &$email, array &$options): bool
{
static $address = null;
static $uncomment = null;
@ -442,12 +447,18 @@ class Validate
*
* @return bool True if validating succeeds
*/
function _fullTLDValidation($email, $options)
public function _fullTLDValidation(string $email, array $options): bool
{
$validate = array();
if(!empty($options["VALIDATE_ITLD_EMAILS"])) array_push($validate, 'itld');
if(!empty($options["VALIDATE_GTLD_EMAILS"])) array_push($validate, 'gtld');
if(!empty($options["VALIDATE_CCTLD_EMAILS"])) array_push($validate, 'cctld');
$validate = [];
if (!empty($options["VALIDATE_ITLD_EMAILS"])) {
array_push($validate, 'itld');
}
if (!empty($options["VALIDATE_GTLD_EMAILS"])) {
array_push($validate, 'gtld');
}
if (!empty($options["VALIDATE_CCTLD_EMAILS"])) {
array_push($validate, 'cctld');
}
if (count($validate) === 0) {
array_push($validate, 'itld', 'gtld', 'cctld');
@ -455,7 +466,7 @@ class Validate
$self = new Validate;
$toValidate = array();
$toValidate = [];
foreach ($validate as $valid) {
$tmpVar = '_' . (string)$valid;
@ -479,12 +490,12 @@ class Validate
*
* @access public
*
* @return true or false (Depending on if it validates or if it does not)
* @return bool true or false (Depending on if it validates or if it does not)
*/
function executeFullEmailValidation($email, $arrayOfTLDs)
public function executeFullEmailValidation(string $email, array $arrayOfTLDs): bool
{
$emailEnding = explode('.', $email);
$emailEnding = $emailEnding[count($emailEnding)-1];
$emailEnding = $emailEnding[count($emailEnding) - 1];
foreach ($arrayOfTLDs as $validator => $keys) {
if (in_array($emailEnding, $keys)) {
return true;
@ -503,20 +514,21 @@ class Validate
* 'use_rfc822' boolean Apply the full RFC822 grammar
*
* Ex.
* $options = array(
* $options = [
* 'check_domain' => 'true',
* 'fullTLDValidation' => 'true',
* 'use_rfc822' => 'true',
* 'VALIDATE_GTLD_EMAILS' => 'true',
* 'VALIDATE_CCTLD_EMAILS' => 'true',
* 'VALIDATE_ITLD_EMAILS' => 'true',
* );
* ];
*
* @return boolean true if valid email, false if not
* @return bool true if valid email, false if not
*
* @access public
* @throws Exception
*/
function email($email, $options = null)
public function email(string $email, array $options = null): bool
{
$check_domain = false;
$use_rfc822 = false;
@ -532,8 +544,8 @@ class Validate
*/
$hasIDNA = false;
if (Validate::_includePathFileExists('Net/IDNA.php')) {
include_once('Net/IDNA.php');
if (Validate::_includePathFileExists('Net/IDNA2.php')) {
include_once('Net/IDNA2.php');
$hasIDNA = true;
}
@ -546,7 +558,7 @@ class Validate
// it's an idn domain name.
$chars = count_chars($domain, 1);
if (!empty($chars) && max(array_keys($chars)) > 127) {
$idna =& Net_IDNA::singleton();
$idna =& Net_IDNA2::singleton();
$domain = $idna->encode($domain);
}
@ -580,7 +592,7 @@ class Validate
$&xi';
//checks if exists the domain (MX or A)
if ($use_rfc822? Validate::__emailRFC822($email, $options) :
if ($use_rfc822 ? Validate::__emailRFC822($email, $options) :
preg_match($regex, $email)) {
if ($check_domain && function_exists('checkdnsrr')) {
$domain = preg_replace('/[^-a-z.0-9]/i', '', array_pop(explode('@', $email)));
@ -598,17 +610,17 @@ class Validate
* Validate a string using the given format 'format'
*
* @param string $string String to validate
* @param array $options Options array where:
* @param array|string $options Options array where:
* 'format' is the format of the string
* Ex:VALIDATE_NUM . VALIDATE_ALPHA (see constants)
* 'min_length' minimum length
* 'max_length' maximum length
*
* @return boolean true if valid string, false if not
* @return bool true if valid string, false if not
*
* @access public
*/
function string($string, $options)
public function string(string $string, $options): bool
{
$format = null;
$min_length = 0;
@ -639,7 +651,7 @@ class Validate
* only http, https, ftp and such you have to pass it in the allowed_schemes
* option, like this:
* <code>
* $options = array('allowed_schemes' => array('http', 'https', 'ftp'))
* $options = ['allowed_schemes' => ['http', 'https', 'ftp']]
* var_dump(Validate::uri('http://www.example.org', $options));
* </code>
*
@ -654,7 +666,7 @@ class Validate
* if not urlencoded, refer to the option "strict'"
*
* @param string $url URI to validate
* @param array $options Options used by the validation method.
* @param array|null $options Options used by the validation method.
* key => type
* 'domain_check' => boolean
* Whether to check the DNS entry or not
@ -666,11 +678,12 @@ class Validate
* default: ';/?:@$,'
* empty: accept all rfc2396 foreseen chars
*
* @return boolean true if valid uri, false if not
* @return bool true if valid uri, false if not
*
* @access public
* @throws Exception
*/
function uri($url, $options = null)
public function uri(string $url, $options = null): bool
{
$strict = ';/?:@$,';
$domain_check = false;
@ -696,9 +709,12 @@ class Validate
((?:/(?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'():@\&=+$,;])*)*/?)? # 6. path
(?:\?([^#]*))? # 7. query
(?:\#((?:%[0-9a-f]{2}|[-a-z0-9_.!~*\'();/?:@\&=+$,])*))? # 8. fragment
$&xi', $url, $matches)) {
$&xi',
$url,
$matches
)) {
$scheme = isset($matches[1]) ? $matches[1] : '';
$authority = isset($matches[3]) ? $matches[3] : '' ;
$authority = isset($matches[3]) ? $matches[3] : '';
if (is_array($allowed_schemes) &&
!in_array($scheme, $allowed_schemes)
) {
@ -736,25 +752,23 @@ class Validate
* 'format' The format of the date (%d-%m-%Y)
* or rfc822_compliant
* 'min' The date has to be greater
* than this array($day, $month, $year)
* than this [$day, $month, $year]
* or PEAR::Date object
* 'max' The date has to be smaller than
* this array($day, $month, $year)
* this [$day, $month, $year]
* or PEAR::Date object
*
* @return boolean true if valid date/time, false if not
* @return bool true if valid date/time, false if not
*
* @access public
*/
function date($date, $options)
public function date(string $date, array $options): bool
{
$max = false;
$min = false;
$format = '';
if (is_array($options)) {
extract($options);
}
if (strtolower($format) == 'rfc822_compliant') {
$preg = '&^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),) \s+
@ -769,10 +783,10 @@ class Validate
}
$year = (int)$matches[4];
$months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$month = array_keys($months, $matches[3]);
$month = (int)$month[0]+1;
$month = (int)$month[0] + 1;
$day = (int)$matches[2];
$weekday = $matches[1];
$hour = (int)$matches[6];
@ -780,7 +794,7 @@ class Validate
isset($matches[9]) ? $second = (int)$matches[9] : $second = 0;
if ((strlen($year) != 4) ||
($day > 31 || $day < 1)||
($day > 31 || $day < 1) ||
($hour > 23) ||
($minute > 59) ||
($second > 59)) {
@ -819,7 +833,7 @@ class Validate
case 'y':
if ($next == 'Y') {
$year = Validate::_substr($date, 4);
$year = (int)$year?$year:'';
$year = (int)$year ? $year : '';
} else {
$year = (int)(substr(date('Y'), 0, 2) .
Validate::_substr($date, 2));
@ -858,7 +872,7 @@ class Validate
}
break;
default:
trigger_error("Not supported char `$next' after % in offset " . ($i+2), E_USER_WARNING);
trigger_error("Not supported char `$next' after % in offset " . ($i + 2), E_USER_WARNING);
}
$i++;
} else {
@ -874,7 +888,7 @@ class Validate
return false;
}
if (isset($day) && isset($month) && isset($year)) {
if (isset($day) && isset($month) && isset($year) && isset($weekday)) {
if (!checkdate($month, $day, $year)) {
return false;
}
@ -888,13 +902,25 @@ class Validate
if ($min) {
include_once 'Date/Calc.php';
if (is_a($min, 'Date') &&
(Date_Calc::compareDates($day, $month, $year,
$min->getDay(), $min->getMonth(), $min->getYear()) < 0)
(Date_Calc::compareDates(
$day,
$month,
$year,
$min->getDay(),
$min->getMonth(),
$min->getYear()
) < 0)
) {
return false;
} elseif (is_array($min) &&
(Date_Calc::compareDates($day, $month, $year,
$min[0], $min[1], $min[2]) < 0)
(Date_Calc::compareDates(
$day,
$month,
$year,
$min[0],
$min[1],
$min[2]
) < 0)
) {
return false;
}
@ -903,13 +929,25 @@ class Validate
if ($max) {
include_once 'Date/Calc.php';
if (is_a($max, 'Date') &&
(Date_Calc::compareDates($day, $month, $year,
$max->getDay(), $max->getMonth(), $max->getYear()) > 0)
(Date_Calc::compareDates(
$day,
$month,
$year,
$max->getDay(),
$max->getMonth(),
$max->getYear()
) > 0)
) {
return false;
} elseif (is_array($max) &&
(Date_Calc::compareDates($day, $month, $year,
$max[0], $max[1], $max[2]) > 0)
(Date_Calc::compareDates(
$day,
$month,
$year,
$max[0],
$max[1],
$max[2]
) > 0)
) {
return false;
}
@ -924,14 +962,14 @@ class Validate
*
* @param string &$date Date
* @param string $num Length
* @param string $opt Unknown
* @param string|false $opt Unknown
*
* @access private
* @return string
*/
function _substr(&$date, $num, $opt = false)
private function _substr(string &$date, string $num, $opt = false): string
{
if ($opt && strlen($date) >= $opt && preg_match('/^[0-9]{'.$opt.'}/', $date, $m)) {
if ($opt && strlen($date) >= $opt && preg_match('/^[0-9]{' . $opt . '}/', $date, $m)) {
$ret = $m[0];
} else {
$ret = substr($date, 0, $num);
@ -940,7 +978,7 @@ class Validate
return $ret;
}
function _modf($val, $div)
public function _modf($val, $div)
{
if (function_exists('bcmod')) {
return bcmod($val, $div);
@ -962,7 +1000,7 @@ class Validate
*
* @return int returns product of number digits with weights
*/
function _multWeights($number, &$weights)
public function _multWeights(string $number, array &$weights): int
{
if (!is_array($weights)) {
return -1;
@ -993,7 +1031,7 @@ class Validate
*
* @return int -1 calculated control number is returned
*/
function _getControlNumber($number, &$weights, $modulo = 10, $subtract = 0, $allow_high = false)
public function _getControlNumber(string $number, array &$weights, int $modulo = 10, int $subtract = 0, bool $allow_high = false): int
{
// calc sum
$sum = Validate::_multWeights($number, $weights);
@ -1023,7 +1061,7 @@ class Validate
*
* @return bool true if valid, false if not
*/
function _checkControlNumber($number, &$weights, $modulo = 10, $subtract = 0)
public function _checkControlNumber(string $number, array &$weights, int $modulo = 10, int $subtract = 0): bool
{
if (strlen($number) < count($weights)) {
return false;
@ -1048,22 +1086,22 @@ class Validate
* assoc array in the form $var_name => $value.
* Can be used on any of Validate subpackages
*
* @param array $data Ex: array('name' => 'toto', 'email' => 'toto@thing.info');
* @param array $data Ex: ['name' => 'toto', 'email' => 'toto@thing.info'];
* @param array $val_type Contains the validation type and all parameters used in.
* 'val_type' is not optional
* others validations properties must have the same name as the function
* parameters.
* Ex: array('toto'=>array('type'=>'string','format'='toto@thing.info','min_length'=>5));
* @param boolean $remove if set, the elements not listed in data will be removed
* Ex: ['toto' => ['type'=>'string','format'='toto@thing.info','min_length'=>5]];
* @param bool $remove if set, the elements not listed in data will be removed
*
* @return array value name => true|false the value name comes from the data key
*
* @access public
*/
function multiple(&$data, &$val_type, $remove = false)
public function multiple(array &$data, array &$val_type, bool $remove = false): array
{
$keys = array_keys($data);
$valid = array();
$valid = [];
foreach ($keys as $var_name) {
if (!isset($val_type[$var_name])) {
@ -1084,7 +1122,7 @@ class Validate
if (sizeof($opt) == 1 && is_array(reset($opt))) {
$opt = array_pop($opt);
}
$valid[$var_name] = call_user_func(array('Validate', $method), $val2check, $opt);
$valid[$var_name] = call_user_func(['Validate', $method], $val2check, $opt);
/**
* external validation method in the form:
@ -1108,19 +1146,26 @@ class Validate
if (!$ce ||
!in_array($method, get_class_methods($class))
) {
trigger_error("Invalid validation type $class::$method",
E_USER_WARNING);
trigger_error(
"Invalid validation type $class::$method",
E_USER_WARNING
);
continue;
}
unset($opt['type']);
if (sizeof($opt) == 1) {
$opt = array_pop($opt);
}
$valid[$var_name] = call_user_func(array($class, $method),
$data[$var_name], $opt);
$valid[$var_name] = call_user_func(
array($class, $method),
$data[$var_name],
$opt
);
} else {
trigger_error("Invalid validation type {$opt['type']}",
E_USER_WARNING);
trigger_error(
"Invalid validation type {$opt['type']}",
E_USER_WARNING
);
}
}
return $valid;
@ -1135,15 +1180,18 @@ class Validate
*
* @return bool true if file exists
*/
function _includePathFileExists($filename)
private function _includePathFileExists(string $filename): bool
{
$paths = explode(":", ini_get("include_path"));
$result = false;
while ((!($result)) && (list($key,$val) = each($paths))) {
foreach ($paths as $val) {
$result = file_exists($val . "/" . $filename);
if ($result) {
break;
}
}
return $result;
}
}

118
extlib/buildPackageXML.php Normal file
View File

@ -0,0 +1,118 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id$
require_once 'PEAR/PackageFileManager2.php';
require_once 'PEAR/PackageFileManager/Git.php';
$pkg = new PEAR_PackageFileManager2;
$options = array(
'simpleoutput' => true,
'baseinstalldir' => '/',
'packagefile' => 'package.xml',
'packagedirectory' => dirname(__FILE__),
'filelistgenerator' => 'Git',
'dir_roles' => array(
'tests' => 'test',
'docs' => 'doc',
'data' => 'data'
),
'ignore' => array(
'package.xml',
'package2.xml',
'*.tgz',
basename(__FILE__)
)
);
$pkg->setOptions($options);
$desc = <<<EOT
Generic classes for representation and manipulation of
dates, times and time zones without the need of timestamps,
which is a huge limitation for PHP programs. Includes time zone data,
time zone conversions and many date/time conversions.
It does not rely on 32-bit system date stamps, so
you can display calendars and compare dates that date
pre 1970 and post 2038.
EOT;
$notes = <<<EOT
QA release.
Users are strongly encouraged to adopt to inbuilt DateTime functionality.
Bug #17730 Patch: Avoid ereg, using preg_match
Doc Bug #15029 large Date_Span's cannot be created
Bug #14929 Timezone summertime
Bug #14856 America/Moncton longname and dstlongname missing
Bug #14084 TZ variable being set wrecks global config
Bug #13615 America/Toronto time-zone is missing longname and dstlongname
Bug #13545 Date_Span::set() doesn't work when passed an int and format
Req #13488 Please rename Methods format2 and format3
EOT;
$summary = <<<EOT
Generic date/time handling class for PEAR
EOT;
// Some hard-coded stuffs.
$pkg->setPackage('Date');
$pkg->setSummary($summary);
$pkg->setDescription($desc);
$pkg->setChannel('pear.php.net');
$pkg->setAPIVersion('1.5.0');
$pkg->setReleaseVersion('1.5.0a2');
$pkg->setReleaseStability('alpha');
$pkg->setAPIStability('alpha');
$pkg->setNotes($notes);
$pkg->setPackageType('php');
$pkg->setLicense('BSD License',
'http://www.opensource.org/licenses/bsd-license.php');
// Add maintainers.
$pkg->addMaintainer('lead', 'baba', 'Baba Buehler', 'baba@babaz.com', 'no');
$pkg->addMaintainer('lead', 'pajoye', 'Pierre-Alain Joye', 'pajoye@php.net', 'no');
$pkg->addMaintainer('lead', 'mohrt', 'Monte Ohrt', 'mohrt@php.net', 'no');
$pkg->addMaintainer('lead', 'firman', 'Firman Wandayandi', 'firman@php.net');
$pkg->addMaintainer('lead', 'c01234', 'C.A. Woodcock', 'c01234@netcomuk.co.uk');
$pkg->addMaintainer('developer', 'alan_k', 'Alan Knowles', 'alan@akbkhome.com');
$pkg->addMaintainer('helper', 'scar', 'Leonardo Dutra', 'scar@php.net');
// Core dependencies.
$pkg->setPhpDep('4.3');
$pkg->setPearinstallerDep('1.4.0');
//$pkg->addDependency("Numbers_Words", "0.15.0", "eq", "pkg", true);
//$pkg->detectDependencies();
// Add some replacements.
$pkg->addGlobalReplacement('package-info', '@package_version@', 'version');
// Generate file contents.
$pkg->generateContents();
// Writes a package.xml.
if (isset($_GET['make']) || (isset($_SERVER['argv']) && @$_SERVER['argv'][1] == 'make')) {
$e = $pkg->writePackageFile();
// Some errors occurs.
if (PEAR::isError($e)) {
throw new Exception('Unable to write package file. Got message: ' .
$e->getMessage());
}
} else {
$pkg->debugPackageFile();
}
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -32,7 +32,7 @@ defined('GNUSOCIAL') || die();
define('GNUSOCIAL_ENGINE', 'GNU social');
define('GNUSOCIAL_ENGINE_URL', 'https://www.gnu.org/software/social/');
define('GNUSOCIAL_BASE_VERSION', '1.26.0');
define('GNUSOCIAL_BASE_VERSION', '1.26.1');
define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);

View File

@ -1978,8 +1978,8 @@ function common_valid_domain($domain)
}
try {
require_once "Net/IDNA.php";
$idn = Net_IDNA::getInstance();
require_once "Net/IDNA2.php";
$idn = Net_IDNA2::getInstance();
$domain = $idn->encode($domain);
} catch (Exception $e) {
return false;