Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

1465
Date/Date.php Normal file

File diff suppressed because it is too large Load Diff

2117
Date/Date/Calc.php Normal file

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,242 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// {{{ Header
/**
* Class to convert date strings between Gregorian and Human calendar formats
*
* The Human Calendar format has been proposed by Scott Flansburg and can be
* explained as follows:
* The year is made up of 13 months
* Each month has 28 days
* Counting of months starts from 0 (zero) so the months will run from 0 to 12
* New Years day (00) is a monthless day
* Note: Leap Years are not yet accounted for in the Human Calendar system
*
* PHP versions 4 and 5
*
* LICENSE:
*
* Copyright (c) 1997-2006 Allan Kent
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted under the terms of the BSD License.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Date and Time
* @package Date
* @author Allan Kent <allan@lodestone.co.za>
* @copyright 1997-2006 Allan Kent
* @license http://www.opensource.org/licenses/bsd-license.php
* BSD License
* @version CVS: $Id: Human.php,v 1.6 2006/11/21 17:38:15 firman Exp $
* @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
*
* @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.4.7
* @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.
*
* @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
*
* @access public
*
* @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
* )
*
* 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.
*/
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
*
* @access public
*
* @return int unix timestamp of date
*/
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:
*/
?>

1083
Date/Date/Span.php Normal file

File diff suppressed because it is too large Load Diff

4731
Date/Date/TimeZone.php Normal file

File diff suppressed because it is too large Load Diff

30
Date/docs/LICENSE Normal file
View File

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

12
Date/docs/TODO Normal file
View File

@ -0,0 +1,12 @@
$Id: TODO,v 1.1 2006/11/21 05:40:20 firman Exp $
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

1
Date/hinweis.txt Normal file
View File

@ -0,0 +1 @@
ben<EFBFBD>tigt von outlook.php

View File

@ -0,0 +1,48 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-674.phpt,v 1.1 2006/11/20 08:53:05 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,66 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-727-1.phpt,v 1.1 2006/11/20 08:54:51 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,66 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-727-2.phpt,v 1.1 2006/11/20 08:56:24 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,514 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-727-3.phpt,v 1.1 2006/11/20 08:57:08 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,514 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-727-4.phpt,v 1.1 2006/11/20 08:57:56 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,72 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-8912.phpt,v 1.1 2006/11/20 09:07:42 firman Exp $
?>
--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');
foreach ($states as $state) {
$new_date = new Date(time());
print 'Original Time (Australia/Adelaide): ' . $new_date->getTime() . "\n";
$timezone = new Date_TimeZone($state);
$new_date->setTZ($originalTimezone);
$new_date->convertTZ($timezone);
print $state . ': ' . $new_date->getTime() . "\n";
print "\n";
}
?>
--EXPECT--
Original Time (Australia/Adelaide): (timestamp)
Australia/Adelaide: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Canberra: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Darwin: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Brisbane: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Hobart: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Melbourne: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Perth: (timestamp)
Original Time (Australia/Adelaide): (timestamp)
Australia/Sydney: (timestamp)
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,38 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-9213.phpt,v 1.1 2006/11/20 09:08:05 firman Exp $
?>
--TEST--
Bug #9213: Date_Calc doesn't like including Date.php
--FILE--
<?php
/**
* Test for: Date_Calc
* Parts tested: DATE_CALC_FORMAT constant
*/
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";
print $calc->beginOfWeek() . "\n";
?>
--EXPECT--
20060529
20060529
20060605
(timestamp)
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,40 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-9414.phpt,v 1.1 2006/11/22 00:19:58 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

View File

@ -0,0 +1,41 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
// CVS: $Id: bug-967.phpt,v 1.1 2006/11/20 09:07:18 firman Exp $
?>
--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
<?php
/*
* Local variables:
* mode: php
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

400
Date/tests/calc.php Normal file
View File

@ -0,0 +1,400 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Daniel Convissor <danielc@php.net> |
// +----------------------------------------------------------------------+
// | 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: Daniel Convissor <danielc@php.net> |
// +----------------------------------------------------------------------+
/**
* 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.
*
* @category Date and Time
* @package Date
* @author Daniel Convissor <danielc@php.net>
* @copyright 2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License
* @version CVS: $Id: calc.php,v 1.8 2005/11/15 00:16:40 pajoye Exp $
* @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::julianDate(22, 11, 2000), 'julianDate');
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::julianDate('22', '11', '2000'), 'julianDate 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');

46
Date/tests/test_calc.php Normal file
View File

@ -0,0 +1,46 @@
<?php
require_once "Date/Calc.php";
/**
* Test dates from 1970 to 2029
* Data from: http://www.merlyn.demon.co.uk/wknotest.txt
* Others usefull datas available from:
* http://www.merlyn.demon.co.uk/#dat
*/
$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 = 2==Date_Calc::weekOfYear(5,1,1998)?true:false;
$pass2 = 2==Date_Calc::weekOfYear(6,1,1998)?true:false;
$pass3 = 2==Date_Calc::weekOfYear(5,1,2004)?true:false;
$pass4 = 2==Date_Calc::weekOfYear(6,1,2004)?true:false;
if( !($pass1 && $pass2 && $pass3 && $pass4) ){
$failed_test_19788 = true;
}
if($failed_test_19788 || $failed_test_data){
echo "Bug #19788: failed\n";
} else {
echo "Bug #19788: OK\n";
}
?>

