[limb-svn] r5847 - in 3.x/trunk/limb/datetime: src tests/cases

svn at limb-project.com svn at limb-project.com
Wed May 9 16:29:32 MSD 2007


Author: pachanga
Date: 2007-05-09 16:29:32 +0400 (Wed, 09 May 2007)
New Revision: 5847
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5847

Modified:
   3.x/trunk/limb/datetime/src/lmbDate.class.php
   3.x/trunk/limb/datetime/src/lmbMonth.class.php
   3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php
   3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
   3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
Log:
-- lmbDate general constructor instantiation BC break! Now when lmbDate is instantiated with all arguments constructor the order of arguments should be as follows: new lmbDate($year, $month, $day, $hour, $minute, $second, $tz=''). Hopefully this shouldn't break to much stuff since this form was rarely used, however it's a more logical way of dates instantiations since it follows order of date items in ISO format.
-- lmbDate :: createWithoutTime() removed, since with new constructor it's simply not required
-- better tests for lmbMonth

Modified: 3.x/trunk/limb/datetime/src/lmbDate.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-09 11:35:41 UTC (rev 5846)
+++ 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-09 12:29:32 UTC (rev 5847)
@@ -28,36 +28,36 @@
   protected $second = 0;
   protected $tz = '';
 
-  function __construct($hour_or_date=null, $minute_or_tz=0, $second=0, $day=0, $month=0, $year=0, $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->hour   = (int)$hour_or_date;
-      $this->minute = (int)$minute_or_tz;
-      $this->second = (int)$second;
+      $this->year   = (int)$year_or_date;
+      $this->month  = (int)$month_or_tz;
       $this->day    = (int)$day;
-      $this->month  = (int)$month;
-      $this->year   = (int)$year;
+      $this->hour   = (int)$hour;
+      $this->minute = (int)$minute;
+      $this->second = (int)$second;
       $this->tz     = $tz;
     }
-    elseif(is_a($hour_or_date, 'lmbDate'))
+    elseif(is_a($year_or_date, 'lmbDate'))
     {
-      $this->_copy($hour_or_date);
+      $this->_copy($year_or_date);
     }
-    elseif(is_numeric($hour_or_date))
+    elseif(is_numeric($year_or_date))
     {
-      $this->_setByStamp($hour_or_date);
-      $this->tz = $minute_or_tz;
+      $this->_setByStamp($year_or_date);
+      $this->tz = $month_or_tz;
     }
-    elseif(is_string($hour_or_date))
+    elseif(is_string($year_or_date))
     {
-      $this->_setByString($hour_or_date);
-      $this->tz = $minute_or_tz;
+      $this->_setByString($year_or_date);
+      $this->tz = $month_or_tz;
     }
     else
     {
       $this->_setByStamp(time());
-      $this->tz = $minute_or_tz;
+      $this->tz = $month_or_tz;
     }
 
     if(!$this->isValid())
@@ -70,25 +70,14 @@
   /**
    * Wrapper around constructor, it can be useful since the following is not allowed in PHP 'new lmbDate(..)->addDay(..)->'
    */
-  static function create($hour_or_date=null, $minute_or_tz=0, $second=0, $day=0, $month=0, $year=0, $tz='')
+  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 lmbDate($hour_or_date, $minute_or_tz, $second, $day, $month, $year, $tz);
+      return new lmbDate($year_or_date, $month_or_tz, $day, $hour, $minute, $second, $tz);
     else
-      return new lmbDate($hour_or_date, $minute_or_tz);
+      return new lmbDate($year_or_date, $month_or_tz);
   }
 
-  static function createWithoutTime($year=null, $month=null, $day=null, $tz='')
-  {
-    if(!$year && !$month && !$day)
-    {
-      $date = new lmbDate();
-      return $date->setSecond(0)->setMinute(0)->setHour(0);
-    }
-    else
-      return new lmbDate(0, 0, 0, $day, $month, $year, $tz);
-  }
-
   static function createByDays($days)
   {
     $days   -= 1721119;
@@ -120,7 +109,7 @@
 
     $century = sprintf('%02d', $century);
     $year    = sprintf('%02d', $year);
-    return new lmbDate(0, 0, 0, $day, $month, $century . $year);
+    return new lmbDate($century . $year, $month, $day);
   }
 
   static function setFirstDayOfWeek($n)
@@ -384,12 +373,12 @@
 
   function getBeginOfDay()
   {
-    return new lmbDate(0, 0, 0, $this->day, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, $this->tz);
   }
 
   function getEndOfDay()
   {
-    return new lmbDate(23, 59, 59, $this->day, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, 23, 59, 59, $this->tz);
   }
 
   function getBeginOfWeek()
@@ -408,7 +397,7 @@
 
   function getBeginOfMonth()
   {
-    return new lmbDate(0, 0, 0, 1, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, 1, $this->tz);
   }
 
   function getEndOfMonth()
