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

svn at limb-project.com svn at limb-project.com
Mon May 7 15:13:08 MSD 2007


Author: pachanga
Date: 2007-05-07 15:13:08 +0400 (Mon, 07 May 2007)
New Revision: 5821
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5821

Modified:
   3.x/trunk/limb/datetime/src/lmbDate.class.php
   3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
Log:
-- lmbDate :: strftime($format) - a wrapper around PHP strftime added
-- lmbDate :: date($format) - a wrapper around PHP date added
-- $with_seconds optional argument added into lmbDate :: getIsoDate(), it allows to skip seconds
-- lmbDate :: getIsoShortDate() added, it returns ISO date without time
-- lmbDate :: getIsoTime($with_seconds = true) added, it returns ISO time only, $with_seconds allows to skip seconds 

Modified: 3.x/trunk/limb/datetime/src/lmbDate.class.php
===================================================================
--- 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-07 10:34:13 UTC (rev 5820)
+++ 3.x/trunk/limb/datetime/src/lmbDate.class.php	2007-05-07 11:13:08 UTC (rev 5821)
@@ -15,7 +15,6 @@
 {
   //YYYY-MM-DD HH:MM:SS timezone
   const DATE_STRING_REGEX = '~^(([0-9]{4})-([0-9]{2})-([0-9]{2}))?((?(1)\s+)([0-9]{2}):([0-9]{2}):?([0-9]{2})?)?$~';
-  const DATE_ISO_FORMAT = "%04d-%02d-%02d %02d:%02d:%02d";
 
   protected $year = 0;
   protected $month = 0;
@@ -75,7 +74,7 @@
   static function stampToISO($stamp)
   {
     $date = new lmbDate((int)$stamp);
-    return $date->getISODate();
+    return $date->getIsoDate();
   }
 
   function _createTimeZoneObject($code=null)
@@ -157,13 +156,35 @@
       return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
   }
 
-  function getISODate()
+  function date($format)
   {
-    return sprintf(self :: DATE_ISO_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());
+  }
+
   /**
    * @deprecated
    */
@@ -174,7 +195,7 @@
 
   function toString()
   {
-    return $this->getISODate();
+    return $this->getIsoDate();
   }
 
   function isInDaylightTime()

Modified: 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php
===================================================================
--- 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-07 10:34:13 UTC (rev 5820)
+++ 3.x/trunk/limb/datetime/tests/cases/lmbDateTest.class.php	2007-05-07 11:13:08 UTC (rev 5821)
@@ -55,10 +55,56 @@
     $this->assertEqual($date->getHour(), 12);
     $this->assertEqual($date->getMinute(), 45);
     $this->assertEqual($date->getSecond(), 12);
+  }
 
+  function testGetIsoDate()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->getIsoDate(), '2005-12-01 12:45:12');
+  }
+
+  function testGetIsoDateWithoutSeconds()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->getIsoDate(false), '2005-12-01 12:45');
+  }
+
+  function testGetIsoShortDate()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->getIsoShortDate(), '2005-12-01');
+  }
+
+  function testGetIsoTime()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->getIsoTime(), '12:45:12');
+  }
+
+  function testGetIsoTimeWithoutSeconds()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->getIsoTime(false), '12:45');
+  }
+
+  function testToStringReturnsIsoDate()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
     $this->assertEqual($date->toString(), '2005-12-01 12:45:12');
   }
 
+  function testStrftime()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->strftime('%m/%d/%y'), '12/01/05');
+  }
+
+  function testDate()
+  {
+    $date = new lmbDate(12, 45, 12, 1, 12 ,2005);
+    $this->assertEqual($date->date('m.d.y'), '12.01.05');
+  }
+
   function testCreateByCopy()
   {
     $date = new lmbDate($sample = new lmbDate(12, 45, 12, 1, 12 ,2005));



More information about the limb-svn mailing list