View File

@ -0,0 +1,70 @@
<?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: test_date_methods_span.php,v 1.2 2005/11/15 00:16:40 pajoye Exp $
//
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));
?>

34
Date/tests/testunit.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 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. |
// +----------------------------------------------------------------------+
// | Authors: Marshall Roch <mroch@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: testunit.php,v 1.2 2005/11/15 00:16:40 pajoye Exp $
/**
* Displays all test cases on the same page
*
* @package Date
* @author Marshall Roch <mroch@php.net>
*/
echo "<pre>";
require_once 'PHPUnit.php';
require_once 'testunit_date.php';
require_once 'testunit_date_span.php';
echo "</pre>";
?>

View File

@ -0,0 +1,279 @@
<?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: testunit_date.php,v 1.3 2005/11/15 00:16:40 pajoye Exp $
//
require("../Date.php");
require_once 'PHPUnit.php';
class myDate extends Date {
function myDate($date)
{
$this->Date($date);
}
}
/**
* Test case for Date
*
* @package Date
* @author Marshall Roch <mroch@php.net>
*/
class Date_Test extends PHPUnit_TestCase {
var $time;
function Date_Test($name)
{
$this->PHPUnit_TestCase($name);
}
function setUp()
{
$this->time = new Date("2003-10-04 14:03:24");
}
function tearDown()
{
unset($this->time);
}
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)
);
}
function testAbstraction()
{
$d = new Date();
$my = new myDate($d);
$this->assertEquals($d->getDate(),$my->getDate());
}
function testDateCopy()
{
$temp = new Date($this->time);
$this->assertEquals($temp, $this->time);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
function testDateUnixtime()
{
$temp = new Date(strtotime("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)
);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
function testSetDateUnixtime()
{
$this->time->setDate(strtotime("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)
);
}
function testGetDateISO()
{
$date = $this->time->getDate(DATE_FORMAT_ISO);
$this->assertEquals('2003-10-04 14:03:24', $date);
}
function testGetDateISOBasic()
{
$date = $this->time->getDate(DATE_FORMAT_ISO_BASIC);
$this->assertEquals('20031004T140324Z', $date);
}
function testGetDateISOExtended()
{
$date = $this->time->getDate(DATE_FORMAT_ISO_EXTENDED);
$this->assertEquals('2003-10-04T14:03:24Z', $date);
}
function testGetDateTimestamp()
{
$date = $this->time->getDate(DATE_FORMAT_TIMESTAMP);
$this->assertEquals('20031004140324', $date);
}
function testGetDateUnixtime()
{
$date = $this->time->getDate(DATE_FORMAT_UNIXTIME);
$this->assertEquals(strtotime('2003-10-04 14:03:24'), $date);
}
function testFormat()
{
$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' => '40',
'y' => '03',
'Y' => '2003',
'%' => '%'
);
foreach ($codes as $code => $expected) {
$this->assertEquals(
"$code: $expected", $this->time->format("$code: %$code")
);
}
}
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);
}
}
// runs the tests
$suite = new PHPUnit_TestSuite("Date_Test");
$result = PHPUnit::run($suite);
// prints the tests
echo $result->toString();
?>

View File

@ -0,0 +1,179 @@
<?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: testunit_date_span.php,v 1.4 2005/11/15 00:16:40 pajoye Exp $
//
require_once 'Date.php';
require_once 'Date/Span.php';
require_once 'PHPUnit.php';
/**
* Test case for Date_Span
*
* @package Date
* @author Leandro Lucarella <llucax@php.net>
*/
class Date_SpanTest extends PHPUnit_TestCase {
var $time;
function Date_SpanTest($name) {
$this->PHPUnit_TestCase($name);
}
function setUp() {
$this->time = new Date_Span(97531);
}
function tearDown() {
unset($this->time);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
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)
);
}
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")
);
}
}
function testAdd() {
$this->time->add(new Date_Span(6000));
$result = $this->time->toSeconds();
$expected = 103531;
$this->assertEquals($expected, $result);
}
function testSubtract() {
$this->time->subtract(new Date_Span(6000));
$result = $this->time->toSeconds();
$expected = 91531;
$this->assertEquals($expected, $result);
}
}
// runs the tests
$suite = new PHPUnit_TestSuite("Date_SpanTest");
$result = PHPUnit::run($suite);
// prints the tests
echo $result->toString();
?>