@@ -418,12 +407,12 @@
 
   function getBeginOfYear()
   {
-    return new lmbDate(0, 0, 0, 1, 1, $this->year, $this->tz);
+    return new lmbDate($this->year, 1, 1, $this->tz);
   }
 
   function getEndOfYear()
   {
-    return new lmbDate(23, 59, 59, 31, 12, $this->year, $this->tz);
+    return new lmbDate($this->year, 12, 31, 23, 59, 59, $this->tz);
   }
 
   function getWeekOfYear()
@@ -441,18 +430,18 @@
     }
 
     $dayofweek = $this->getDayOfWeek();
-    $firstday  = self :: createWithoutTime($year, 1, 1)->getDayOfWeek();
+    $firstday  = self :: create($year, 1, 1)->getDayOfWeek();
     if(($month == 1) && (($firstday < 1) || ($firstday > 4)) && ($day < 4))
     {
-      $firstday  = self :: createWithoutTime($year - 1, 1, 1)->getDayOfWeek();
+      $firstday  = self :: create($year - 1, 1, 1)->getDayOfWeek();
       $month     = 12;
       $day       = 31;
     }
-    elseif(($month == 12) && ((self :: createWithoutTime($year + 1, 1, 1)->getDayOfWeek() < 5) &&
-            (self :: createWithoutTime($year + 1, 1, 1)->getDayOfWeek() > 0)))
+    elseif(($month == 12) && ((self :: create($year + 1, 1, 1)->getDayOfWeek() < 5) &&
+            (self :: create($year + 1, 1, 1)->getDayOfWeek() > 0)))
         return 1;
 
-    return intval(((self :: createWithoutTime($year, 1, 1)->getDayOfWeek() < 5) && (self :: createWithoutTime($year, 1, 1)->getDayOfWeek() > 0)) +
+    return intval(((self :: create($year, 1, 1)->getDayOfWeek() < 5) && (self :: create($year, 1, 1)->getDayOfWeek() > 0)) +
            4 * ($month - 1) + (2 * ($month - 1) + ($day - 1) + $firstday - $dayofweek + 6) * 36 / 256);
   }
 
@@ -525,37 +514,37 @@
 
   function setYear($y)
   {
-    return new lmbDate($this->hour, $this->minute, $this->second, $this->day, $this->month, $y, $this->tz);
+    return new lmbDate($y, $this->month, $this->day, $this->hour, $this->minute, $this->second, $this->tz);
   }
 
   function setMonth($m)
   {
-    return new lmbDate($this->hour, $this->minute, $this->second, $this->day, $m, $this->year, $this->tz);
+    return new lmbDate($this->year, $m, $this->day, $this->hour, $this->minute, $this->second, $this->tz);
   }
 
   function setDay($d)
   {
-    return new lmbDate($this->hour, $this->minute, $this->second, $d, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $d, $this->hour, $this->minute, $this->second, $this->tz);
   }
 
   function setHour($h)
   {
-    return new lmbDate($h, $this->minute, $this->second, $this->day, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, $h, $this->minute, $this->second, $this->tz);
   }
 
   function setMinute($m)
   {
-    return new lmbDate($this->hour, $m, $this->second, $this->day, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, $this->hour, $m, $this->second, $this->tz);
   }
 
   function setSecond($s)
   {
-    return new lmbDate($this->hour, $this->minute, $s, $this->day, $this->month, $this->year, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, $this->hour, $this->minute, $s, $this->tz);
   }
 
   function setTimeZone($tz)
   {
-    return new lmbDate($this->hour, $this->minute, $this->second, $this->day, $this->month, $this->year, $tz);
+    return new lmbDate($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second, $tz);
   }
 
   function addYear($n=1)
@@ -602,12 +591,12 @@
 
   function stripTime()
   {
-    return lmbDate :: createWithoutTime($this->year, $this->month, $this->day, $this->tz);
+    return new lmbDate($this->year, $this->month, $this->day, 0, 0, 0, $this->tz);
   }
 
   function stripDate()
   {
-    return new lmbDate($this->hour, $this->minute, $this->second, null, null, null, $this->tz);
+    return new lmbDate(null, null, null, $this->hour, $this->minute, $this->second, $this->tz);
   }
 }
 ?>
\ No newline at end of file

Modified: 3.x/trunk/limb/datetime/src/lmbMonth.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbMonth.class.php	2007-05-09 11:35:41 UTC (rev 5846)
+++ 3.x/trunk/limb/datetime/src/lmbMonth.class.php	2007-05-09 12:29:32 UTC (rev 5847)
@@ -19,14 +19,14 @@
   function __construct($year_or_date = null, $month = null)
   {
     if($year_or_date && $month)
-      $tmp_date = new lmbDate(0, 0, 0, 0, $month, $year_or_date);
+      $tmp_date = new lmbDate($year_or_date, $month, 1);
     elseif($year_or_date && !$month)
       $tmp_date = new lmbDate($year_or_date);
     else
       $tmp_date = new lmbDate();
 
-    $this->start_date = $tmp_date->setDay(1);
-    $this->end_date = $this->start_date->addMonth(1)->addDay(-1);
+    $this->start_date = $tmp_date->getBeginOfMonth();
+    $this->end_date = $tmp_date->getEndOfMonth();
   }
 
   function getMonth()

