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

svn at limb-project.com svn at limb-project.com
Tue May 8 17:47:27 MSD 2007


Author: pachanga
Date: 2007-05-08 17:47:27 +0400 (Tue, 08 May 2007)
New Revision: 5836
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5836

Modified:
   3.x/trunk/limb/datetime/src/lmbMonth.class.php
   3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
Log:
-- lmbMonth :: getMonth(), getMonthName(), getMonthShortName(), getYear() added
-- lmbMonth can be constructed now using 3 different ways:
  * new lmbMonth() - current month
  * new lmbMonth(2007, 1)
  * new lmbMonth(new lmbDate(..))

Modified: 3.x/trunk/limb/datetime/src/lmbMonth.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbMonth.class.php	2007-05-08 12:45:27 UTC (rev 5835)
+++ 3.x/trunk/limb/datetime/src/lmbMonth.class.php	2007-05-08 13:47:27 UTC (rev 5836)
@@ -16,13 +16,39 @@
   protected $start_date;
   protected $end_date;
 
-  function __construct($year, $month)
+  function __construct($year_or_date = null, $month = null)
   {
-    $tmp_date = new lmbDate(0, 0, 0, 0, $month, $year);
+    if($year_or_date && $month)
+      $tmp_date = new lmbDate(0, 0, 0, 0, $month, $year_or_date);
+    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);
   }
 
+  function getMonth()
+  {
+    return $this->start_date->getMonth();
+  }
+
+  function getMonthName()
+  {
+    return $this->start_date->date('M');
+  }
+
+  function getMonthShortName()
+  {
+    return $this->start_date->date('F');
+  }
+
+  function getYear()
+  {
+    return $this->start_date->getYear();
+  }
+
   function getStartDate()
   {
     return $this->start_date;

Modified: 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php	2007-05-08 12:45:27 UTC (rev 5835)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbMonthTest.class.php	2007-05-08 13:47:27 UTC (rev 5836)
@@ -10,9 +10,40 @@
  * @package    datetime
  */
 lmb_require('limb/datetime/src/lmbMonth.class.php');
+lmb_require('limb/datetime/src/lmbDate.class.php');
 
 class lmbMonthTest extends UnitTestCase
 {
+  function testCreateCurrent()
+  {
+    $date = new lmbDate();
+
+    $c = new lmbMonth();
+    $this->assertEqual($c->getYear(), $date->getYear());
+    $this->assertEqual($c->getMonth(), $date->getMonth());
+  }
+
+  function testCreate()
+  {
+    $c = new lmbMonth(2007, 5);
+    $this->assertEqual($c->getYear(), 2007);
+    $this->assertEqual($c->getMonth(), 5);
+  }
+
+  function testCreateByDate()
+  {
+    $c = new lmbMonth(new lmbDate('2007-05-01'));
+    $this->assertEqual($c->getYear(), 2007);
+    $this->assertEqual($c->getMonth(), 5);
+  }
+
+  function testCreateByString()
+  {
+    $c = new lmbMonth('2007-05-01');
+    $this->assertEqual($c->getYear(), 2007);
+    $this->assertEqual($c->getMonth(), 5);
+  }
+
   function testGetBoundaries()
   {
     $c = new lmbMonth(2007, 5);
@@ -20,6 +51,18 @@
     $this->assertEqual(new lmbDate('2007-05-31'), $c->getEndDate());
   }
 
+  function testGetMonthName()
+  {
+    $c = new lmbMonth(2007, 5);
+    $this->assertEqual($c->getMonthName(), 'May');
+  }
+
+  function testGetMonthShortName()
+  {
+    $c = new lmbMonth(2007, 1);
+    $this->assertEqual($c->getMonthName(), 'Jan');
+  }
+
   function testGetNumberOfDays()
   {
     $c = new lmbMonth(2007, 5);



More information about the limb-svn mailing list