[CORE] Fixed some small issues with PEAR

This commit is contained in:
Diogo Cordeiro 2019-07-15 01:40:09 +01:00
parent d9e7862cea
commit 7d262ad50b
76 changed files with 1891 additions and 58027 deletions

View File

@ -7,6 +7,9 @@ plugin_mo = $(patsubst %.po,%.mo,$(wildcard plugins/*/locale/*/LC_MESSAGES/*.po)
translations : $(core_mo) $(plugin_mo)
upgrade :
php scripts/upgrade.php
clean :
rm -f $(core_mo) $(plugin_mo)

View File

@ -25,6 +25,7 @@
"michelf/php-markdown": "^1.8.0",
"openid/php-openid": "^2.3",
"paragonie/constant_time_encoding": "^1.0.4",
"pear/console_getopt": "^1.4",
"phpseclib/phpseclib": "dev-master#f815e43077da67d3dd5b4d18a45753f5b79c1ab9",
"stomp-php/stomp-php": "^4.5.1"
},

49
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "443e1729de86d54a2d4e4707b15ad41d",
"content-hash": "f84a3a1654cf40103976cea8b2365b8c",
"packages": [
{
"name": "apereo/phpcas",
@ -682,6 +682,53 @@
],
"time": "2019-01-03T20:59:08+00:00"
},
{
"name": "pear/console_getopt",
"version": "v1.4.2",
"source": {
"type": "git",
"url": "https://github.com/pear/Console_Getopt.git",
"reference": "6c77aeb625b32bd752e89ee17972d103588b90c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Console_Getopt/zipball/6c77aeb625b32bd752e89ee17972d103588b90c0",
"reference": "6c77aeb625b32bd752e89ee17972d103588b90c0",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
"Console": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Greg Beaver",
"email": "cellog@php.net",
"role": "Helper"
},
{
"name": "Andrei Zmievski",
"email": "andrei@php.net",
"role": "Lead"
},
{
"name": "Stig Bakken",
"email": "stig@php.net",
"role": "Developer"
}
],
"description": "More info available on: http://pear.php.net/package/Console_Getopt",
"time": "2019-02-06T16:52:33+00:00"
},
{
"name": "phpseclib/phpseclib",
"version": "dev-master",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,242 +0,0 @@
<?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:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +0,0 @@
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.

View File

@ -1,12 +0,0 @@
$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

@ -1,137 +0,0 @@
<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

@ -1,225 +0,0 @@
<?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

@ -1,453 +0,0 @@
<?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

@ -1,65 +0,0 @@
--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

@ -1,32 +0,0 @@
--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

@ -1,13 +0,0 @@
--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

@ -1,22 +0,0 @@
--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

@ -1,17 +0,0 @@
--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

@ -1,104 +0,0 @@
--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

@ -1,22 +0,0 @@
--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

@ -1,104 +0,0 @@
--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

@ -1,34 +0,0 @@
--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

@ -1,52 +0,0 @@
--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

@ -1,52 +0,0 @@
--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

@ -1,500 +0,0 @@
--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

@ -1,500 +0,0 @@
--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

@ -1,21 +0,0 @@
--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

@ -1,88 +0,0 @@
--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

@ -1,22 +0,0 @@
--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

@ -1,26 +0,0 @@
--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

@ -1,99 +0,0 @@
--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

@ -1,27 +0,0 @@
--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

@ -1,27 +0,0 @@
--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

View File

@ -1,408 +0,0 @@
<?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

@ -1,447 +0,0 @@
<?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

@ -1,447 +0,0 @@
<?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

@ -1,447 +0,0 @@
<?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

@ -1,50 +0,0 @@
<?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

@ -1,68 +0,0 @@
<?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

@ -1,526 +0,0 @@
<?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

@ -1,231 +0,0 @@
<?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

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?php
/**
* Error Stack Implementation
*
*
* This is an incredibly simple implementation of a very complex error handling
* facility. It contains the ability
* to track multiple errors from multiple packages simultaneously. In addition,
@ -9,10 +9,10 @@
* information such as the exact file, line number, class and function that
* generated the error, and if necessary, it can raise a traditional PEAR_Error.
* It has built-in support for PEAR::Log, to log errors as they occur
*
*
* Since version 0.2alpha, it is also possible to selectively ignore errors,
* through the use of an error callback, see {@link pushCallback()}
*
*
* Since version 0.3alpha, it is possible to specify the exception class
* returned from {@link push()}
*
@ -28,7 +28,7 @@
/**
* Singleton storage
*
*
* Format:
* <pre>
* array(
@ -44,7 +44,7 @@ $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
/**
* Global error callback (default)
*
*
* This is only used if set to non-false. * is the default callback for
* all packages, whereas specific packages may set a default callback
* for all instances, regardless of whether they are a singleton or not.
@ -60,7 +60,7 @@ $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'] = array(
/**
* Global Log object (default)
*
*
* This is only used if set to non-false. Use to set a default log object for
* all stacks, regardless of instantiation order or location
* @see PEAR_ErrorStack::setDefaultLogger()
@ -71,7 +71,7 @@ $GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = false;
/**
* Global Overriding Callback
*
*
* This callback will override any error callbacks that specific loggers have set.
* Use with EXTREME caution
* @see PEAR_ErrorStack::staticPushCallback()
@ -165,14 +165,14 @@ class PEAR_ErrorStack {
* @access protected
*/
var $_package;
/**
* Determines whether a PEAR_Error is thrown upon every error addition
* @var boolean
* @access private
*/
var $_compat = false;
/**
* If set to a valid callback, this will be used to generate the error
* message from the error code, otherwise the message passed in will be
@ -181,7 +181,7 @@ class PEAR_ErrorStack {
* @access private
*/
var $_msgCallback = false;
/**
* If set to a valid callback, this will be used to generate the error
* context for an error. For PHP-related errors, this will be a file
@ -236,10 +236,10 @@ class PEAR_ErrorStack {
$this->setContextCallback($contextCallback);
$this->_compat = $throwPEAR_Error;
}
/**
* Return a single error stack for this package.
*
*
* Note that all parameters are ignored if the stack for package $package
* has already been instantiated
* @param string $package name of the package this error stack represents
@ -275,7 +275,7 @@ class PEAR_ErrorStack {
/**
* Internal error handler for PEAR_ErrorStack class
*
*
* Dies if the error is an exception (and would have died anyway)
* @access private
*/
@ -292,10 +292,10 @@ class PEAR_ErrorStack {
die($message);
}
}
/**
* Set up a PEAR::Log object for all error stacks that don't have one
* @param Log $log
* @param Log $log
*/
public static function setDefaultLogger(&$log)
{
@ -305,10 +305,10 @@ class PEAR_ErrorStack {
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log;
}
}
/**
* Set up a PEAR::Log object for this error stack
* @param Log $log
* @param Log $log
*/
function setLogger(&$log)
{
@ -318,10 +318,10 @@ class PEAR_ErrorStack {
$this->_logger = &$log;
}
}
/**
* Set an error code => error message mapping callback
*
*
* This method sets the callback that can be used to generate error
* messages for any instance
* @param array|string Callback function/method
@ -336,10 +336,10 @@ class PEAR_ErrorStack {
}
}
}
/**
* Get an error code => error message mapping callback
*
*
* This method returns the current callback that can be used to generate error
* messages
* @return array|string|false Callback function/method or false if none
@ -348,10 +348,10 @@ class PEAR_ErrorStack {
{
return $this->_msgCallback;
}
/**
* Sets a default callback to be used by all error stacks
*
*
* This method sets the callback that can be used to generate error
* messages for a singleton
* @param array|string Callback function/method
@ -365,16 +365,14 @@ class PEAR_ErrorStack {
$package = $package ? $package : '*';
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_CALLBACK'][$package] = $callback;
}
/**
* Set a callback that generates context information (location of error) for an error stack
*
*
* This method sets the callback that can be used to generate context
* information for an error. Passing in NULL will disable context generation
* and remove the expensive call to debug_backtrace()
* @param array|string|null Callback function/method
* @return bool
* @return array|bool|callable|false|string
*/
function setContextCallback($contextCallback)
{
@ -382,23 +380,22 @@ class PEAR_ErrorStack {
return $this->_contextCallback = false;
}
if (!$contextCallback) {
$this->_contextCallback = [&$this, 'getFileLine'];
$this->_contextCallback = array(&$this, 'getFileLine');
} else {
if (is_callable($contextCallback)) {
$this->_contextCallback = $contextCallback;
}
}
return $this->_contextCallback;
}
/**
* Set an error Callback
* If set to a valid callback, this will be called every time an error
* is pushed onto the stack. The return value will be used to determine
* whether to allow an error to be pushed or logged.
*
*
* The return value must be one of the ERRORSTACK_* constants.
*
*
* This functionality can be used to emulate PEAR's pushErrorHandling, and
* the PEAR_ERROR_CALLBACK mode, without affecting the integrity of
* the error stack or logging
@ -410,7 +407,7 @@ class PEAR_ErrorStack {
{
array_push($this->_errorCallback, $cb);
}
/**
* Remove a callback from the error callback stack
* @see pushCallback()
@ -423,7 +420,7 @@ class PEAR_ErrorStack {
}
return array_pop($this->_errorCallback);
}
/**
* Set a temporary overriding error callback for every package error stack
*
@ -437,7 +434,7 @@ class PEAR_ErrorStack {
{
array_push($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'], $cb);
}
/**
* Remove a temporary overriding error callback
* @see staticPushCallback()
@ -451,15 +448,15 @@ class PEAR_ErrorStack {
}
return $ret;
}
/**
* Add an error to the stack
*
*
* If the message generator exists, it is called with 2 parameters.
* - the current Error Stack object
* - an array that is in the same format as an error. Available indices
* are 'code', 'package', 'time', 'params', 'level', and 'context'
*
*
* Next, if the error should contain context information, this is
* handled by the context grabbing method.
* Finally, the error is pushed onto the proper error stack
@ -477,7 +474,7 @@ class PEAR_ErrorStack {
* @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also
* thrown. If a PEAR_Error is returned, the userinfo
* property is set to the following array:
*
*
* <code>
* array(
* 'code' => $code,
@ -490,7 +487,7 @@ class PEAR_ErrorStack {
* //['repackage' => $err] repackaged error array/Exception class
* );
* </code>
*
*
* Normally, the previous array is returned.
*/
function push($code, $level = 'error', $params = array(), $msg = false,
@ -504,19 +501,19 @@ class PEAR_ErrorStack {
}
$context = call_user_func($this->_contextCallback, $code, $params, $backtrace);
}
// save error
$time = explode(' ', microtime());
$time = $time[1] + $time[0];
$err = array(
'code' => $code,
'params' => $params,
'package' => $this->_package,
'level' => $level,
'time' => $time,
'context' => $context,
'message' => $msg,
);
'code' => $code,
'params' => $params,
'package' => $this->_package,
'level' => $level,
'time' => $time,
'context' => $context,
'message' => $msg,
);
if ($repackage) {
$err['repackage'] = $repackage;
@ -525,9 +522,9 @@ class PEAR_ErrorStack {
// set up the error message, if necessary
if ($this->_msgCallback) {
$msg = call_user_func_array($this->_msgCallback,
array(&$this, $err));
array(&$this, $err));
$err['message'] = $msg;
}
}
$push = $log = true;
$die = false;
// try the overriding callback first
@ -549,18 +546,18 @@ class PEAR_ErrorStack {
}
if (is_callable($callback)) {
switch(call_user_func($callback, $err)){
case PEAR_ERRORSTACK_IGNORE:
return $err;
break;
case PEAR_ERRORSTACK_PUSH:
$log = false;
break;
case PEAR_ERRORSTACK_LOG:
$push = false;
break;
case PEAR_ERRORSTACK_DIE:
$die = true;
break;
case PEAR_ERRORSTACK_IGNORE:
return $err;
break;
case PEAR_ERRORSTACK_PUSH:
$log = false;
break;
case PEAR_ERRORSTACK_LOG:
$push = false;
break;
case PEAR_ERRORSTACK_DIE:
$die = true;
break;
// anything else returned has the same effect as pushandlog
}
}
@ -584,10 +581,10 @@ class PEAR_ErrorStack {
}
return $err;
}
/**
* Static version of {@link push()}
*
*
* @param string $package Package name this error belongs to
* @param int $code Package-specific error code
* @param string $level Error level. This is NOT spell-checked
@ -617,7 +614,7 @@ class PEAR_ErrorStack {
}
return $s->push($code, $level, $params, $msg, $repackage, $backtrace);
}
/**
* Log an error using PEAR::Log
* @param array $err Error array
@ -652,10 +649,10 @@ class PEAR_ErrorStack {
}
}
/**
* Pop an error off of the error stack
*
*
* @return false|array
* @since 0.4alpha it is no longer possible to specify a specific error
* level to return - the last error pushed will be returned, instead
@ -687,12 +684,11 @@ class PEAR_ErrorStack {
}
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package]->pop();
}
return false;
}
/**
* Determine whether there are any errors on the stack
* @param string|array|bool $level name. Use to determine if any errors
* @param string|array Level name. Use to determine if any errors
* of level (string), or levels (array) have been pushed
* @return boolean
*/
@ -703,10 +699,10 @@ class PEAR_ErrorStack {
}
return count($this->_errors);
}
/**
* Retrieve all errors since last purge
*
*
* @param boolean set in order to empty the error stack
* @param string level name, to return only errors of a particular severity
* @return array
@ -740,7 +736,7 @@ class PEAR_ErrorStack {
$this->_errorsByLevel = array();
return $ret;
}
/**
* Determine whether there are any errors on a single error stack, or on any error stack
*
@ -765,7 +761,7 @@ class PEAR_ErrorStack {
}
return false;
}
/**
* Get a list of all errors since last purge, organized by package
* @since PEAR 1.4.0dev BC break! $level is now in the place $merge used to be
@ -775,7 +771,7 @@ class PEAR_ErrorStack {
* @param array $sortfunc Function used to sort a merged array - default
* sorts by time, and should be good for most cases
*
* @return array
* @return array
*/
public static function staticGetErrors(
$purge = false, $level = false, $merge = false,
@ -800,7 +796,7 @@ class PEAR_ErrorStack {
}
return $ret;
}
/**
* Error sorting function, sorts by time
* @access private
@ -840,8 +836,8 @@ class PEAR_ErrorStack {
$functionframe = 0;
} else {
while (isset($backtrace[$functionframe]['function']) &&
$backtrace[$functionframe]['function'] == 'eval' &&
isset($backtrace[$functionframe + 1])) {
$backtrace[$functionframe]['function'] == 'eval' &&
isset($backtrace[$functionframe + 1])) {
$functionframe++;
}
}
@ -852,11 +848,11 @@ class PEAR_ErrorStack {
$funcbacktrace = $backtrace[$functionframe];
$filebacktrace = $backtrace[$frame];
$ret = array('file' => $filebacktrace['file'],
'line' => $filebacktrace['line']);
'line' => $filebacktrace['line']);
// rearrange for eval'd code or create function errors
if (strpos($filebacktrace['file'], '(') &&
preg_match(';^(.*?)\((\d+)\) : (.*?)\\z;', $filebacktrace['file'],
$matches)) {
if (strpos($filebacktrace['file'], '(') &&
preg_match(';^(.*?)\((\d+)\) : (.*?)\\z;', $filebacktrace['file'],
$matches)) {
$ret['file'] = $matches[1];
$ret['line'] = $matches[2] + 0;
}
@ -876,26 +872,26 @@ class PEAR_ErrorStack {
}
return false;
}
/**
* Standard error message generation callback
*
*
* This method may also be called by a custom error message generator
* to fill in template values from the params array, simply
* set the third parameter to the error message template string to use
*
*
* The special variable %__msg% is reserved: use it only to specify
* where a message passed in by the user should be placed in the template,
* like so:
*
*
* Error message: %msg% - internal error
*
*
* If the message passed like so:
*
*
* <code>
* $stack->push(ERROR_CODE, 'error', array(), 'server error 500');
* </code>
*
*
* The returned error message will be "Error message: server error 500 -
* internal error"
* @param PEAR_ErrorStack
@ -933,7 +929,7 @@ class PEAR_ErrorStack {
}
return $mainmsg;
}
/**
* Standard Error Message Template generator from code
* @return string
@ -945,42 +941,39 @@ class PEAR_ErrorStack {
}
return $this->_errorMsgs[$code];
}
/**
* Set the Error Message Template array
*
*
* The array format must be:
* <pre>
* array(error code => 'message template',...)
* </pre>
*
*
* Error message parameters passed into {@link push()} will be used as input
* for the error message. If the template is 'message %foo% was %bar%', and the
* parameters are array('foo' => 'one', 'bar' => 'six'), the error message returned will
* be 'message one was six'
*
* Returns string via property
* @param $template
* @return null
* @return string
*/
function setErrorMessageTemplate($template)
{
$this->_errorMsgs = $template;
return null;
}
/**
* emulate PEAR::raiseError()
*
*
* @return PEAR_Error
*/
function raiseError()
{
require_once '../PEAR.php';
require_once 'PEAR.php';
$args = func_get_args();
return call_user_func_array(array('PEAR', 'raiseError'), $args);
}
}
$stack = &PEAR_ErrorStack::singleton('PEAR_ErrorStack');
$stack->pushCallback(array('PEAR_ErrorStack', '_handleError'));
$stack->pushCallback(array('PEAR_ErrorStack', '_handleError'));
?>

