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

svn at limb-project.com svn at limb-project.com
Wed May 9 15:35:41 MSD 2007


Author: pachanga
Date: 2007-05-09 15:35:41 +0400 (Wed, 09 May 2007)
New Revision: 5846
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5846

Modified:
   3.x/trunk/limb/datetime/src/lmbDate.class.php
   3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
Log:
-- lmbDate :: getBeginOfDay(), getEndOfDay(), getBeginOfMonth(), getEndOfMonth(), getBeginOfYear(), getEndOfYear() added

Modified: 3.x/trunk/limb/datetime/src/lmbDate.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-09 08:15:57 UTC (rev 5845)
+++ 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-09 11:35:41 UTC (rev 5846)
@@ -382,6 +382,16 @@
     return (int)($day - 7 * floor($day / 7));
   }
 
+  function getBeginOfDay()
+  {
+    return new lmbDate(0, 0, 0, $this->day, $this->month, $this->year, $this->tz);
+  }
+
+  function getEndOfDay()
+  {
+    return new lmbDate(23, 59, 59, $this->day, $this->month, $this->year, $this->tz);
+  }
+
   function getBeginOfWeek()
   {
     $this_weekday = $this->getDayOfWeek();
@@ -396,6 +406,26 @@
     return lmbDate :: createByDays($this->getDateDays() + $interval);
   }
 
+  function getBeginOfMonth()
+  {
+    return new lmbDate(0, 0, 0, 1, $this->month, $this->year, $this->tz);
+  }
+
+  function getEndOfMonth()
+  {
+    return $this->setDay(1)->addMonth(1)->addDay(-1)->getEndOfDay();
+  }
+
+  function getBeginOfYear()
+  {
+    return new lmbDate(0, 0, 0, 1, 1, $this->year, $this->tz);
+  }
+
+  function getEndOfYear()
+  {
+    return new lmbDate(23, 59, 59, 31, 12, $this->year, $this->tz);
+  }
+
   function getWeekOfYear()
   {
     $day = $this->day;

Modified: 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-09 08:15:57 UTC (rev 5845)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-09 11:35:41 UTC (rev 5846)
@@ -262,6 +262,18 @@
     $this->assertEqual($date->getDayOfWeek(), 6);
   }
 
+  function testGetBeginOfDay()
+  {
+    $date = new lmbDate('2005-08-20 12:24:12');
+    $this->assertEqual($date->getBeginOfDay(), new lmbDate('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'));
+  }
+
   function testGetBeginOfWeek()
   {
     $date = new lmbDate('2005-01-20');
@@ -298,6 +310,30 @@
     $this->assertEqual($date->getEndOfWeek(), new lmbDate('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'));
+  }
+
+  function testGetEndOfMonth()
+  {
+    $date = new lmbDate('2007-05-09 12:24:12');
+    $this->assertEqual($date->getEndOfMonth(), new lmbDate('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'));
+  }
+
+  function testGetEndOfYear()
+  {
+    $date = new lmbDate('2007-05-09 12:24:12');
+    $this->assertEqual($date->getEndOfYear(), new lmbDate('2007-12-31 23:59:59'));
+  }
+
   function testSetYear()
   {
     $date = new lmbDate('2005-01-01');



More information about the limb-svn mailing list