[limb-svn] r6534 - in 3.x/trunk/limb/datetime: src tests/cases
svn at limb-project.com
svn at limb-project.com
Thu Nov 22 10:24:57 MSK 2007
Author: pachanga
Date: 2007-11-22 10:24:57 +0300 (Thu, 22 Nov 2007)
New Revision: 6534
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6534
Removed:
3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php
3.x/trunk/limb/datetime/tests/cases/lmbDatePeriodTest.class.php
3.x/trunk/limb/datetime/tests/cases/lmbTimePeriodTest.class.php
Modified:
3.x/trunk/limb/datetime/src/lmbDate.class.php
3.x/trunk/limb/datetime/src/lmbDatePeriod.class.php
3.x/trunk/limb/datetime/src/lmbDateTime.class.php
3.x/trunk/limb/datetime/src/lmbMonth.class.php
3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
Log:
-- lmbDate is now considered obsolete, it simply extends lmbDateTime
-- lmbDatePeriod and lmbTimePeriod removed - lmbDateTimePeriod should be used instead
Modified: 3.x/trunk/limb/datetime/src/lmbDate.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDate.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/src/lmbDate.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -6,668 +6,17 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/core/src/lmbObject.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
/**
- * class lmbDate.
+ * class lmbDateTime.
*
+ * This class is OBSOLETE, use lmbDateTime instead!
+ *
* @package datetime
* @version $Id$
*/
-class lmbDate extends lmbObject
+class lmbDate extends lmbDateTime
{
- const MINUTE = 60;
- const HOUR = 3600;
- const DAY = 86400;
- const WEEK = 604800;
-
- //YYYY-MM-DD HH:MM:SS timezone
- const DATE_ISO_REGEX = '~^(([0-9]{4})-([0-9]{2})-([0-9]{2}))?((?(1)\s+)([0-9]{2}):([0-9]{2}):?([0-9]{2})?)?$~';
-
- /**
- * Defines what day starts the week.
- * Monday (1) is the international standard, Sunday (0) is used in US.
- * @see setWeekStartsAt()
- */
- static protected $week_starts_at = 1;
-
- protected $year = 0;
- protected $month = 0;
- protected $day = 0;
- protected $hour = 0;
- protected $minute = 0;
- protected $second = 0;
- protected $tz = '';
-
- function __construct($year_or_date=null, $month_or_tz=null, $day=null, $hour=0, $minute=0, $second=0, $tz='')
- {
- if(func_num_args() > 2)
- {
- $this->year = (int)$year_or_date;
- $this->month = (int)$month_or_tz;
- $this->day = (int)$day;
- $this->hour = (int)$hour;
- $this->minute = (int)$minute;
- $this->second = (int)$second;
- $this->tz = $tz;
- }
- elseif(is_a($year_or_date, 'lmbDate'))
- {
- $this->_copy($year_or_date);
- }
- elseif(is_numeric($year_or_date))
- {
- $this->_setByStamp($year_or_date);
- $this->tz = $month_or_tz;
- }
- elseif(is_string($year_or_date))
- {
- $this->_setByString($year_or_date);
- $this->tz = $month_or_tz;
- }
- else
- {
- $this->_setByStamp(time());
- $this->tz = $month_or_tz;
- }
-
- if(!$this->isValid())
- {
- $args = func_get_args();
- throw new lmbException("Could not create date using args", $args);
- }
- }
-
- /**
- * Wrapper around constructor
- *
- * It can be useful since the following is not allowed in PHP 'new lmbDate(..)->addDay(..)->'
- *
- * @param integer $year_or_date
- * @param integer $month_or_tz
- * @param integer $day
- * @param integer $hour
- * @param integer $minute
- * @param integer $second
- * @param string $tz
- * @return lmbDate
- */
- static function create($year_or_date=null, $month_or_tz=null, $day=null, $hour=0, $minute=0, $second=0, $tz='')
- {
- if(func_num_args() > 2)
- return new self($year_or_date, $month_or_tz, $day, $hour, $minute, $second, $tz);
- else
- return new self($year_or_date, $month_or_tz);
- }
-
- static function createByDays($days)
- {
- $days -= 1721119;
- $century = floor((4 * $days - 1) / 146097);
- $days = floor(4 * $days - 1 - 146097 * $century);
- $day = floor($days / 4);
-
- $year = floor((4 * $day + 3) / 1461);
- $day = floor(4 * $day + 3 - 1461 * $year);
- $day = floor(($day + 4) / 4);
-
- $month = floor((5 * $day - 3) / 153);
- $day = floor(5 * $day - 3 - 153 * $month);
- $day = floor(($day + 5) / 5);
-
- if($month < 10)
- {
- $month +=3;
- }
- else
- {
- $month -=9;
- if($year++ == 99)
- {
- $year = 0;
- $century++;
- }
- }
-
- $century = sprintf('%02d', $century);
- $year = sprintf('%02d', $year);
- return new self($century . $year, $month, $day);
- }
-
- static function setWeekStartsAt($n)
- {
- self :: $week_starts_at = $n;
- }
-
- static function getWeekStartsAt()
- {
- return self :: $week_starts_at;
- }
-
- static function stampToIso($stamp)
- {
- $date = new self((int)$stamp);
- return $date->getIsoDate();
- }
-
- static function stampToShortIso($stamp)
- {
- $date = new $class((int)$stamp);
- return $date->getIsoShortDate();
- }
-
- function _createTimeZoneObject($code=null)
- {
- lmb_require('limb/datetime/src/lmbDateTimeZone.class.php');
-
- if(!$code)
- return lmbDateTimeZone::getDefault();
- else
- return new lmbDateTimeZone($code);
- }
-
- function isValid()
- {
- if($this->year < 0) return false;
- if($this->month < 0 || $this->month > 12) return false;
- if($this->day < 0 || $this->day > 31) return false;
- if($this->hour < 0 || $this->hour > 23) return false;
- if($this->minute < 0 || $this->minute > 59) return false;
- if($this->second < 0 || $this->second > 59) return false;
-
- //dirty hack for checkdate...
- return checkdate($this->month ? $this->month : 1,
- $this->day ? $this->day : 1,
- $this->year ? $this->year : 1);
- }
-
- static function validate($year_or_date=null, $month_or_tz=null, $day=null, $hour=0, $minute=0, $second=0, $tz='')
- {
- try
- {
- if(func_num_args() > 2)
- new self($year_or_date, $month_or_tz, $day, $hour, $minute, $second, $tz);
- else
- new self($year_or_date, $month_or_tz);
- return true;
- }
- catch(lmbException $e)
- {
- return false;
- }
- }
-
- protected function _setByString($string)
- {
- if(!preg_match(self :: DATE_ISO_REGEX, trim($string), $regs))
- throw new lmbException("Could not setup date using string '$string'");
-
- if(isset($regs[1]))
- {
- $this->year = (int)$regs[2];
- $this->month = (int)$regs[3];
- $this->day = (int)$regs[4];
- }
-
- if(isset($regs[5]))
- {
- $this->hour = (int)$regs[6];
- $this->minute = (int)$regs[7];
- if(isset($regs[8]))
- $this->second = (int)$regs[8];
- }
- }
-
- protected function _setByStamp($time)
- {
- if(!$arr = @getdate($time))
- throw new lmbException("Could not setup date using stamp'$time'");
-
- $this->year = $arr['year'];
- $this->month = $arr['mon'];
- $this->day = $arr['mday'];
- $this->hour = $arr['hours'];
- $this->minute = $arr['minutes'];
- $this->second = $arr['seconds'];
- }
-
- protected function _copy($date)
- {
- $this->year = $date->getYear();
- $this->month = $date->getMonth();
- $this->day = $date->getDay();
- $this->hour = $date->getHour();
- $this->minute = $date->getMinute();
- $this->second = $date->getSecond();
- $this->tz = $date->getTimeZone();
- }
-
- function getStamp()
- {
- //temporary ugly hack for unspecified year
- if(!$this->year)
- return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day);
- else
- return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
- }
-
- function date($format)
- {
- return date($format, $this->getStamp());
- }
-
- function strftime($format)
- {
- return strftime($format, $this->getStamp());
- }
-
- function getIsoDate($with_seconds = true)
- {
- return sprintf($with_seconds ? '%04d-%02d-%02d %02d:%02d:%02d' : '%04d-%02d-%02d %02d:%02d',
- $this->getYear(), $this->getMonth(), $this->getDay(),
- $this->getHour(), $this->getMinute(), $this->getSecond());
- }
-
- function getIsoShortDate()
- {
- return sprintf('%04d-%02d-%02d',
- $this->getYear(), $this->getMonth(), $this->getDay());
- }
-
- function getIsoTime($with_seconds = true)
- {
- return sprintf($with_seconds ? '%02d:%02d:%02d' : '%02d:%02d',
- $this->getHour(), $this->getMinute(), $this->getSecond());
- }
-
- function getIsoShortTime()
- {
- return $this->getIsoTime(false);
- }
-
- function toString()
- {
- return $this->getIsoDate();
- }
-
- function isInDaylightTime()
- {
- return $this->getTimeZoneObject()->inDaylightTime($this);
- }
-
- function toUTC()
- {
- $tz = $this->getTimeZoneObject();
-
- if($tz->getOffset($this) > 0)
- $date = $this->addSecond(-1 * intval($tz->getOffset($this) / 1000));
- else
- $date = $this->addSecond(intval(abs($tz->getOffset($this)) / 1000));
-
- return $date->setTimeZone('UTC');
- }
-
- /**
- * Compares object with $d date object.
- * return int 0 if the dates are equal, -1 if is before, 1 if is after than $d
- */
- function compare($d)
- {
- if(!$d instanceof lmbDate)
- throw new lmbException("Wrong date argument", array('arg' => $d));
-
- $s1 = $this->getStamp();
- $s2 = $d->getStamp();
-
- if($s1 > $s2)
- return 1;
- elseif($s2 > $s1)
- return -1;
- else
- return 0;
- }
-
- function isBefore($when, $use_time_zone=false)
- {
- if($this->compare($when, $use_time_zone) == -1)
- return true;
- else
- return false;
- }
-
- function isAfter($when, $use_time_zone=false)
- {
- if($this->compare($when, $use_time_zone) == 1)
- return true;
- else
- return false;
- }
-
- function isEqual($when, $use_time_zone=false)
- {
- if($this->compare($when, $use_time_zone) == 0)
- return true;
- else
- return false;
- }
-
- function isEqualDate($when)
- {
- return $this->stripTime()->isEqual($when->stripTime());
- }
-
- function isLeapYear()
- {
- return (($this->year % 4 == 0 && $this->year % 100 != 0) || $this->year % 400 == 0);
- }
-
- function getDayOfYear()
- {
- $days = array(0,31,59,90,120,151,181,212,243,273,304,334);
-
- $julian = ($days[$this->month - 1] + $this->day);
-
- if($this->month > 2 && $this->isLeapYear())
- $julian++;
-
- return $julian;
- }
-
- function getDayOfWeek()
- {
- return $this->_correctDayOfWeek($this->getPhpDayOfWeek(), self :: $week_starts_at);
- }
-
- function getIntlDayOfWeek()
- {
- return $this->_correctDayOfWeek($this->getPhpDayOfWeek(), 1);
- }
-
- function getPhpDayOfWeek()
- {
- $year = $this->year;
- $month = $this->month;
- $day = $this->day;
-
- if(1901 < $year && $year < 2038)
- return (int)date('w', mktime(0, 0, 0, $month, $day, $year));
-
- if($month > 2)
- {
- $month -= 2;
- }
- else
- {
- $month += 10;
- $year--;
- }
-
- $day = (floor((13 * $month - 1) / 5) +
- $day + ($year % 100) +
- floor(($year % 100) / 4) +
- floor(($year / 100) / 4) - 2 *
- floor($year / 100) + 77);
-
- return $day - 7 * floor($day / 7);
- }
-
- protected function _correctDayOfWeek($dow, $week_starts_at)
- {
- if($week_starts_at == 0)
- return $dow;
-
- if($dow == 0)
- return 6;
- return $dow - 1;
- }
-
- function getBeginOfDay()
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, $this->tz);
- }
-
- function getEndOfDay()
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, 23, 59, 59, $this->tz);
- }
-
- function getBeginOfWeek()
- {
- $this_weekday = $this->getPhpDayOfWeek();
- $interval = (7 - self :: $week_starts_at + $this_weekday) % 7;
- return lmbDate :: createByDays($this->getDateDays() - $interval);
- }
-
- function getEndOfWeek()
- {
- $this_weekday = $this->getPhpDayOfWeek();
- $interval = (6 + self :: $week_starts_at - $this_weekday) % 7;
- return lmbDate :: createByDays($this->getDateDays() + $interval);
- }
-
- function getBeginOfMonth()
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, 1, $this->tz);
- }
-
- function getEndOfMonth()
- {
- return $this->setDay(1)->addMonth(1)->addDay(-1)->getEndOfDay();
- }
-
- function getBeginOfYear()
- {
- $class = get_class($this);
- return new $class($this->year, 1, 1, $this->tz);
- }
-
- function getEndOfYear()
- {
- $class = get_class($this);
- return new $class($this->year, 12, 31, 23, 59, 59, $this->tz);
- }
-
- function getWeekOfYear()
- {
- $day = $this->day;
- $month = $this->month;
- $year = $this->year;
-
- if((1901 < $year) && ($year < 2038))
- {
- $res = (int)date('W', mktime(0, 0, 0, $month, $day, $year));
- if($res > 52) //bug in PHP date???
- return $res % 52;
- return $res;
- }
-
- $dayofweek = $this->getPhpDayOfWeek();
- $firstday = self :: create($year, 1, 1)->getPhpDayOfWeek();
- if(($month == 1) && (($firstday < 1) || ($firstday > 4)) && ($day < 4))
- {
- $firstday = self :: create($year - 1, 1, 1)->getPhpDayOfWeek();
- $month = 12;
- $day = 31;
- }
- elseif(($month == 12) && ((self :: create($year + 1, 1, 1)->getPhpDayOfWeek() < 5) &&
- (self :: create($year + 1, 1, 1)->getPhpDayOfWeek() > 0)))
- return 1;
-
- return intval(((self :: create($year, 1, 1)->getPhpDayOfWeek() < 5) && (self :: create($year, 1, 1)->getPhpDayOfWeek() > 0)) +
- 4 * ($month - 1) + (2 * ($month - 1) + ($day - 1) + $firstday - $dayofweek + 6) * 36 / 256);
- }
-
- function getDateDays()
- {
- $century = (int)substr("{$this->year}", 0, 2);
- $year = (int)substr("{$this->year}", 2, 2);
- $month = $this->month;
- $day = $this->day;
-
- if($month > 2)
- $month -= 3;
- else
- {
- $month += 9;
- if($year)
- $year--;
- else
- {
- $year = 99;
- $century --;
- }
- }
- return (
- floor((146097 * $century) / 4) +
- floor((1461 * $year) / 4) +
- floor((153 * $month + 2) / 5) +
- $day + 1721119);
- }
-
- function getYear()
- {
- return $this->year;
- }
-
- function getMonth()
- {
- return $this->month;
- }
-
- function getDay()
- {
- return $this->day;
- }
-
- function getHour()
- {
- return $this->hour;
- }
-
- function getMinute()
- {
- return $this->minute;
- }
-
- function getSecond()
- {
- return $this->second;
- }
-
- function getTimeZoneObject()
- {
- return $this->_createTimeZoneObject($this->tz);
- }
-
- function getTimeZone()
- {
- return $this->tz;
- }
-
- function setYear($y)
- {
- $class = get_class($this);
- return new $class($y, $this->month, $this->day, $this->hour, $this->minute, $this->second, $this->tz);
- }
-
- function setMonth($m)
- {
- $class = get_class($this);
- return new $class($this->year, $m, $this->day, $this->hour, $this->minute, $this->second, $this->tz);
- }
-
- function setDay($d)
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $d, $this->hour, $this->minute, $this->second, $this->tz);
- }
-
- function setHour($h)
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, $h, $this->minute, $this->second, $this->tz);
- }
-
- function setMinute($m)
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, $this->hour, $m, $this->second, $this->tz);
- }
-
- function setSecond($s)
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, $this->hour, $this->minute, $s, $this->tz);
- }
-
- function setTimeZone($tz)
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second, $tz);
- }
-
- function addYear($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year + $n));
- return $date->setTimeZone($this->tz);
- }
-
- function addMonth($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute, $this->second, $this->month + $n, $this->day, $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function addWeek($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute, $this->second, $this->month, $this->day + ($n * 7), $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function addDay($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute, $this->second, $this->month, $this->day + $n, $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function addHour($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour + $n, $this->minute, $this->second, $this->month, $this->day, $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function addMinute($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute + $n, $this->second, $this->month, $this->day, $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function addSecond($n=1)
- {
- $class = get_class($this);
- $date = new $class(mktime($this->hour, $this->minute, $this->second + $n, $this->month, $this->day, $this->year));
- return $date->setTimeZone($this->tz);
- }
-
- function stripTime()
- {
- $class = get_class($this);
- return new $class($this->year, $this->month, $this->day, 0, 0, 0, $this->tz);
- }
-
- function stripDate()
- {
- $class = get_class($this);
- return new $class(null, null, null, $this->hour, $this->minute, $this->second, $this->tz);
- }
}
Modified: 3.x/trunk/limb/datetime/src/lmbDatePeriod.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDatePeriod.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/src/lmbDatePeriod.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -6,7 +6,7 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
lmb_require('limb/core/src/exception/lmbException.class.php');
/**
@@ -22,8 +22,8 @@
function __construct($start, $end)
{
- $this->start = (is_object($start)) ? $start : new lmbDate($start);
- $this->end = (is_object($end)) ? $end : new lmbDate($end);
+ $this->start = (is_object($start)) ? $start : new lmbDateTime($start);
+ $this->end = (is_object($end)) ? $end : new lmbDateTime($end);
if($this->end->isBefore($this->start))
throw new lmbException('Wrong period interval', array('start' => $this->start->toString(),
Modified: 3.x/trunk/limb/datetime/src/lmbDateTime.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDateTime.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/src/lmbDateTime.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -12,7 +12,7 @@
* class lmbDateTime.
*
* @package datetime
- * @version $Id: lmbDate.class.php 6532 2007-11-20 15:55:48Z serega $
+ * @version $Id: lmbDateTime.class.php 6532 2007-11-20 15:55:48Z serega $
*/
class lmbDateTime extends lmbObject
{
Modified: 3.x/trunk/limb/datetime/src/lmbMonth.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbMonth.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/src/lmbMonth.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -6,7 +6,7 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
/**
* class lmbMonth.
@@ -22,11 +22,11 @@
function __construct($year_or_date = null, $month = null)
{
if($year_or_date && $month)
- $tmp_date = new lmbDate($year_or_date, $month, 1);
+ $tmp_date = new lmbDateTime($year_or_date, $month, 1);
elseif($year_or_date && !$month)
- $tmp_date = new lmbDate($year_or_date);
+ $tmp_date = new lmbDateTime($year_or_date);
else
- $tmp_date = new lmbDate();
+ $tmp_date = new lmbDateTime();
$this->start_date = $tmp_date->getBeginOfMonth();
$this->end_date = $tmp_date->getEndOfMonth();
@@ -71,19 +71,19 @@
{
$dow = $this->start_date->getPhpDayOfWeek();
- if(lmbDate :: getWeekStartsAt() == 1 && $dow == 0)
+ if(lmbDateTime :: getWeekStartsAt() == 1 && $dow == 0)
{
- $first_week_days = 7 - $dow + lmbDate :: getWeekStartsAt();
+ $first_week_days = 7 - $dow + lmbDateTime :: getWeekStartsAt();
$weeks = 1;
}
- elseif(lmbDate :: getWeekStartsAt() == 0 && $dow == 6)
+ elseif(lmbDateTime :: getWeekStartsAt() == 0 && $dow == 6)
{
- $first_week_days = 7 - $dow + lmbDate :: getWeekStartsAt();
+ $first_week_days = 7 - $dow + lmbDateTime :: getWeekStartsAt();
$weeks = 1;
}
else
{
- $first_week_days = lmbDate :: getWeekStartsAt() - $dow;
+ $first_week_days = lmbDateTime :: getWeekStartsAt() - $dow;
$weeks = 0;
}
@@ -101,7 +101,7 @@
for($i=0;$i<=6;$i++)
{
- $week_array[$i] = lmbDate :: createByDays($curr_day);
+ $week_array[$i] = lmbDateTime :: createByDays($curr_day);
$curr_day++;
}
return $week_array;
Deleted: 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -1,45 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/datetime/src/lmbDateTime.class.php');
-lmb_require('limb/datetime/src/lmbDateTimePeriod.class.php');
-
-/**
- * class lmbTimePeriod.
- *
- * @package datetime
- * @version $Id$
- */
-class lmbTimePeriod extends lmbDateTimePeriod
-{
- function __construct($start, $end)
- {
- $start_date = new lmbDateTime($start);
- $end_date = new lmbDateTime($end);
-
- parent :: __construct($start_date->stripDate(), $end_date->stripDate());
- }
-
- function getDatePeriod($date)
- {
- $date = new lmbDateTime($date);
- $year = $date->getYear();
- $month = $date->getMonth();
- $day = $date->getDay();
-
- $start_date = new lmbDateTime($year, $month, $day,
- $this->start->getHour(), $this->start->getMinute(), $this->start->getSecond());
-
- $end_date = new lmbDateTime($year, $month, $day,
- $this->end->getHour(), $this->end->getMinute(), $this->end->getSecond());
-
- return new lmbDateTimePeriod($start_date, $end_date);
- }
-}
-
-
Deleted: 3.x/trunk/limb/datetime/tests/cases/lmbDatePeriodTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbDatePeriodTest.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbDatePeriodTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -1,71 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/datetime/src/lmbDatePeriod.class.php');
-
-class lmbDatePeriodTest extends UnitTestCase
-{
- function testInvalidPeriod()
- {
- try
- {
- $period = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:45:10');
- $this->assertTrue(false);
- }
- catch(lmbException $e){}
- }
-
- function testToString()
- {
- $p = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
- $this->assertEqual($p->toString(), '2005-12-01 13:45:12 - 2005-12-01 13:46:00');
- }
-
- function testGetDuration()
- {
- $p = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
- $this->assertEqual($p->getDuration(), 48);
- }
-
- function testIsEqual()
- {
- $p1 = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
- $p2 = new lmbDatePeriod('2006-12-01 13:45:12', '2006-12-01 13:46:00');
-
- $this->assertTrue($p1->isEqual($p1));
- $this->assertFalse($p1->isEqual($p2));
- }
-
- function testIsInside()
- {
- $child = new lmbDatePeriod('2005-12-01 13:45:12', '2005-12-01 13:46:00');
- $parent = new lmbDatePeriod('2005-12-01 10:00:00', '2005-12-01 14:01:00');
- $intersect = new lmbDatePeriod('2005-12-01 11:00:00', '2005-12-01 15:01:00');
-
- $this->assertTrue($child->isInside($parent));
- $this->assertTrue($parent->includes($child));
- $this->assertFalse($parent->includes($intersect));
- }
-
- function testIntersects()
- {
- $period1 = new lmbDatePeriod("2005-09-05 14:40:00", "2005-09-05 14:41:50");
- $period2 = new lmbDatePeriod("2005-09-05 14:39:00", "2005-09-05 14:41:00");
- $period3 = new lmbDatePeriod("2006-09-05 14:39:00", "2006-09-05 14:41:00");
-
- $this->assertTrue($period1->intersects($period1));
-
- $this->assertTrue($period1->intersects($period2));
- $this->assertTrue($period2->intersects($period1));
-
- $this->assertFalse($period1->intersects($period3));
- $this->assertFalse($period3->intersects($period1));
- }
-}
-
-
Modified: 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -6,10 +6,10 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
lmb_require('limb/datetime/src/lmbDateTimeZone.class.php');
-class FooDate extends lmbDate {}
+class FooDate extends lmbDateTime {}
class lmbDateTest extends UnitTestCase
{
@@ -17,7 +17,7 @@
{
try
{
- $date = new lmbDate(400, 500, 5000, 9000);
+ $date = new lmbDateTime(400, 500, 5000, 9000);
$this->assertTrue(false);
}
catch(lmbException $e){}
@@ -25,7 +25,7 @@
function testNegativeStamp()
{
- $date = new lmbDate(-564634800);
+ $date = new lmbDateTime(-564634800);
$this->assertEqual($date->getDay(), 10);
$this->assertEqual($date->getMonth(), 2);
$this->assertEqual($date->getYear(), 1952);
@@ -35,7 +35,7 @@
{
try
{
- $date = new lmbDate('baba-duba');
+ $date = new lmbDateTime('baba-duba');
$this->assertTrue(false);
}
catch(lmbException $e){}
@@ -43,25 +43,25 @@
function testValidate()
{
- $this->assertTrue(lmbDate :: validate('2005-12-01 12:45:12'));
- $this->assertTrue(lmbDate :: validate('2005-12-01 12:45'));
- $this->assertTrue(lmbDate :: validate('2005-12-01'));
- $this->assertTrue(lmbDate :: validate('12:45:12'));
- $this->assertTrue(lmbDate :: validate('12:45'));
- $this->assertTrue(lmbDate :: validate(' 12:45:12 '));
+ $this->assertTrue(lmbDateTime :: validate('2005-12-01 12:45:12'));
+ $this->assertTrue(lmbDateTime :: validate('2005-12-01 12:45'));
+ $this->assertTrue(lmbDateTime :: validate('2005-12-01'));
+ $this->assertTrue(lmbDateTime :: validate('12:45:12'));
+ $this->assertTrue(lmbDateTime :: validate('12:45'));
+ $this->assertTrue(lmbDateTime :: validate(' 12:45:12 '));
}
function testValidateFalse()
{
- $this->assertFalse(lmbDate :: validate('baba-duba'));
- $this->assertFalse(lmbDate :: validate('2005-12-01 12.'));
- $this->assertFalse(lmbDate :: validate(2006, 13, 11));
+ $this->assertFalse(lmbDateTime :: validate('baba-duba'));
+ $this->assertFalse(lmbDateTime :: validate('2005-12-01 12.'));
+ $this->assertFalse(lmbDateTime :: validate(2006, 13, 11));
}
function testCreate()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
- $this->assertEqual(lmbDate :: create(2005, 12, 1, 12, 45, 12), $date);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
+ $this->assertEqual(lmbDateTime :: create(2005, 12, 1, 12, 45, 12), $date);
$this->assertEqual($date->getDay(), 1);
$this->assertEqual($date->getMonth(), 12);
@@ -73,70 +73,70 @@
function testGetIsoDate()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoDate(), '2005-12-01 12:45:12');
}
function testGetIsoDateWithoutSeconds()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoDate(false), '2005-12-01 12:45');
}
function testGetIsoShortDate()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoShortDate(), '2005-12-01');
}
function testGetIsoTime()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoTime(), '12:45:12');
}
function testGetIsoTimeWithoutSeconds()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoTime(false), '12:45');
}
function testGetIsoShortTimeWithoutSeconds()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->getIsoShortTime(), '12:45');
}
function testToStringReturnsIsoDate()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->toString(), '2005-12-01 12:45:12');
}
function testStrftime()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->strftime('%m/%d/%y'), '12/01/05');
}
function testDate()
{
- $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+ $date = new lmbDateTime(2005, 12, 1, 12, 45, 12);
$this->assertEqual($date->date('m.d.y'), '12.01.05');
}
function testCreateByCopy()
{
- $date = new lmbDate($sample = new lmbDate(2005, 12, 1, 12, 45, 12));
- $this->assertEqual(lmbDate :: create($sample), $date);
+ $date = new lmbDateTime($sample = new lmbDateTime(2005, 12, 1, 12, 45, 12));
+ $this->assertEqual(lmbDateTime :: create($sample), $date);
$this->assertEqual($date, $sample);
}
function testCreateByIso()
{
- $date = new lmbDate('2005-12-01 12:45:12');
- $this->assertEqual(lmbDate :: create('2005-12-01 12:45:12'), $date);
+ $date = new lmbDateTime('2005-12-01 12:45:12');
+ $this->assertEqual(lmbDateTime :: create('2005-12-01 12:45:12'), $date);
$this->assertEqual($date->getDay(), 1);
$this->assertEqual($date->getMonth(), 12);
@@ -150,8 +150,8 @@
function testCreateByIsoDateOnly()
{
- $date = new lmbDate('2005-12-01');
- $this->assertEqual(lmbDate :: create('2005-12-01'), $date);
+ $date = new lmbDateTime('2005-12-01');
+ $this->assertEqual(lmbDateTime :: create('2005-12-01'), $date);
$this->assertEqual($date->getDay(), 1);
$this->assertEqual($date->getMonth(), 12);
@@ -165,8 +165,8 @@
function testCreateByIsoTimeOnly()
{
- $date = new lmbDate('12:45:12');
- $this->assertEqual(lmbDate :: create('12:45:12'), $date);
+ $date = new lmbDateTime('12:45:12');
+ $this->assertEqual(lmbDateTime :: create('12:45:12'), $date);
$this->assertEqual($date->getDay(), 0);
$this->assertEqual($date->getMonth(), 0);
@@ -180,8 +180,8 @@
function testCreateByIsoTimeWithSecondsOmitted()
{
- $date = new lmbDate('12:45');
- $this->assertEqual(lmbDate :: create('12:45'), $date);
+ $date = new lmbDateTime('12:45');
+ $this->assertEqual(lmbDateTime :: create('12:45'), $date);
$this->assertEqual($date->getDay(), 0);
$this->assertEqual($date->getMonth(), 0);
@@ -196,14 +196,14 @@
function testStampToIso()
{
$stamp = mktime(21, 45, 13, 12, 1, 2005);
- $iso = lmbDate :: stampToIso($stamp);
+ $iso = lmbDateTime :: stampToIso($stamp);
$this->assertEqual($iso, '2005-12-01 21:45:13');
}
function testCreateByStamp()
{
- $date = new lmbDate($stamp = mktime(21, 45, 13, 12, 1, 2005));
- $this->assertEqual(lmbDate :: create($stamp), $date);
+ $date = new lmbDateTime($stamp = mktime(21, 45, 13, 12, 1, 2005));
+ $this->assertEqual(lmbDateTime :: create($stamp), $date);
$this->assertEqual($date->getDay(), 1);
$this->assertEqual($date->getMonth(), 12);
@@ -217,50 +217,50 @@
function testCreateByDays()
{
- $date = new lmbDate('2005-12-01');
+ $date = new lmbDateTime('2005-12-01');
$days = $date->getDateDays();
- $this->assertEqual(lmbDate :: createByDays($days), $date);
+ $this->assertEqual(lmbDateTime :: createByDays($days), $date);
}
function testGetStamp()
{
- $date = new lmbDate($stamp = mktime(21, 45, 13, 12, 1, 2005));
+ $date = new lmbDateTime($stamp = mktime(21, 45, 13, 12, 1, 2005));
$this->assertEqual($date->getStamp(), $stamp);
}
function testGetPhpDayOfWeekForSunday()
{
- $date = new lmbDate('2005-01-16');
+ $date = new lmbDateTime('2005-01-16');
$this->assertEqual($date->getPhpDayOfWeek(), 0);
}
function testGetIntlDayOfWeekForSunday()
{
- $date = new lmbDate('2005-01-16');
+ $date = new lmbDateTime('2005-01-16');
$this->assertEqual($date->getIntlDayOfWeek(), 6);
}
function testGetPhpDayOfWeekForMonday()
{
- $date = new lmbDate('2005-01-17');
+ $date = new lmbDateTime('2005-01-17');
$this->assertEqual($date->getPhpDayOfWeek(), 1);
}
function testGetIntlDayOfWeekForMonday()
{
- $date = new lmbDate('2005-01-17');
+ $date = new lmbDateTime('2005-01-17');
$this->assertEqual($date->getIntlDayOfWeek(), 0);
}
function testGetPhpDayOfWeekForSuturday()
{
- $date = new lmbDate('2005-01-15');
+ $date = new lmbDateTime('2005-01-15');
$this->assertEqual($date->getPhpDayOfWeek(), 6);
}
function testGetIntlDayOfWeekForSuturday()
{
- $date = new lmbDate('2005-01-15');
+ $date = new lmbDateTime('2005-01-15');
$this->assertEqual($date->getIntlDayOfWeek(), 5);
}
@@ -268,91 +268,91 @@
//for day of the week which happens in February
function testGetPhpDayOfWeekMonthBeforeFebruary()
{
- $date = new lmbDate('2005-01-20');
+ $date = new lmbDateTime('2005-01-20');
$this->assertEqual($date->getPhpDayOfWeek(), 4);
}
function testGetPhpDayOfWeekMonthAfterFebruary()
{
- $date = new lmbDate('2005-08-20');
+ $date = new lmbDateTime('2005-08-20');
$this->assertEqual($date->getPhpDayOfWeek(), 6);
}
function testGetBeginOfDay()
{
- $date = new lmbDate('2005-08-20 12:24:12');
- $this->assertEqual($date->getBeginOfDay(), new lmbDate('2005-08-20 00:00:00'));
+ $date = new lmbDateTime('2005-08-20 12:24:12');
+ $this->assertEqual($date->getBeginOfDay(), new lmbDateTime('2005-08-20 00:00:00'));
}
function testGetEndOfDay()
{
- $date = new lmbDate('2005-08-20 12:24:12');
- $this->assertEqual($date->getEndOfDay(), new lmbDate('2005-08-20 23:59:59'));
+ $date = new lmbDateTime('2005-08-20 12:24:12');
+ $this->assertEqual($date->getEndOfDay(), new lmbDateTime('2005-08-20 23:59:59'));
}
function testGetBeginOfWeek()
{
- $date = new lmbDate('2005-01-20');
- $this->assertEqual($date->getBeginOfWeek(), new lmbDate('2005-01-17'));
+ $date = new lmbDateTime('2005-01-20');
+ $this->assertEqual($date->getBeginOfWeek(), new lmbDateTime('2005-01-17'));
}
function testGetBeginOfWeekForMonday()
{
- $date = new lmbDate('2005-01-17');
- $this->assertEqual($date->getBeginOfWeek(), new lmbDate('2005-01-17'));
+ $date = new lmbDateTime('2005-01-17');
+ $this->assertEqual($date->getBeginOfWeek(), new lmbDateTime('2005-01-17'));
}
function testGetBeginOfWeekForSunday()
{
- $date = new lmbDate('2005-01-16');
- $this->assertEqual($date->getBeginOfWeek(), new lmbDate('2005-01-10'));
+ $date = new lmbDateTime('2005-01-16');
+ $this->assertEqual($date->getBeginOfWeek(), new lmbDateTime('2005-01-10'));
}
function testGetEndOfWeek()
{
- $date = new lmbDate('2005-01-20');
- $this->assertEqual($date->getEndOfWeek(), new lmbDate('2005-01-23'));
+ $date = new lmbDateTime('2005-01-20');
+ $this->assertEqual($date->getEndOfWeek(), new lmbDateTime('2005-01-23'));
}
function testGetEndOfWeekForMonday()
{
- $date = new lmbDate('2005-01-17');
- $this->assertEqual($date->getEndOfWeek(), new lmbDate('2005-01-23'));
+ $date = new lmbDateTime('2005-01-17');
+ $this->assertEqual($date->getEndOfWeek(), new lmbDateTime('2005-01-23'));
}
function testGetEndOfWeekForSunday()
{
- $date = new lmbDate('2005-01-16');
- $this->assertEqual($date->getEndOfWeek(), new lmbDate('2005-01-16'));
+ $date = new lmbDateTime('2005-01-16');
+ $this->assertEqual($date->getEndOfWeek(), new lmbDateTime('2005-01-16'));
}
function testGetBeginOfMonth()
{
- $date = new lmbDate('2005-08-20 12:24:12');
- $this->assertEqual($date->getBeginOfMonth(), new lmbDate('2005-08-01 00:00:00'));
+ $date = new lmbDateTime('2005-08-20 12:24:12');
+ $this->assertEqual($date->getBeginOfMonth(), new lmbDateTime('2005-08-01 00:00:00'));
}
function testGetEndOfMonth()
{
- $date = new lmbDate('2007-05-09 12:24:12');
- $this->assertEqual($date->getEndOfMonth(), new lmbDate('2007-05-31 23:59:59'));
+ $date = new lmbDateTime('2007-05-09 12:24:12');
+ $this->assertEqual($date->getEndOfMonth(), new lmbDateTime('2007-05-31 23:59:59'));
}
function testGetBeginOfYear()
{
- $date = new lmbDate('2005-08-20 12:24:12');
- $this->assertEqual($date->getBeginOfYear(), new lmbDate('2005-01-01 00:00:00'));
+ $date = new lmbDateTime('2005-08-20 12:24:12');
+ $this->assertEqual($date->getBeginOfYear(), new lmbDateTime('2005-01-01 00:00:00'));
}
function testGetEndOfYear()
{
- $date = new lmbDate('2007-05-09 12:24:12');
- $this->assertEqual($date->getEndOfYear(), new lmbDate('2007-12-31 23:59:59'));
+ $date = new lmbDateTime('2007-05-09 12:24:12');
+ $this->assertEqual($date->getEndOfYear(), new lmbDateTime('2007-12-31 23:59:59'));
}
function testSetYear()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setYear(2006);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2006-01-01 00:00:00');
@@ -360,7 +360,7 @@
function testSetMonth()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setMonth(2);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-02-01 00:00:00');
@@ -368,7 +368,7 @@
function testSetDay()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setDay(2);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-01-02 00:00:00');
@@ -376,7 +376,7 @@
function testSetHour()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setHour(2);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-01-01 02:00:00');
@@ -384,7 +384,7 @@
function testSetMinute()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setMinute(2);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-01-01 00:02:00');
@@ -392,7 +392,7 @@
function testSetSecond()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setSecond(20);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-01-01 00:00:20');
@@ -400,7 +400,7 @@
function TODO_testSetWeek()
{
- $date = new lmbDate('2005-01-01');
+ $date = new lmbDateTime('2005-01-01');
$new_date = $date->setWeek(2);
$this->assertEqual($date->toString(), '2005-01-01 00:00:00');
$this->assertEqual($new_date->toString(), '2005-01-08 00:00:00');//???
@@ -408,7 +408,7 @@
function testSetTimeZone()
{
- $date = new lmbDate('2005-01-01', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-01-01', 'Europe/Moscow');
$new_date = $date->setTimeZone('UTC');
$this->assertEqual($date->getTimeZone(), 'Europe/Moscow');
$this->assertEqual($new_date->getTimeZone(), 'UTC');
@@ -416,7 +416,7 @@
function testAddYear()
{
- $date = lmbDate :: create('2005-01-01')->addYear();
+ $date = lmbDateTime :: create('2005-01-01')->addYear();
$new_date = $date->addYear(-3);
$this->assertEqual($date->toString(), '2006-01-01 00:00:00');
@@ -425,7 +425,7 @@
function testAddMonth()
{
- $date = lmbDate :: create('2005-01-01')->addMonth();
+ $date = lmbDateTime :: create('2005-01-01')->addMonth();
$new_date = $date->addMonth(-2);
$this->assertEqual($date->toString(), '2005-02-01 00:00:00');
$this->assertEqual($new_date->toString(), '2004-12-01 00:00:00');
@@ -433,7 +433,7 @@
function testAddWeek()
{
- $date = lmbDate :: create('2005-01-01')->addWeek();
+ $date = lmbDateTime :: create('2005-01-01')->addWeek();
$new_date = $date->addWeek(-3);
$this->assertEqual($date->toString(), '2005-01-08 00:00:00');
$this->assertEqual($new_date->toString(), '2004-12-18 00:00:00');
@@ -441,7 +441,7 @@
function testAddDay()
{
- $date = lmbDate :: create('2005-01-01')->addDay();
+ $date = lmbDateTime :: create('2005-01-01')->addDay();
$new_date = $date->addDay(-33);
$this->assertEqual($date->toString(), '2005-01-02 00:00:00');
$this->assertEqual($new_date->toString(), '2004-11-30 00:00:00');
@@ -449,7 +449,7 @@
function testAddHour()
{
- $date = lmbDate :: create('2005-01-01')->addHour();
+ $date = lmbDateTime :: create('2005-01-01')->addHour();
$new_date = $date->addHour(-3);
$this->assertEqual($date->toString(), '2005-01-01 01:00:00');
$this->assertEqual($new_date->toString(), '2004-12-31 22:00:00');
@@ -457,7 +457,7 @@
function testAddMinute()
{
- $date = lmbDate :: create('2005-01-01')->addMinute();
+ $date = lmbDateTime :: create('2005-01-01')->addMinute();
$new_date = $date->addMinute(-3);
$this->assertEqual($date->toString(), '2005-01-01 00:01:00');
$this->assertEqual($new_date->toString(), '2004-12-31 23:58:00');
@@ -465,7 +465,7 @@
function testAddSecond()
{
- $date = lmbDate :: create('2005-01-01')->addSecond();
+ $date = lmbDateTime :: create('2005-01-01')->addSecond();
$new_date = $date->addSecond(-61);
$this->assertEqual($date->toString(), '2005-01-01 00:00:01');
$this->assertEqual($new_date->toString(), '2004-12-31 23:59:00');
@@ -473,103 +473,103 @@
function testAddMixed()
{
- $date = lmbDate :: create('2005-01-01')->addMonth()->addWeek(-1)->addDay(2)->addHour(2)->addSecond(-30)->addMinute(2);
+ $date = lmbDateTime :: create('2005-01-01')->addMonth()->addWeek(-1)->addDay(2)->addHour(2)->addSecond(-30)->addMinute(2);
$this->assertEqual($date->toString(), '2005-01-27 02:01:30');
}
function testCreateWithTZ()
{
- $date = new lmbDate(2005, 5, 3, 12, 10, 5, 'Europe/Moscow');
+ $date = new lmbDateTime(2005, 5, 3, 12, 10, 5, 'Europe/Moscow');
$tz = $date->getTimeZoneObject();
$this->assertEqual($tz, new lmbDateTimeZone('Europe/Moscow'));
}
function testCreateWithInvalidTZ()
{
- $date = new lmbDate(2005, 5, 3, 12, 10, 5, 'bla-bla');
+ $date = new lmbDateTime(2005, 5, 3, 12, 10, 5, 'bla-bla');
$tz = $date->getTimeZoneObject();
$this->assertEqual($tz, new lmbDateTimeZone('UTC'));
}
function testCreateTZByDateString()
{
- $date = new lmbDate('2005-01-01', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-01-01', 'Europe/Moscow');
$tz = $date->getTimeZoneObject();
$this->assertEqual($tz, new lmbDateTimeZone('Europe/Moscow'));
}
function testCreateTZByDateTimeString()
{
- $date = new lmbDate('2005-01-01 12:20:40', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-01-01 12:20:40', 'Europe/Moscow');
$tz = $date->getTimeZoneObject();
$this->assertEqual($tz, new lmbDateTimeZone('Europe/Moscow'));
}
function testIgnoreTZWhileCloning()
{
- $date = new lmbDate(new lmbDate('2005-01-01 12:20:40', 'Europe/Moscow'), 'ya-hooo');
+ $date = new lmbDateTime(new lmbDateTime('2005-01-01 12:20:40', 'Europe/Moscow'), 'ya-hooo');
$tz = $date->getTimeZoneObject();
$this->assertEqual($tz, new lmbDateTimeZone('Europe/Moscow'));
}
function testToUTC()
{
- $date = new lmbDate('2005-06-01 12:20:40', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-06-01 12:20:40', 'Europe/Moscow');
$new_date = $date->toUTC();
$this->assertEqual($new_date->toString(), '2005-06-01 08:20:40');
}
function testToUTCWithDayLightSaving()
{
- $date = new lmbDate('2005-01-01 12:20:40', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-01-01 12:20:40', 'Europe/Moscow');
$new_date = $date->toUTC();
$this->assertEqual($new_date->toString(), '2005-01-01 09:20:40');
}
function testIsInDaylightTime()
{
- $date = new lmbDate('2005-01-01 12:20:40', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-01-01 12:20:40', 'Europe/Moscow');
$this->assertFalse($date->isInDaylightTime());
- $date = new lmbDate('2005-06-01 12:20:40', 'Europe/Moscow');
+ $date = new lmbDateTime('2005-06-01 12:20:40', 'Europe/Moscow');
$this->assertTrue($date->isInDaylightTime());
}
function testIsLeapYear()
{
- $date = new lmbDate('2005-01-01 12:20:40');
+ $date = new lmbDateTime('2005-01-01 12:20:40');
$this->assertFalse($date->isLeapYear());
- $date = new lmbDate('2004-01-01 12:20:40');
+ $date = new lmbDateTime('2004-01-01 12:20:40');
$this->assertTrue($date->isLeapYear());
}
function testGetDayOfYear()
{
- $date = new lmbDate('2005-01-01 12:20:40');
+ $date = new lmbDateTime('2005-01-01 12:20:40');
$this->assertEqual($date->getDayOfYear(), 1);
- $date = new lmbDate('2005-12-31 12:20:40');
+ $date = new lmbDateTime('2005-12-31 12:20:40');
$this->assertEqual($date->getDayOfYear(), 365);
}
function testGetWeekOfYear()
{
- $date = new lmbDate('2005-01-01 12:20:40');
+ $date = new lmbDateTime('2005-01-01 12:20:40');
$this->assertEqual($date->getWeekOfYear(), 1);
- $date = new lmbDate('2005-01-06 12:20:40');
+ $date = new lmbDateTime('2005-01-06 12:20:40');
$this->assertEqual($date->getWeekOfYear(), 1);
- $date = new lmbDate('2005-12-31 12:20:40');
+ $date = new lmbDateTime('2005-12-31 12:20:40');
$this->assertEqual($date->getWeekOfYear(), 52);
}
function testCompare()
{
- $d1 = new lmbDate('2005-01-01');
- $d2 = new lmbDate('2005-01-01');
+ $d1 = new lmbDateTime('2005-01-01');
+ $d2 = new lmbDateTime('2005-01-01');
$this->assertEqual($d1->compare($d2), 0);
$this->assertEqual($d1->addYear()->compare($d2), 1);
@@ -578,7 +578,7 @@
function testCompareThrowsExceptionForNonDate()
{
- $d = new lmbDate();
+ $d = new lmbDateTime();
try
{
@@ -590,28 +590,28 @@
function testStripTime()
{
- $date = new lmbDate('2005-01-01 12:20:40');
- $this->assertEqual($date->stripTime(), new lmbDate('2005-01-01'));
+ $date = new lmbDateTime('2005-01-01 12:20:40');
+ $this->assertEqual($date->stripTime(), new lmbDateTime('2005-01-01'));
}
function testStripDate()
{
- $date = new lmbDate('2005-01-01 12:20:40');
- $this->assertEqual($date->stripDate(), new lmbDate('12:20:40'));
+ $date = new lmbDateTime('2005-01-01 12:20:40');
+ $this->assertEqual($date->stripDate(), new lmbDateTime('12:20:40'));
}
function testIsDateEqual()
{
- $date1 = new lmbDate('2005-01-01 12:20:40');
- $date2 = new lmbDate('2005-01-01 13:20:40');
+ $date1 = new lmbDateTime('2005-01-01 12:20:40');
+ $date2 = new lmbDateTime('2005-01-01 13:20:40');
$this->assertTrue($date1->isEqualDate($date2));
$this->assertTrue($date2->isEqualDate($date1));
}
function testIsDateNotEqual()
{
- $date1 = new lmbDate('2005-02-01 12:20:40');
- $date2 = new lmbDate('2005-01-01 13:20:40');
+ $date1 = new lmbDateTime('2005-02-01 12:20:40');
+ $date2 = new lmbDateTime('2005-01-01 13:20:40');
$this->assertFalse($date1->isEqualDate($date2));
$this->assertFalse($date2->isEqualDate($date1));
}
Modified: 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -7,13 +7,13 @@
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/datetime/src/lmbMonth.class.php');
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
class lmbMonthTest extends UnitTestCase
{
function testCreateCurrent()
{
- $date = new lmbDate();
+ $date = new lmbDateTime();
$c = new lmbMonth();
$this->assertEqual($c->getYear(), $date->getYear());
@@ -29,7 +29,7 @@
function testCreateByDate()
{
- $c = new lmbMonth(new lmbDate('2007-05-01'));
+ $c = new lmbMonth(new lmbDateTime('2007-05-01'));
$this->assertEqual($c->getYear(), 2007);
$this->assertEqual($c->getMonth(), 5);
}
@@ -44,8 +44,8 @@
function testGetBoundaries()
{
$c = new lmbMonth(2007, 5);
- $this->assertEqual(new lmbDate('2007-05-01 00:00:00'), $c->getStartDate());
- $this->assertEqual(new lmbDate('2007-05-31 23:59:59'), $c->getEndDate());
+ $this->assertEqual(new lmbDateTime('2007-05-01 00:00:00'), $c->getStartDate());
+ $this->assertEqual(new lmbDateTime('2007-05-31 23:59:59'), $c->getEndDate());
}
function testGetMonthName()
@@ -109,13 +109,13 @@
$expected3 = array();
for($i=0;$i<7;$i++)
- $expected0[] = new lmbDate(sprintf("1999-02-%02d", $i+1));
+ $expected0[] = new lmbDateTime(sprintf("1999-02-%02d", $i+1));
for($i=7;$i<14;$i++)
- $expected1[] = new lmbDate(sprintf("1999-02-%02d", $i+1));
+ $expected1[] = new lmbDateTime(sprintf("1999-02-%02d", $i+1));
for($i=14;$i<21;$i++)
- $expected2[] = new lmbDate(sprintf("1999-02-%02d", $i+1));
+ $expected2[] = new lmbDateTime(sprintf("1999-02-%02d", $i+1));
for($i=21;$i<28;$i++)
- $expected3[] = new lmbDate(sprintf("1999-02-%02d", $i+1));
+ $expected3[] = new lmbDateTime(sprintf("1999-02-%02d", $i+1));
$this->assertEqual($week0, $expected0);
$this->assertEqual($week1, $expected1);
@@ -139,21 +139,21 @@
$expected4 = array();
for($i=29;$i<32;$i++)
- $expected0[] = new lmbDate(sprintf("2007-01-%02d", $i));
+ $expected0[] = new lmbDateTime(sprintf("2007-01-%02d", $i));
for($i=1;$i<5;$i++)
- $expected0[] = new lmbDate(sprintf("2007-02-%02d", $i));
+ $expected0[] = new lmbDateTime(sprintf("2007-02-%02d", $i));
for($i=5;$i<12;$i++)
- $expected1[] = new lmbDate(sprintf("2007-02-%02d", $i));
+ $expected1[] = new lmbDateTime(sprintf("2007-02-%02d", $i));
for($i=12;$i<19;$i++)
- $expected2[] = new lmbDate(sprintf("2007-02-%02d", $i));
+ $expected2[] = new lmbDateTime(sprintf("2007-02-%02d", $i));
for($i=19;$i<26;$i++)
- $expected3[] = new lmbDate(sprintf("2007-02-%02d", $i));
+ $expected3[] = new lmbDateTime(sprintf("2007-02-%02d", $i));
for($i=26;$i<29;$i++)
- $expected4[] = new lmbDate(sprintf("2007-02-%02d", $i));
+ $expected4[] = new lmbDateTime(sprintf("2007-02-%02d", $i));
for($i=1;$i<5;$i++)
- $expected4[] = new lmbDate(sprintf("2007-03-%02d", $i));
+ $expected4[] = new lmbDateTime(sprintf("2007-03-%02d", $i));
$this->assertEqual($week0, $expected0);
$this->assertEqual($week1, $expected1);
Deleted: 3.x/trunk/limb/datetime/tests/cases/lmbTimePeriodTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbTimePeriodTest.class.php 2007-11-21 20:03:24 UTC (rev 6533)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbTimePeriodTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
@@ -1,28 +0,0 @@
-<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-lmb_require('limb/datetime/src/lmbTimePeriod.class.php');
-lmb_require('limb/datetime/src/lmbDateTimePeriod.class.php');
-
-class lmbTimePeriodTest extends UnitTestCase
-{
- function testUseOnlyTime()
- {
- $p = new lmbTimePeriod('2005-12-01 13:45:12', '2006-12-01 13:46:00');
- $this->assertEqual($p->getDuration(), 48);
- }
-
- function testGetDatePeriod()
- {
- $p = new lmbTimePeriod('13:45:12', '13:46:00');
- $date_period = $p->getDatePeriod('2006-12-01');
- $this->assertEqual($date_period, new lmbDateTimePeriod('2006-12-01 13:45:12', '2006-12-01 13:46:00'));
- }
-}
-
-
More information about the limb-svn
mailing list