View File

@ -13,7 +13,6 @@
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Exception.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
@ -89,7 +88,7 @@
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @version Release: @package_version@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.3
*
@ -99,9 +98,9 @@ class PEAR_Exception extends Exception
const OBSERVER_PRINT = -2;
const OBSERVER_TRIGGER = -4;
const OBSERVER_DIE = -8;
protected $cause;
private static $_observers = array();
private static $_uniqueid = 0;
protected $cause;
private $_trace;
/**
@ -117,7 +116,6 @@ class PEAR_Exception extends Exception
* @param string exception message
* @param int|Exception|PEAR_Error|array|null exception cause
* @param int|null exception code or null
* @throws PEAR_Exception
*/
public function __construct($message, $p2 = null, $p3 = null)
{
@ -146,6 +144,32 @@ class PEAR_Exception extends Exception
$this->signal();
}
/**
* @param mixed $callback - A valid php callback, see php func is_callable()
* - A PEAR_Exception::OBSERVER_* constant
* - An array(const PEAR_Exception::OBSERVER_*,
* mixed $options)
* @param string $label The name of the observer. Use this if you want
* to remove it later with removeObserver()
*/
public static function addObserver($callback, $label = 'default')
{
self::$_observers[$label] = $callback;
}
public static function removeObserver($label = 'default')
{
unset(self::$_observers[$label]);
}
/**
* @return int unique identifier for an observer
*/
public static function getUniqueId()
{
return self::$_uniqueid++;
}
private function signal()
{
foreach (self::$_observers as $func) {
@ -173,32 +197,6 @@ class PEAR_Exception extends Exception
}
}
/**
* @param mixed $callback - A valid php callback, see php func is_callable()
* - A PEAR_Exception::OBSERVER_* constant
* - An array(const PEAR_Exception::OBSERVER_*,
* mixed $options)
* @param string $label The name of the observer. Use this if you want
* to remove it later with removeObserver()
*/
public static function addObserver($callback, $label = 'default')
{
self::$_observers[$label] = $callback;
}
public static function removeObserver($label = 'default')
{
unset(self::$_observers[$label]);
}
/**
* @return int unique identifier for an observer
*/
public static function getUniqueId()
{
return self::$_uniqueid++;
}
/**
* Return specific error information that can be used for more detailed
* error messages or translation.
@ -228,6 +226,79 @@ class PEAR_Exception extends Exception
return $this->cause;
}
/**
* Function must be public to call on caused exceptions
* @param array
*/
public function getCauseMessage(&$causes)
{
$trace = $this->getTraceSafe();
$cause = array('class' => get_class($this),
'message' => $this->message,
'file' => 'unknown',
'line' => 'unknown');
if (isset($trace[0])) {
if (isset($trace[0]['file'])) {
$cause['file'] = $trace[0]['file'];
$cause['line'] = $trace[0]['line'];
}
}
$causes[] = $cause;
if ($this->cause instanceof PEAR_Exception) {
$this->cause->getCauseMessage($causes);
} elseif ($this->cause instanceof Exception) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage(),
'file' => $this->cause->getFile(),
'line' => $this->cause->getLine());
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($this->cause)) {
foreach ($this->cause as $cause) {
if ($cause instanceof PEAR_Exception) {
$cause->getCauseMessage($causes);
} elseif ($cause instanceof Exception) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage(),
'file' => $cause->getFile(),
'line' => $cause->getLine());
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($cause) && isset($cause['message'])) {
// PEAR_ErrorStack warning
$causes[] = array(
'class' => $cause['package'],
'message' => $cause['message'],
'file' => isset($cause['context']['file']) ?
$cause['context']['file'] :
'unknown',
'line' => isset($cause['context']['line']) ?
$cause['context']['line'] :
'unknown',
);
}
}
}
}
public function getTraceSafe()
{
if (!isset($this->_trace)) {
$this->_trace = $this->getTrace();
if (empty($this->_trace)) {
$backtrace = debug_backtrace();
$this->_trace = array($backtrace[count($backtrace)-1]);
}
}
return $this->_trace;
}
public function getErrorClass()
{
$trace = $this->getTraceSafe();
@ -253,22 +324,22 @@ class PEAR_Exception extends Exception
$trace = $this->getTraceSafe();
$causes = array();
$this->getCauseMessage($causes);
$html = '<table style="border: 1px" cellspacing="0">' . "\n";
$html = '<table style="border: 1px" cellspacing="0">' . "\n";
foreach ($causes as $i => $cause) {
$html .= '<tr><td colspan="3" style="background: #ff9999">'
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
. 'on line <b>' . $cause['line'] . '</b>'
. "</td></tr>\n";
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
. 'on line <b>' . $cause['line'] . '</b>'
. "</td></tr>\n";
}
$html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
. '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
. '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
foreach ($trace as $k => $v) {
$html .= '<tr><td style="text-align: center;">' . $k . '</td>'
. '<td>';
. '<td>';
if (!empty($v['class'])) {
$html .= $v['class'] . $v['type'];
}
@ -278,7 +349,7 @@ class PEAR_Exception extends Exception
foreach ($v['args'] as $arg) {
if (is_null($arg)) $args[] = 'null';
elseif (is_array($arg)) $args[] = 'Array';
elseif (is_object($arg)) $args[] = 'Object(' . get_class($arg) . ')';
elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
else {
@ -289,92 +360,19 @@ class PEAR_Exception extends Exception
}
}
}
$html .= '(' . implode(', ', $args) . ')'
. '</td>'
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
. '</td></tr>' . "\n";
$html .= '(' . implode(', ',$args) . ')'
. '</td>'
. '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
. '</td></tr>' . "\n";
}
$html .= '<tr><td style="text-align: center;">' . ($k + 1) . '</td>'
. '<td>{main}</td>'
. '<td>&nbsp;</td></tr>' . "\n"
. '</table>';
$html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
. '<td>{main}</td>'
. '<td>&nbsp;</td></tr>' . "\n"
. '</table>';
return $html;
}
/**
* Function must be public to call on caused exceptions
* @param array
*/
public function getCauseMessage(&$causes)
{
$trace = $this->getTraceSafe();
$cause = array('class' => get_class($this),
'message' => $this->message,
'file' => 'unknown',
'line' => 'unknown');
if (isset($trace[0])) {
if (isset($trace[0]['file'])) {
$cause['file'] = $trace[0]['file'];
$cause['line'] = $trace[0]['line'];
}
}
$causes[] = $cause;
if ($this->cause instanceof PEAR_Exception) {
$this->cause->getCauseMessage($causes);
} elseif ($this->cause instanceof Exception) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage(),
'file' => $this->cause->getFile(),
'line' => $this->cause->getLine());
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($this->cause)) {
foreach ($this->cause as $cause) {
if ($cause instanceof PEAR_Exception) {
$cause->getCauseMessage($causes);
} elseif ($cause instanceof Exception) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage(),
'file' => $cause->getFile(),
'line' => $cause->getLine());
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($cause) && isset($cause['message'])) {
// PEAR_ErrorStack warning
$causes[] = array(
'class' => $cause['package'],
'message' => $cause['message'],
'file' => isset($cause['context']['file']) ?
$cause['context']['file'] :
'unknown',
'line' => isset($cause['context']['line']) ?
$cause['context']['line'] :
'unknown',
);
}
}
}
}
public function getTraceSafe()
{
if (!isset($this->_trace)) {
$this->_trace = $this->getTrace();
if (empty($this->_trace)) {
$backtrace = debug_backtrace();
$this->_trace = array($backtrace[count($backtrace) - 1]);
}
}
return $this->_trace;
}
public function toText()
{
$causes = array();
@ -382,8 +380,8 @@ class PEAR_Exception extends Exception
$causeMsg = '';
foreach ($causes as $i => $cause) {
$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
. $cause['message'] . ' in ' . $cause['file']
. ' on line ' . $cause['line'] . "\n";
. $cause['message'] . ' in ' . $cause['file']
. ' on line ' . $cause['line'] . "\n";
}
return $causeMsg . $this->getTraceAsString();
}