Modified: 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php	2007-05-09 11:35:41 UTC (rev 5846)
+++ 3.x/trunk/limb/datetime/src/lmbTimePeriod.class.php	2007-05-09 12:29:32 UTC (rev 5847)
@@ -1,13 +1,13 @@
 <?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    datetime
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    datetime
  */
 lmb_require('limb/datetime/src/lmbDate.class.php');
 lmb_require('limb/datetime/src/lmbDatePeriod.class.php');
@@ -30,19 +30,11 @@
     $month = $date->getMonth();
     $day = $date->getDay();
 
-    $start_date = new lmbDate($this->start->getHour(),
-                           $this->start->getMinute(),
-                           $this->start->getSecond(),
-                           $day,
-                           $month,
-                           $year);
+    $start_date = new lmbDate($year, $month, $day,
+                              $this->start->getHour(), $this->start->getMinute(), $this->start->getSecond());
 
-    $end_date = new lmbDate($this->end->getHour(),
-                         $this->end->getMinute(),
-                         $this->end->getSecond(),
-                         $day,
-                         $month,
-                         $year);
+    $end_date = new lmbDate($year, $month, $day,
+                            $this->end->getHour(), $this->end->getMinute(), $this->end->getSecond());
 
     return new lmbDatePeriod($start_date, $end_date);
   }

Modified: 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-09 11:35:41 UTC (rev 5846)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-09 12:29:32 UTC (rev 5847)
@@ -62,8 +62,8 @@
 
   function testCreate()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
-    $this->assertEqual(lmbDate :: create(12, 45, 12, 1, 12 ,2005), $date);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
+    $this->assertEqual(lmbDate :: create(2005, 12, 1, 12, 45, 12), $date);
 
     $this->assertEqual($date->getDay(), 1);
     $this->assertEqual($date->getMonth(), 12);
@@ -75,55 +75,55 @@
 
   function testGetIsoDate()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->getIsoDate(), '2005-12-01 12:45:12');
   }
 
   function testGetIsoDateWithoutSeconds()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->getIsoDate(false), '2005-12-01 12:45');
   }
 
   function testGetIsoShortDate()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->getIsoShortDate(), '2005-12-01');
   }
 
   function testGetIsoTime()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->getIsoTime(), '12:45:12');
   }
 
   function testGetIsoTimeWithoutSeconds()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->getIsoTime(false), '12:45');
   }
 
   function testToStringReturnsIsoDate()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->toString(), '2005-12-01 12:45:12');
   }
 
   function testStrftime()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->strftime('%m/%d/%y'), '12/01/05');
   }
 
   function testDate()
   {
-    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $date = new lmbDate(2005, 12, 1, 12, 45, 12);
     $this->assertEqual($date->date('m.d.y'), '12.01.05');
   }
 
   function testCreateByCopy()
   {
-    $date = new lmbDate($sample = new lmbDate(12, 45, 12, 1, 12 ,2005));
+    $date = new lmbDate($sample = new lmbDate(2005, 12, 1, 12, 45, 12));
     $this->assertEqual(lmbDate :: create($sample), $date);
 
     $this->assertEqual($date, $sample);
@@ -159,12 +159,6 @@
     $this->assertEqual($date->toString(), '2005-12-01 00:00:00');
   }
 
-  function testCreateWithoutTime()
-  {
-    $date = new lmbDate('2005-12-01');
-    $this->assertEqual(lmbDate :: createWithoutTime(2005, 12, 1), $date);
-  }
-
   function testCreateByIsoTimeOnly()
   {
     $date = new lmbDate('12:45:12');
@@ -468,14 +462,14 @@
 
   function testCreateWithTZ()
   {
-    $date = new lmbDate(12, 10, 5, 3, 5, 2005, 'Europe/Moscow');
+    $date = new lmbDate(2005, 5, 3, 12, 10, 5, 'Europe/Moscow');
     $tz = $date->getTimeZoneObject();
     $this->assertEqual($tz, new lmbDateTimeZone('Europe/Moscow'));
   }
 
   function testCreateWithInvalidTZ()
   {
-    $date = new lmbDate(12, 10, 5, 3, 5, 2005, 'bla-bla');
+    $date = new lmbDate(2005, 5, 3, 12, 10, 5, 'bla-bla');
     $tz = $date->getTimeZoneObject();
     $this->assertEqual($tz, new lmbDateTimeZone('UTC'));
   }

Modified: 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php	2007-05-09 11:35:41 UTC (rev 5846)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php	2007-05-09 12:29:32 UTC (rev 5847)
@@ -47,8 +47,8 @@
   function testGetBoundaries()
   {
     $c = new lmbMonth(2007, 5);
-    $this->assertEqual(new lmbDate('2007-05-01'), $c->getStartDate());
-    $this->assertEqual(new lmbDate('2007-05-31'), $c->getEndDate());
+    $this->assertEqual(new lmbDate('2007-05-01 00:00:00'), $c->getStartDate());
+    $this->assertEqual(new lmbDate('2007-05-31 23:59:59'), $c->getEndDate());
   }
 
   function testGetMonthName()



More information about the limb-svn mailing list