27
extlib/PEAR_LICENSE Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 1997-2009,
Stig Bakken <ssb@php.net>,
Gregory Beaver <cellog@php.net>,
Helgi Þormar Þorbjörnsson <helgi@php.net>,
Tomas V.V.Cox <cox@idecnet.com>,
Martin Jansen <mj@php.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
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.

View File

@ -22,194 +22,47 @@ require_once 'Console/Getopt.php';
$GLOBALS['_System_temp_files'] = array();
/**
* System offers cross platform compatible system functions
*
* Static functions for different operations. Should work under
* Unix and Windows. The names and usage has been taken from its respectively
* GNU commands. The functions will return (bool) false on error and will
* trigger the error with the PHP trigger_error() function (you can silence
* the error by prefixing a '@' sign after the function call, but this
* is not recommended practice. Instead use an error handler with
* {@link set_error_handler()}).
*
* Documentation on this class you can find in:
* http://pear.php.net/manual/
*
* Example usage:
* if (!@System::rm('-r file1 dir1')) {
* print "could not delete file1 or dir1";
* }
*
* In case you need to to pass file names with spaces,
* pass the params as an array:
*
* System::rm(array('-r', $file1, $dir1));
*
* @category pear
* @package System
* @author Tomas V.V. Cox <cox@idecnet.com>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @static
*/
* System offers cross platform compatible system functions
*
* Static functions for different operations. Should work under
* Unix and Windows. The names and usage has been taken from its respectively
* GNU commands. The functions will return (bool) false on error and will
* trigger the error with the PHP trigger_error() function (you can silence
* the error by prefixing a '@' sign after the function call, but this
* is not recommended practice. Instead use an error handler with
* {@link set_error_handler()}).
*
* Documentation on this class you can find in:
* http://pear.php.net/manual/
*
* Example usage:
* if (!@System::rm('-r file1 dir1')) {
* print "could not delete file1 or dir1";
* }
*
* In case you need to to pass file names with spaces,
* pass the params as an array:
*
* System::rm(array('-r', $file1, $dir1));
*
* @category pear
* @package System
* @author Tomas V.V. Cox <cox@idecnet.com>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @static
*/
class System
{
/**
* Concatenate files
*
* Usage:
* 1) $var = System::cat('sample.txt test.txt');
* 2) System::cat('sample.txt test.txt > final.txt');
* 3) System::cat('sample.txt test.txt >> final.txt');
*
* Note: as the class use fopen, urls should work also
*
* @param string $args the arguments
* @return boolean true on success
*/
public static function &cat($args)
{
$ret = null;
$files = array();
if (!is_array($args)) {
$args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
}
$count_args = count($args);
for ($i = 0; $i < $count_args; $i++) {
if ($args[$i] == '>') {
$mode = 'wb';
$outputfile = $args[$i + 1];
break;
} elseif ($args[$i] == '>>') {
$mode = 'ab+';
$outputfile = $args[$i + 1];
break;
} else {
$files[] = $args[$i];
}
}
$outputfd = false;
if (isset($mode)) {
if (!$outputfd = fopen($outputfile, $mode)) {
$err = System::raiseError("Could not open $outputfile");
return $err;
}
$ret = true;
}
foreach ($files as $file) {
if (!$fd = fopen($file, 'r')) {
System::raiseError("Could not open $file");
continue;
}
while ($cont = fread($fd, 2048)) {
if (is_resource($outputfd)) {
fwrite($outputfd, $cont);
} else {
$ret .= $cont;
}
}
fclose($fd);
}
if (is_resource($outputfd)) {
fclose($outputfd);
}
return $ret;
}
/**
* Output errors with PHP trigger_error(). You can silence the errors
* with prefixing a "@" sign to the function call: @System::mkdir(..);
*
* @param mixed $error a PEAR error or a string with the error message
* @return bool false
*/
protected static function raiseError($error)
{
if (PEAR::isError($error)) {
$error = $error->getMessage();
}
trigger_error($error, E_USER_WARNING);
return false;
}
/**
* Creates temporary files or directories. This function will remove
* the created files when the scripts finish its execution.
*
* Usage:
* 1) $tempfile = System::mktemp("prefix");
* 2) $tempdir = System::mktemp("-d prefix");
* 3) $tempfile = System::mktemp();
* 4) $tempfile = System::mktemp("-t /var/tmp prefix");
*
* prefix -> The string that will be prepended to the temp name
* (defaults to "tmp").
* -d -> A temporary dir will be created instead of a file.
* -t -> The target dir where the temporary (file|dir) will be created. If
* this param is missing by default the env vars TMP on Windows or
* TMPDIR in Unix will be used. If these vars are also missing
* c:\windows\temp or /tmp will be used.
*
* @param string $args The arguments
* @return mixed the full path of the created (file|dir) or false
* @see System::tmpdir()
*/
public static function mktemp($args = null)
{
static $first_time = true;
$opts = System::_parseArgs($args, 't:d');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
foreach ($opts[0] as $opt) {
if ($opt[0] == 'd') {
$tmp_is_dir = true;
} elseif ($opt[0] == 't') {
$tmpdir = $opt[1];
}
}
$prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
if (!isset($tmpdir)) {
$tmpdir = System::tmpdir();
}
if (!System::mkDir(['-p', $tmpdir])) {
return false;
}
$tmp = tempnam($tmpdir, $prefix);
if (isset($tmp_is_dir)) {
unlink($tmp); // be careful possible race condition here
if (!mkdir($tmp, 0700)) {
return System::raiseError("Unable to create temporary directory $tmpdir");
}
}
$GLOBALS['_System_temp_files'][] = $tmp;
/*if (isset($tmp_is_dir)) {
//$GLOBALS['_System_temp_files'][] = dirname($tmp);
}*/
if ($first_time) {
PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
$first_time = false;
}
return $tmp;
}
/**
* returns the commandline arguments of a function
*
* @param string $argv the commandline
* @param string $short_options the allowed option short-tags
* @param string $long_options the allowed option long-tags
* @param string $argv the commandline
* @param string $short_options the allowed option short-tags
* @param string $long_options the allowed option long-tags
* @return array the given options and there values
*/
public static function _parseArgs($argv, $short_options, $long_options = null)
@ -239,126 +92,117 @@ class System
if (empty($a)) {
continue;
}
$argv[$k] = trim($a);
$argv[$k] = trim($a) ;
}
}
return (new Console_Getopt)->getopt2($argv, $short_options, $long_options);
return Console_Getopt::getopt2($argv, $short_options, $long_options);
}
/**
* Get the path of the temporal directory set in the system
* by looking in its environments variables.
* Note: php.ini-recommended removes the "E" from the variables_order setting,
* making unavaible the $_ENV array, that s why we do tests with _ENV
* Output errors with PHP trigger_error(). You can silence the errors
* with prefixing a "@" sign to the function call: @System::mkdir(..);
*
* @return string The temporary directory on the system
* @param mixed $error a PEAR error or a string with the error message
* @return bool false
*/
public static function tmpdir()
protected static function raiseError($error)
{
if (OS_WINDOWS) {
if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
return $var;
}
if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {
return $var;
}
if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : getenv('USERPROFILE')) {
return $var;
}
if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {
return $var;
}
return getenv('SystemRoot') . '\temp';
if (PEAR::isError($error)) {
$error = $error->getMessage();
}
if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
trigger_error($error, E_USER_WARNING);
return false;
}
/**
* Make directories.
* Creates a nested array representing the structure of a directory
*
* The -p option will create parent directories
* @param string $args the name of the director(y|ies) to create
* @return bool True for success
* System::_dirToStruct('dir1', 0) =>
* Array
* (
* [dirs] => Array
* (
* [0] => dir1
* )
*
* [files] => Array
* (
* [0] => dir1/file2
* [1] => dir1/file3
* )
* )
* @param string $sPath Name of the directory
* @param integer $maxinst max. deep of the lookup
* @param integer $aktinst starting deep of the lookup
* @param bool $silent if true, do not emit errors.
* @return array the structure of the dir
*/
public static function mkDir($args)
protected static function _dirToStruct($sPath, $maxinst, $aktinst = 0, $silent = false)
{
$opts = System::_parseArgs($args, 'pm:');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
$struct = array('dirs' => array(), 'files' => array());
if (($dir = @opendir($sPath)) === false) {
if (!$silent) {
System::raiseError("Could not open dir $sPath");
}
return $struct; // XXX could not open error
}
$mode = 0777; // default mode
foreach ($opts[0] as $opt) {
if ($opt[0] == 'p') {
$create_parents = true;
} elseif ($opt[0] == 'm') {
// if the mode is clearly an octal number (starts with 0)
// convert it to decimal
if (strlen($opt[1]) && $opt[1]{0} == '0') {
$opt[1] = octdec($opt[1]);
$struct['dirs'][] = $sPath = realpath($sPath); // XXX don't add if '.' or '..' ?
$list = array();
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$list[] = $file;
}
}
closedir($dir);
natsort($list);
if ($aktinst < $maxinst || $maxinst == 0) {
foreach ($list as $val) {
$path = $sPath . DIRECTORY_SEPARATOR . $val;
if (is_dir($path) && !is_link($path)) {
$tmp = System::_dirToStruct($path, $maxinst, $aktinst+1, $silent);
$struct = array_merge_recursive($struct, $tmp);
} else {
// convert to int
$opt[1] += 0;
}
$mode = $opt[1];
}
}
$ret = true;
if (isset($create_parents)) {
foreach ($opts[1] as $dir) {
$dirstack = array();
while ((!file_exists($dir) || !is_dir($dir)) &&
$dir != DIRECTORY_SEPARATOR) {
array_unshift($dirstack, $dir);
$dir = dirname($dir);
}
while ($newdir = array_shift($dirstack)) {
if (!is_writeable(dirname($newdir))) {
$ret = false;
break;
}
if (!mkdir($newdir, $mode)) {
$ret = false;
}
}
}
} else {
foreach ($opts[1] as $dir) {
if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
$ret = false;
$struct['files'][] = $path;
}
}
}
return $ret;
return $struct;
}
/**
* Remove temporary files created my mkTemp. This function is executed
* at script shutdown time
* Creates a nested array representing the structure of a directory and files
*
* @param array $files Array listing files and dirs
* @return array
* @static
* @see System::_dirToStruct()
*/
public static function _removeTmpFiles()
protected static function _multipleToStruct($files)
{
if (count($GLOBALS['_System_temp_files'])) {
$delete = $GLOBALS['_System_temp_files'];
array_unshift($delete, '-r');
System::rm($delete);
$GLOBALS['_System_temp_files'] = array();
$struct = array('dirs' => array(), 'files' => array());
settype($files, 'array');
foreach ($files as $file) {
if (is_dir($file) && !is_link($file)) {
$tmp = System::_dirToStruct($file, 0);
$struct = array_merge_recursive($tmp, $struct);
} else {
if (!in_array($file, $struct['files'])) {
$struct['files'][] = $file;
}
}
}
return $struct;
}
/**
* The rm command for removing files.
* Supports multiple files and dirs and also recursive deletes
*
* @param string $args the arguments for rm
* @param string $args the arguments for rm
* @return mixed PEAR_Error or true for success
* @static
* @access public
@ -401,93 +245,249 @@ class System
}
/**
* Creates a nested array representing the structure of a directory and files
* Make directories.
*
* @param array $files Array listing files and dirs
* @return array
* @static
* @see System::_dirToStruct()
* The -p option will create parent directories
* @param string $args the name of the director(y|ies) to create
* @return bool True for success
*/
protected static function _multipleToStruct($files)
public static function mkDir($args)
{
$struct = array('dirs' => array(), 'files' => array());
settype($files, 'array');
foreach ($files as $file) {
if (is_dir($file) && !is_link($file)) {
$tmp = System::_dirToStruct($file, 0);
$struct = array_merge_recursive($tmp, $struct);
} else {
if (!in_array($file, $struct['files'])) {
$struct['files'][] = $file;
$opts = System::_parseArgs($args, 'pm:');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
$mode = 0777; // default mode
foreach ($opts[0] as $opt) {
if ($opt[0] == 'p') {
$create_parents = true;
} elseif ($opt[0] == 'm') {
// if the mode is clearly an octal number (starts with 0)
// convert it to decimal
if (strlen($opt[1]) && $opt[1]{0} == '0') {
$opt[1] = octdec($opt[1]);
} else {
// convert to int
$opt[1] += 0;
}
$mode = $opt[1];
}
}
$ret = true;
if (isset($create_parents)) {
foreach ($opts[1] as $dir) {
$dirstack = array();
while ((!file_exists($dir) || !is_dir($dir)) &&
$dir != DIRECTORY_SEPARATOR) {
array_unshift($dirstack, $dir);
$dir = dirname($dir);
}
while ($newdir = array_shift($dirstack)) {
if (!is_writeable(dirname($newdir))) {
$ret = false;
break;
}
if (!mkdir($newdir, $mode)) {
$ret = false;
}
}
}
} else {
foreach($opts[1] as $dir) {
if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
$ret = false;
}
}
}
return $struct;
return $ret;
}
/**
* Creates a nested array representing the structure of a directory
* Concatenate files
*
* System::_dirToStruct('dir1', 0) =>
* Array
* (
* [dirs] => Array
* (
* [0] => dir1
* )
* Usage:
* 1) $var = System::cat('sample.txt test.txt');
* 2) System::cat('sample.txt test.txt > final.txt');
* 3) System::cat('sample.txt test.txt >> final.txt');
*
* [files] => Array
* (
* [0] => dir1/file2
* [1] => dir1/file3
* )
* )
* @param string $sPath Name of the directory
* @param integer $maxinst max. deep of the lookup
* @param integer $aktinst starting deep of the lookup
* @param bool $silent if true, do not emit errors.
* @return array the structure of the dir
* Note: as the class use fopen, urls should work also
*
* @param string $args the arguments
* @return boolean true on success
*/
protected static function _dirToStruct($sPath, $maxinst, $aktinst = 0, $silent = false)
public static function &cat($args)
{
$struct = array('dirs' => array(), 'files' => array());
if (($dir = @opendir($sPath)) === false) {
if (!$silent) {
System::raiseError("Could not open dir $sPath");
}
return $struct; // XXX could not open error
$ret = null;
$files = array();
if (!is_array($args)) {
$args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
}
$struct['dirs'][] = $sPath = realpath($sPath); // XXX don't add if '.' or '..' ?
$list = array();
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$list[] = $file;
$count_args = count($args);
for ($i = 0; $i < $count_args; $i++) {
if ($args[$i] == '>') {
$mode = 'wb';
$outputfile = $args[$i+1];
break;
} elseif ($args[$i] == '>>') {
$mode = 'ab+';
$outputfile = $args[$i+1];
break;
} else {
$files[] = $args[$i];
}
}
closedir($dir);
natsort($list);
if ($aktinst < $maxinst || $maxinst == 0) {
foreach ($list as $val) {
$path = $sPath . DIRECTORY_SEPARATOR . $val;
if (is_dir($path) && !is_link($path)) {
$tmp = System::_dirToStruct($path, $maxinst, $aktinst + 1, $silent);
$struct = array_merge_recursive($struct, $tmp);
$outputfd = false;
if (isset($mode)) {
if (!$outputfd = fopen($outputfile, $mode)) {
$err = System::raiseError("Could not open $outputfile");
return $err;
}
$ret = true;
}
foreach ($files as $file) {
if (!$fd = fopen($file, 'r')) {
System::raiseError("Could not open $file");
continue;
}
while ($cont = fread($fd, 2048)) {
if (is_resource($outputfd)) {
fwrite($outputfd, $cont);
} else {
$struct['files'][] = $path;
$ret .= $cont;
}
}
fclose($fd);
}
if (is_resource($outputfd)) {
fclose($outputfd);
}
return $ret;
}
/**
* Creates temporary files or directories. This function will remove
* the created files when the scripts finish its execution.
*
* Usage:
* 1) $tempfile = System::mktemp("prefix");
* 2) $tempdir = System::mktemp("-d prefix");
* 3) $tempfile = System::mktemp();
* 4) $tempfile = System::mktemp("-t /var/tmp prefix");
*
* prefix -> The string that will be prepended to the temp name
* (defaults to "tmp").
* -d -> A temporary dir will be created instead of a file.
* -t -> The target dir where the temporary (file|dir) will be created. If
* this param is missing by default the env vars TMP on Windows or
* TMPDIR in Unix will be used. If these vars are also missing
* c:\windows\temp or /tmp will be used.
*
* @param string $args The arguments
* @return mixed the full path of the created (file|dir) or false
* @see System::tmpdir()
*/
public static function mktemp($args = null)
{
static $first_time = true;
$opts = System::_parseArgs($args, 't:d');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
return $struct;
foreach ($opts[0] as $opt) {
if ($opt[0] == 'd') {
$tmp_is_dir = true;
} elseif ($opt[0] == 't') {
$tmpdir = $opt[1];
}
}
$prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
if (!isset($tmpdir)) {
$tmpdir = System::tmpdir();
}
if (!System::mkDir(array('-p', $tmpdir))) {
return false;
}
$tmp = tempnam($tmpdir, $prefix);
if (isset($tmp_is_dir)) {
unlink($tmp); // be careful possible race condition here
if (!mkdir($tmp, 0700)) {
return System::raiseError("Unable to create temporary directory $tmpdir");
}
}
$GLOBALS['_System_temp_files'][] = $tmp;
if (isset($tmp_is_dir)) {
//$GLOBALS['_System_temp_files'][] = dirname($tmp);
}
if ($first_time) {
PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
$first_time = false;
}
return $tmp;
}
/**
* Remove temporary files created my mkTemp. This function is executed
* at script shutdown time
*/
public static function _removeTmpFiles()
{
if (count($GLOBALS['_System_temp_files'])) {
$delete = $GLOBALS['_System_temp_files'];
array_unshift($delete, '-r');
System::rm($delete);
$GLOBALS['_System_temp_files'] = array();
}
}
/**
* Get the path of the temporal directory set in the system
* by looking in its environments variables.
* Note: php.ini-recommended removes the "E" from the variables_order setting,
* making unavaible the $_ENV array, that s why we do tests with _ENV
*
* @return string The temporary directory on the system
*/
public static function tmpdir()
{
if (OS_WINDOWS) {
if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
return $var;
}
if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {
return $var;
}
if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : getenv('USERPROFILE')) {
return $var;
}
if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {
return $var;
}
return getenv('SystemRoot') . '\temp';
}
if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
/**
* The "which" command (show the full path of a command)
*
* @param string $program The command to search for
* @param mixed $fallback Value to return if $program is not found
* @param mixed $fallback Value to return if $program is not found
*
* @return mixed A string with the full path or false if not found
* @author Stig Bakken <ssb@php.net>
@ -514,8 +514,8 @@ class System
if (OS_WINDOWS) {
$exe_suffixes = getenv('PATHEXT')
? explode(PATH_SEPARATOR, getenv('PATHEXT'))
: array('.exe', '.bat', '.cmd', '.com');
? explode(PATH_SEPARATOR, getenv('PATHEXT'))
: array('.exe','.bat','.cmd','.com');
// allow passing a command.exe param
if (strpos($program, '.') !== false) {
array_unshift($exe_suffixes, '');
@ -560,7 +560,7 @@ class System
* -maxdepth <n> -> max depth of recursion
* -name <pattern> -> search pattern (bash style). Multiple -name param allowed
*
* @param mixed Either array or string with the command line
* @param mixed Either array or string with the command line
* @return array Array of found files
*/
public static function find($args)
@ -579,8 +579,8 @@ class System
for ($i = 0; $i < $args_count; $i++) {
switch ($args[$i]) {
case '-type':
if (in_array($args[$i + 1], array('d', 'f'))) {
if ($args[$i + 1] == 'd') {
if (in_array($args[$i+1], array('d', 'f'))) {
if ($args[$i+1] == 'd') {
$do_files = false;
} else {
$do_dirs = false;
@ -589,15 +589,15 @@ class System
$i++;
break;
case '-name':
$name = preg_quote($args[$i + 1], '#');
$name = preg_quote($args[$i+1], '#');
// our magic characters ? and * have just been escaped,
// so now we change the escaped versions to PCRE operators
$name = strtr($name, array('\?' => '.', '\*' => '.*'));
$patterns[] = '(' . $name . ')';
$patterns[] = '('.$name.')';
$i++;
break;
case '-maxdepth':
$depth = $args[$i + 1];
$depth = $args[$i+1];
break;
}
}
@ -611,7 +611,7 @@ class System
}
if (count($patterns)) {
$dsq = preg_quote(DIRECTORY_SEPARATOR, '#');
$pattern = '#(^|' . $dsq . ')' . implode('|', $patterns) . '($|' . $dsq . ')#';
$pattern = '#(^|'.$dsq.')'.implode('|', $patterns).'($|'.$dsq.')#';
$ret = array();
$files_count = count($files);
for ($i = 0; $i < $files_count; $i++) {

View File

@ -744,219 +744,6 @@ class Validate
return false;
}
/**
* Validate date and times. Note that this method need the Date_Calc class
*
* @param string $date Date to validate
* @param array $options array options where :
* 'format' The format of the date (%d-%m-%Y)
* or rfc822_compliant
* 'min' The date has to be greater
* than this [$day, $month, $year]
* or PEAR::Date object
* 'max' The date has to be smaller than
* this [$day, $month, $year]
* or PEAR::Date object
*
* @return bool true if valid date/time, false if not
*
* @access public
*/
public function date(string $date, array $options): bool
{
$max = false;
$min = false;
$format = '';
extract($options);
if (strtolower($format) == 'rfc822_compliant') {
$preg = '&^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),) \s+
(?:(\d{2})?) \s+
(?:(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)?) \s+
(?:(\d{2}(\d{2})?)?) \s+
(?:(\d{2}?)):(?:(\d{2}?))(:(?:(\d{2}?)))? \s+
(?:[+-]\d{4}|UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Za-ik-z])$&xi';
if (!preg_match($preg, $date, $matches)) {
return false;
}
$year = (int)$matches[4];
$months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
$month = array_keys($months, $matches[3]);
$month = (int)$month[0] + 1;
$day = (int)$matches[2];
$weekday = $matches[1];
$hour = (int)$matches[6];
$minute = (int)$matches[7];
isset($matches[9]) ? $second = (int)$matches[9] : $second = 0;
if ((strlen($year) != 4) ||
($day > 31 || $day < 1) ||
($hour > 23) ||
($minute > 59) ||
($second > 59)) {
return false;
}
} else {
$date_len = strlen($format);
for ($i = 0; $i < $date_len; $i++) {
$c = $format{$i};
if ($c == '%') {
$next = $format{$i + 1};
switch ($next) {
case 'j':
case 'd':
if ($next == 'j') {
$day = (int)Validate::_substr($date, 1, 2);
} else {
$day = (int)Validate::_substr($date, 0, 2);
}
if ($day < 1 || $day > 31) {
return false;
}
break;
case 'm':
case 'n':
if ($next == 'm') {
$month = (int)Validate::_substr($date, 0, 2);
} else {
$month = (int)Validate::_substr($date, 1, 2);
}
if ($month < 1 || $month > 12) {
return false;
}
break;
case 'Y':
case 'y':
if ($next == 'Y') {
$year = Validate::_substr($date, 4);
$year = (int)$year ? $year : '';
} else {
$year = (int)(substr(date('Y'), 0, 2) .
Validate::_substr($date, 2));
}
if (strlen($year) != 4 || $year < 0 || $year > 9999) {
return false;
}
break;
case 'g':
case 'h':
if ($next == 'g') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if (!preg_match('/^\d+$/', $hour) || $hour < 0 || $hour > 12) {
return false;
}
break;
case 'G':
case 'H':
if ($next == 'G') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if (!preg_match('/^\d+$/', $hour) || $hour < 0 || $hour > 24) {
return false;
}
break;
case 's':
case 'i':
$t = Validate::_substr($date, 2);
if (!preg_match('/^\d+$/', $t) || $t < 0 || $t > 59) {
return false;
}
break;
default:
trigger_error("Not supported char `$next' after % in offset " . ($i + 2), E_USER_WARNING);
}
$i++;
} else {
//literal
if (Validate::_substr($date, 1) != $c) {
return false;
}
}
}
}
// there is remaing data, we don't want it
if (strlen($date) && (strtolower($format) != 'rfc822_compliant')) {
return false;
}
if (isset($day) && isset($month) && isset($year) && isset($weekday)) {
if (!checkdate($month, $day, $year)) {
return false;
}
if (strtolower($format) == 'rfc822_compliant') {
if ($weekday != date("D", mktime(0, 0, 0, $month, $day, $year))) {
return false;
}
}
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)
) {
return false;
} elseif (is_array($min) &&
(Date_Calc::compareDates(
$day,
$month,
$year,
$min[0],
$min[1],
$min[2]
) < 0)
) {
return false;
}
}
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)
) {
return false;
} elseif (is_array($max) &&
(Date_Calc::compareDates(
$day,
$month,
$year,
$max[0],
$max[1],
$max[2]
) > 0)
) {
return false;
}
}
}
return true;
}
/**
* Substr
*

22
extlib/Validate_LICENSE Normal file
View File

@ -0,0 +1,22 @@
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, th
is 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 name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WA
RRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABIL
ITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR C
ONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOW
EVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILI
TY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U
SE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('INSTALLDIR', realpath(__DIR__ . '/..'));
$shortoptions = 'i:n:o';
$longoptions = array('id=', 'nickname=', 'owner');
@ -33,7 +33,7 @@ Perform commands on behalf of a user, such as sub, unsub, join, drop
END_OF_USERROLE_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
require_once INSTALLDIR . '/scripts/commandline.inc';
function interpretCommand($user, $body)
{

View File

@ -39,14 +39,12 @@ set_time_limit(0);
mb_internal_encoding('UTF-8');
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
// Add extlib to our path so we can get Console_Getopt
$_extra_path = array(INSTALLDIR.'/extlib/');
// Autoload composer dependencies
require_once INSTALLDIR . '/vendor/autoload.php';
// Add extlib to our path
$_extra_path = [INSTALLDIR.'/extlib/'];
set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path());
require_once 'Console/Getopt.php';
// Note: $shortoptions and $longoptions should be pre-defined!
$_default_shortoptions = 'qvhc:s:p:';

View File

@ -16,14 +16,14 @@ Options:
ENDOFHELP;
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('INSTALLDIR', dirname(__DIR__));
set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path());
$pattern = "*.php *.inc";
$exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
$plugin = false;
require_once 'Console/Getopt.php';
require_once INSTALLDIR . '/vendor/autoload.php';
$parser = new Console_Getopt();
$result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
if (PEAR::isError($result)) {

View File

@ -145,6 +145,7 @@ return array(
'CAS_Request_MultiRequestInterface' => $vendorDir . '/apereo/phpcas/source/CAS/Request/MultiRequestInterface.php',
'CAS_Request_RequestInterface' => $vendorDir . '/apereo/phpcas/source/CAS/Request/RequestInterface.php',
'CAS_TypeMismatchException' => $vendorDir . '/apereo/phpcas/source/CAS/TypeMismatchException.php',
'Console_Getopt' => $vendorDir . '/pear/console_getopt/Console/Getopt.php',
'HTMLPurifier' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.php',
'HTMLPurifier_Arborize' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php',
'HTMLPurifier_AttrCollections' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php',

View File

@ -7,4 +7,5 @@ $baseDir = dirname($vendorDir);
return array(
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
'Console' => array($vendorDir . '/pear/console_getopt'),
);

View File

@ -91,6 +91,13 @@ class ComposerStaticInit444c3f31864f68a3f466e2c19837e185
0 => __DIR__ . '/..' . '/ezyang/htmlpurifier/library',
),
),
'C' =>
array (
'Console' =>
array (
0 => __DIR__ . '/..' . '/pear/console_getopt',
),
),
);
public static $classMap = array (
@ -233,6 +240,7 @@ class ComposerStaticInit444c3f31864f68a3f466e2c19837e185
'CAS_Request_MultiRequestInterface' => __DIR__ . '/..' . '/apereo/phpcas/source/CAS/Request/MultiRequestInterface.php',
'CAS_Request_RequestInterface' => __DIR__ . '/..' . '/apereo/phpcas/source/CAS/Request/RequestInterface.php',
'CAS_TypeMismatchException' => __DIR__ . '/..' . '/apereo/phpcas/source/CAS/TypeMismatchException.php',
'Console_Getopt' => __DIR__ . '/..' . '/pear/console_getopt/Console/Getopt.php',
'HTMLPurifier' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.php',
'HTMLPurifier_Arborize' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php',
'HTMLPurifier_AttrCollections' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php',

View File

@ -7,4 +7,5 @@ $baseDir = dirname($vendorDir);
return array(
$vendorDir . '/openid/php-openid',
$vendorDir . '/pear/console_getopt',
);

View File

@ -699,6 +699,55 @@
"random"
]
},
{
"name": "pear/console_getopt",
"version": "v1.4.2",
"version_normalized": "1.4.2.0",
"source": {
"type": "git",
"url": "https://github.com/pear/Console_Getopt.git",
"reference": "6c77aeb625b32bd752e89ee17972d103588b90c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Console_Getopt/zipball/6c77aeb625b32bd752e89ee17972d103588b90c0",
"reference": "6c77aeb625b32bd752e89ee17972d103588b90c0",
"shasum": ""
},
"time": "2019-02-06T16:52:33+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Console": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Greg Beaver",
"email": "cellog@php.net",
"role": "Helper"
},
{
"name": "Andrei Zmievski",
"email": "andrei@php.net",
"role": "Lead"
},
{
"name": "Stig Bakken",
"email": "stig@php.net",
"role": "Developer"
}
],
"description": "More info available on: http://pear.php.net/package/Console_Getopt"
},
{
"name": "phpseclib/phpseclib",
"version": "dev-master",

6
vendor/pear/console_getopt/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# composer related
composer.lock
composer.phar
vendor
README.html
dist/

View File

@ -0,0 +1,9 @@
language: php
php:
- 7
- 5.6
- 5.5
- 5.4
sudo: false
script:
- pear run-tests -r tests/

View File

@ -3,21 +3,18 @@
/**
* PHP Version 5
*
* Copyright (c) 1997-2004 The PHP Group
* Copyright (c) 2001-2015, The PEAR developers
*
* This source file is subject to version 3.0 of the PHP license,
* This source file is subject to the BSD-2-Clause license,
* that is bundled with this package in the file LICENSE, and is
* available through the world-wide-web at the following url:
* http://www.php.net/license/3_0.txt.
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* license@php.net so we can mail you a copy immediately.
* http://opensource.org/licenses/bsd-license.php.
*
* @category Console
* @package Console_Getopt
* @author Andrei Zmievski <andrei@php.net>
* @license http://www.php.net/license/3_0.txt PHP 3.0
* @version CVS: $Id: Getopt.php 306067 2010-12-08 00:13:31Z dufuz $
* @license http://opensource.org/licenses/bsd-license.php BSD-2-Clause
* @version CVS: $Id$
* @link http://pear.php.net/package/Console_Getopt
*/
@ -29,7 +26,7 @@ require_once 'PEAR.php';
* @category Console
* @package Console_Getopt
* @author Andrei Zmievski <andrei@php.net>
* @license http://www.php.net/license/3_0.txt PHP 3.0
* @license http://opensource.org/licenses/bsd-license.php BSD-2-Clause
* @link http://pear.php.net/package/Console_Getopt
*/
class Console_Getopt
@ -68,9 +65,8 @@ class Console_Getopt
*
* @return array two-element array containing the list of parsed options and
* the non-option arguments
* @access public
*/
function getopt2($args, $short_options, $long_options = null, $skip_unknown = false)
public static function getopt2($args, $short_options, $long_options = null, $skip_unknown = false)
{
return Console_Getopt::doGetopt(2, $args, $short_options, $long_options, $skip_unknown);
}
@ -87,7 +83,7 @@ class Console_Getopt
* @return array two-element array containing the list of parsed options and
* the non-option arguments
*/
function getopt($args, $short_options, $long_options = null, $skip_unknown = false)
public static function getopt($args, $short_options, $long_options = null, $skip_unknown = false)
{
return Console_Getopt::doGetopt(1, $args, $short_options, $long_options, $skip_unknown);
}
@ -103,7 +99,7 @@ class Console_Getopt
*
* @return array
*/
function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
public static function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
{
// in case you pass directly readPHPArgv() as the first arg
if (PEAR::isError($args)) {
@ -132,8 +128,8 @@ class Console_Getopt
}
}
reset($args);
while (list($i, $arg) = each($args)) {
for ($i = 0; $i < count($args); $i++) {
$arg = $args[$i];
/* The special element '--' means explicit end of
options. Treat the rest of the arguments as non-options
and end the loop. */
@ -149,6 +145,7 @@ class Console_Getopt
$error = Console_Getopt::_parseLongOption(substr($arg, 2),
$long_options,
$opts,
$i,
$args,
$skip_unknown);
if (PEAR::isError($error)) {
@ -162,6 +159,7 @@ class Console_Getopt
$error = Console_Getopt::_parseShortOption(substr($arg, 1),
$short_options,
$opts,
$i,
$args,
$skip_unknown);
if (PEAR::isError($error)) {
@ -179,13 +177,13 @@ class Console_Getopt
* @param string $arg Argument
* @param string[] $short_options Available short options
* @param string[][] &$opts
* @param string[] &$args
* @param int &$argIdx
* @param string[] $args
* @param boolean $skip_unknown suppresses Console_Getopt: unrecognized option
*
* @access private
* @return void
*/
function _parseShortOption($arg, $short_options, &$opts, &$args, $skip_unknown)
protected static function _parseShortOption($arg, $short_options, &$opts, &$argIdx, $args, $skip_unknown)
{
for ($i = 0; $i < strlen($arg); $i++) {
$opt = $arg{$i};
@ -215,16 +213,17 @@ class Console_Getopt
if ($i + 1 < strlen($arg)) {
$opts[] = array($opt, substr($arg, $i + 1));
break;
} else if (list(, $opt_arg) = each($args)) {
} else if (isset($args[++$argIdx])) {
$opt_arg = $args[$argIdx];
/* Else use the next argument. */;
if (Console_Getopt::_isShortOpt($opt_arg)
|| Console_Getopt::_isLongOpt($opt_arg)) {
$msg = "option requires an argument --$opt";
return PEAR::raiseError("Console_Getopt:" . $msg);
return PEAR::raiseError("Console_Getopt: " . $msg);
}
} else {
$msg = "option requires an argument --$opt";
return PEAR::raiseError("Console_Getopt:" . $msg);
return PEAR::raiseError("Console_Getopt: " . $msg);
}
}
}
@ -238,10 +237,9 @@ class Console_Getopt
*
* @param string $arg Argument to check
*
* @access private
* @return bool
*/
function _isShortOpt($arg)
protected static function _isShortOpt($arg)
{
return strlen($arg) == 2 && $arg[0] == '-'
&& preg_match('/[a-zA-Z]/', $arg[1]);
@ -252,10 +250,9 @@ class Console_Getopt
*
* @param string $arg Argument to check
*
* @access private
* @return bool
*/
function _isLongOpt($arg)
protected static function _isLongOpt($arg)
{
return strlen($arg) > 2 && $arg[0] == '-' && $arg[1] == '-' &&
preg_match('/[a-zA-Z]+$/', substr($arg, 2));
@ -267,12 +264,12 @@ class Console_Getopt
* @param string $arg Argument
* @param string[] $long_options Available long options
* @param string[][] &$opts
* @param string[] &$args
* @param int &$argIdx
* @param string[] $args
*
* @access private
* @return void|PEAR_Error
*/
function _parseLongOption($arg, $long_options, &$opts, &$args, $skip_unknown)
protected static function _parseLongOption($arg, $long_options, &$opts, &$argIdx, $args, $skip_unknown)
{
@list($opt, $opt_arg) = explode('=', $arg, 2);
@ -313,9 +310,12 @@ class Console_Getopt
if (substr($long_opt, -2) != '==') {
/* Long option requires an argument.
Take the next argument if one wasn't specified. */;
if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) {
$msg = "Console_Getopt: option requires an argument --$opt";
return PEAR::raiseError($msg);
if (!strlen($opt_arg)) {
if (!isset($args[++$argIdx])) {
$msg = "Console_Getopt: option requires an argument --$opt";
return PEAR::raiseError($msg);
}
$opt_arg = $args[$argIdx];
}
if (Console_Getopt::_isShortOpt($opt_arg)
@ -344,10 +344,9 @@ class Console_Getopt
* Safely read the $argv PHP array across different PHP configurations.
* Will take care on register_globals and register_argc_argv ini directives
*
* @access public
* @return mixed the $argv PHP array or PEAR error if not registered
*/
function readPHPArgv()
public static function readPHPArgv()
{
global $argv;
if (!is_array($argv)) {
@ -363,4 +362,4 @@ class Console_Getopt
return $argv;
}
}
}

25
vendor/pear/console_getopt/LICENSE vendored Normal file
View File

@ -0,0 +1,25 @@
Copyright (c) 2001-2015, The PEAR developers
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.
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
HOLDER 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.

26
vendor/pear/console_getopt/README.rst vendored Normal file
View File

@ -0,0 +1,26 @@
*******************************************
Console_Getopt - Command-line option parser
*******************************************
This is a PHP implementation of "getopt" supporting both short and long options.
It helps parsing command line options in your PHP script.
Homepage: http://pear.php.net/package/Console_Getopt
.. image:: https://travis-ci.org/pear/Console_Getopt.svg?branch=master
:target: https://travis-ci.org/pear/Console_Getopt
Alternatives
============
* Console_CommandLine__ (recommended)
* Console_GetoptPlus__
__ http://pear.php.net/package/Console_CommandLine
__ http://pear.php.net/package/Console_GetoptPlus
License
=======
BSD-2-Clause

View File

@ -0,0 +1,35 @@
{
"authors": [
{
"email": "andrei@php.net",
"name": "Andrei Zmievski",
"role": "Lead"
},
{
"email": "stig@php.net",
"name": "Stig Bakken",
"role": "Developer"
},
{
"email": "cellog@php.net",
"name": "Greg Beaver",
"role": "Helper"
}
],
"autoload": {
"psr-0": {
"Console": "./"
}
},
"description": "More info available on: http://pear.php.net/package/Console_Getopt",
"include-path": [
"./"
],
"license": "BSD-2-Clause",
"name": "pear/console_getopt",
"support": {
"issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Console_Getopt",
"source": "https://github.com/pear/Console_Getopt"
},
"type": "library"
}

284
vendor/pear/console_getopt/package.xml vendored Normal file
View File

@ -0,0 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>Console_Getopt</name>
<channel>pear.php.net</channel>
<summary>Command-line option parser</summary>
<description>This is a PHP implementation of &quot;getopt&quot; supporting both
short and long options.</description>
<lead>
<name>Andrei Zmievski</name>
<user>andrei</user>
<email>andrei@php.net</email>
<active>no</active>
</lead>
<developer>
<name>Stig Bakken</name>
<user>ssb</user>
<email>stig@php.net</email>
<active>no</active>
</developer>
<helper>
<name>Greg Beaver</name>
<user>cellog</user>
<email>cellog@php.net</email>
<active>no</active>
</helper>
<date>2019-02-06</date>
<version>
<release>1.4.2</release>
<api>1.4.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD-2-Clause</license>
<notes>
* Remove use of each(), which is removed in PHP 8
</notes>
<contents>
<dir name="/">
<dir name="Console">
<file name="Getopt.php" role="php" />
</dir>
<dir name="tests">
<file role="test" name="001-getopt.phpt" />
<file role="test" name="bug10557.phpt" />
<file role="test" name="bug11068.phpt" />
<file role="test" name="bug13140.phpt" />
</dir>
</dir>
</contents>
<compatible>
<name>PEAR</name>
<channel>pear.php.net</channel>
<min>1.4.0</min>
<max>1.999.999</max>
</compatible>
<dependencies>
<required>
<php>
<min>5.4.0</min>
</php>
<pearinstaller>
<min>1.8.0</min>
</pearinstaller>
</required>
</dependencies>
<phprelease />
<changelog>
<release>
<date>2019-02-06</date>
<version>
<release>1.4.2</release>
<api>1.4.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD-2-Clause</license>
<notes>
* Remove use of each(), which is removed in PHP 8
</notes>
</release>
<release>
<date>2015-07-20</date>
<version>
<release>1.4.1</release>
<api>1.4.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD-2-Clause</license>
<notes>
* Fix unit test on PHP 7 [cweiske]
</notes>
</release>
<release>
<date>2015-02-22</date>
<version>
<release>1.4.0</release>
<api>1.4.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/bsd-license.php">BSD-2-Clause</license>
<notes>
* Change license to BSD-2-Clause
* Set minimum PHP version to 5.4.0
* Mark static methods with "static" keyword
</notes>
</release>
<release>
<date>2011-03-07</date>
<version>
<release>1.3.1</release>
<api>1.3.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
* Change the minimum PEAR installer dep to be lower
</notes>
</release>
<release>
<date>2010-12-11</date>
<time>20:20:13</time>
<version>
<release>1.3.0</release>
<api>1.3.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
* Implement Request #13140: [PATCH] to skip unknown parameters. [patch by rquadling, improved on by dufuz]
</notes>
</release>
<release>
<date>2007-06-12</date>
<version>
<release>1.2.3</release>
<api>1.2.1</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
* fix Bug #11068: No way to read plain &quot;-&quot; option [cardoe]
</notes>
</release>
<release>
<version>
<release>1.2.2</release>
<api>1.2.1</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2007-02-17</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
* fix Bug #4475: An ambiguous error occurred when specifying similar longoption name.
* fix Bug #10055: Not failing properly on short options missing required values
</notes>
</release>
<release>
<version>
<release>1.2.1</release>
<api>1.2.1</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2006-12-08</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Fixed bugs #4448 (Long parameter values truncated with longoption parameter) and #7444 (Trailing spaces after php closing tag)
</notes>
</release>
<release>
<version>
<release>1.2</release>
<api>1.2</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2003-12-11</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Fix to preserve BC with 1.0 and allow correct behaviour for new users
</notes>
</release>
<release>
<version>
<release>1.0</release>
<api>1.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<date>2002-09-13</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Stable release
</notes>
</release>
<release>
<version>
<release>0.11</release>
<api>0.11</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<date>2002-05-26</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
POSIX getopt compatibility fix: treat first element of args
array as command name
</notes>
</release>
<release>
<version>
<release>0.10</release>
<api>0.10</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<date>2002-05-12</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Packaging fix
</notes>
</release>
<release>
<version>
<release>0.9</release>
<api>0.9</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<date>2002-05-12</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Initial release
</notes>
</release>
</changelog>
</package>

View File

@ -0,0 +1,63 @@
--TEST--
Console_Getopt
--FILE--
<?php
require_once 'Console/Getopt.php';
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s\n\n");
function test($argstr, $optstr) {
$argv = preg_split('/[[:space:]]+/', $argstr);
if (PEAR::isError($options = Console_Getopt::getopt($argv, $optstr))) {
return;
}
$opts = $options[0];
$non_opts = $options[1];
$i = 0;
print "options: ";
foreach ($opts as $o => $d) {
if ($i++ > 0) {
print ", ";
}
print $d[0] . '=' . $d[1];
}
print "\n";
print "params: " . implode(", ", $non_opts) . "\n";
print "\n";
}
test("-abc", "abc");
test("-abc foo", "abc");
test("-abc foo", "abc:");
test("-abc foo bar gazonk", "abc");
test("-abc foo bar gazonk", "abc:");
test("-a -b -c", "abc");
test("-a -b -c", "abc:");
test("-abc", "ab:c");
test("-abc foo -bar gazonk", "abc");
?>
--EXPECT--
options: a=, b=, c=
params:
options: a=, b=, c=
params: foo
options: a=, b=, c=foo
params:
options: a=, b=, c=
params: foo, bar, gazonk
options: a=, b=, c=foo
params: bar, gazonk
options: a=, b=, c=
params:
Console_Getopt: option requires an argument --c
options: a=, b=c
params:
options: a=, b=, c=
params: foo, -bar, gazonk

View File

@ -0,0 +1,22 @@
--TEST--
Console_Getopt [bug 10557]
--SKIPIF--
--FILE--
<?php
$_SERVER['argv'] =
$argv = array('hi', '-fjjohnston@mail.com', '--to', '--mailpack', '--debug');
require_once 'Console/Getopt.php';
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'f:t:',
array('from=','to=','mailpack=','direction=','verbose','debug'));
if(PEAR::isError($ret))
{
echo $ret->getMessage()."\n";
echo 'FATAL';
exit;
}
print_r($ret);
?>
--EXPECT--
Console_Getopt: option requires an argument --to
FATAL

View File

@ -0,0 +1,44 @@
--TEST--
Console_Getopt [bug 11068]
--SKIPIF--
--FILE--
<?php
$_SERVER['argv'] =
$argv = array('hi', '-fjjohnston@mail.com', '--to', 'hi', '-');
require_once 'Console/Getopt.php';
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'f:t:',
array('from=','to=','mailpack=','direction=','verbose','debug'));
if(PEAR::isError($ret))
{
echo $ret->getMessage()."\n";
echo 'FATAL';
exit;
}
print_r($ret);
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => Array
(
[0] => f
[1] => jjohnston@mail.com
)
[1] => Array
(
[0] => --to
[1] => hi
)
)
[1] => Array
(
[0] => -
)
)

View File

@ -0,0 +1,75 @@
--TEST--
Console_Getopt [bug 13140]
--SKIPIF--
--FILE--
<?php
$_SERVER['argv'] = $argv =
array('--bob', '--foo' , '-bar', '--test', '-rq', 'thisshouldbehere');
require_once 'Console/Getopt.php';
$cg = new Console_GetOpt();
print_r($cg->getopt2($cg->readPHPArgv(), 't', array('test'), true));
print_r($cg->getopt2($cg->readPHPArgv(), 'bar', array('foo'), true));
?>
--EXPECT--
Array
(
[0] => Array
(
[0] => Array
(
[0] => --test
[1] =>
)
)
[1] => Array
(
[0] => thisshouldbehere
)
)
Array
(
[0] => Array
(
[0] => Array
(
[0] => --foo
[1] =>
)
[1] => Array
(
[0] => b
[1] =>
)
[2] => Array
(
[0] => a
[1] =>
)
[3] => Array
(
[0] => r
[1] =>
)
[4] => Array
(
[0] => r
[1] =>
)
)
[1] => Array
(
[0] => thisshouldbehere
)
)