[limb-svn] r5822 - in 3.x/trunk/limb/i18n: src/datetime src/template/tags/i18n tests/cases/datetime
svn at limb-project.com
svn at limb-project.com
Mon May 7 15:14:00 MSD 2007
Author: pachanga
Date: 2007-05-07 15:14:00 +0400 (Mon, 07 May 2007)
New Revision: 5822
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5822
Added:
3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php
Removed:
3.x/trunk/limb/i18n/src/datetime/lmbDateFormat.class.php
3.x/trunk/limb/i18n/tests/cases/datetime/lmbDateFormatTest.class.php
Modified:
3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php
3.x/trunk/limb/i18n/src/template/tags/i18n/date.filter.php
3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php
Log:
-- lmbDateFormat removed, its functionality moved into new lmbLocaleDate :: localeStrftime(..)
Deleted: 3.x/trunk/limb/i18n/src/datetime/lmbDateFormat.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/datetime/lmbDateFormat.class.php 2007-05-07 11:13:08 UTC (rev 5821)
+++ 3.x/trunk/limb/i18n/src/datetime/lmbDateFormat.class.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -1,206 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright Copyright © 2004-2007 BIT
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- * @version $Id$
- * @package i18n
- */
-
-class lmbDateFormat
-{
- /**
- * date pretty printing, similar to strftime()
- *
- * Formats the date in the given format, much like
- * strftime(). Most strftime() attributes are supported.
- * %a abbreviated weekday name (Sun, Mon, Tue)
- * %A full weekday name (Sunday, Monday, Tuesday)
- * %b abbreviated month name (Jan, Feb, Mar)
- * %B full month name (January, February, March)
- * %C century number (the year divided by 100 and truncated to an integer, range 00 to 99)
- * %d day of month (range 00 to 31)
- * %D same as "%m/%d/%y"
- * %e day of month, single digit (range 0 to 31)
- * %E number of days since unspecified epoch
- * %H hour as decimal number (00 to 23)
- * %I hour as decimal number on 12-hour clock (01 to 12)
- * %j day of year (range 001 to 366)
- * %m month as decimal number (range 01 to 12)
- * %M minute as a decimal number (00 to 59)
- * %n newline character (\n)
- * %O dst-corrected timezone offset expressed as "+/-HH:MM"
- * %o raw timezone offset expressed as "+/-HH:MM"
- * %p either 'am' or 'pm' depending on the time
- * %P either 'AM' or 'PM' depending on the time
- * %r time in am/pm notation, same as "%I:%M:%S %p"
- * %R time in 24-hour notation, same as "%H:%M"
- * %S seconds as a decimal number (00 to 59)
- * %t tab character (\t)
- * %T current time, same as "%H:%M:%S"
- * %w weekday as decimal (0 = Sunday)
- * %U week number of current year, first sunday as first week
- * %y year as decimal (range 00 to 99)
- * %Y year as decimal including century (range 0000 to 9999)
- * %% literal '%'
- */
- function toString($date, $format, $locale=null)
- {
- $output = '';
-
- for($strpos = 0; $strpos < strlen($format); $strpos++)
- {
- $char = substr($format, $strpos, 1);
- if($char != '%')
- {
- $output .= $char;
- continue;
- }
-
- $nextchar = substr($format, $strpos + 1, 1);
- switch($nextchar)
- {
- case 'a':
- $this->_assertLocale($locale);
- $output .= $locale->getDayName($date->getDayOfWeek(), true);
- break;
- case 'A':
- $this->_assertLocale($locale);
- $output .= $locale->getDayName($date->getDayOfWeek());
- break;
- case 'b':
- $this->_assertLocale($locale);
- $output .= $locale->getMonthName($date->getMonth() - 1, true);
- break;
- case 'B':
- $this->_assertLocale($locale);
- $output .= $locale->getMonthName($date->getMonth() - 1);
- break;
- case 'p':
- $this->_assertLocale($locale);
- $output .= $locale->getMeridiemName($date->getHour());
- break;
- case 'P':
- $this->_assertLocale($locale);
- $output .= $locale->getMeridiemName($date->getHour(), true);
- break;
- case 'C':
- $output .= sprintf("%02d", intval($date->getYear()/100));
- break;
- case 'd':
- $output .= sprintf("%02d", $date->getDay());
- break;
- case 'D':
- $output .= sprintf("%02d/%02d/%02d", $date->getMonth(), $date->getDay(), substr($date->getYear(), 2));
- break;
- case 'e':
- $output .= $date->getDay();
- break;
- case 'E':
- $output .= $date->dateToDays();
- break;
- case 'H':
- $output .= sprintf("%02d", $date->getHour());
- break;
- case 'I':
- $hour = ($date->getHour() + 1) > 12 ? $date->getHour() - 12 : $date->getHour();
- $output .= sprintf("%02d", $hour==0 ? 12 : $hour);
- break;
- case 'j':
- $output .= sprintf("%03d", $date->getDayOfYear());
- break;
- case 'm':
- $output .= sprintf("%02d",$date->getMonth());
- break;
- case 'M':
- $output .= sprintf("%02d",$date->getMinute());
- break;
- case 'n':
- $output .= "\n";
- break;
- case 'O':
- $offms = $date->getTimeZone()->getOffset($this);
- $direction = $offms >= 0 ? '+' : '-';
- $offmins = abs($offms) / 1000 / 60;
- $hours = $offmins / 60;
- $minutes = $offmins % 60;
- $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
- break;
- case 'o':
- $offms = $date->getTimeZone()->getRawOffset($this);
- $direction = $offms >= 0 ? '+' : '-';
- $offmins = abs($offms) / 1000 / 60;
- $hours = $offmins / 60;
- $minutes = $offmins % 60;
- $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
- break;
- case 'r':
- $hour = ($date->getHour() + 1) > 12 ? $date->getHour() - 12 : $date->getHour();
- $output .= sprintf("%02d:%02d:%02d %s", $hour==0 ? 12 : $hour, $date->getMinute(), $date->getSecond(), $date->getHour() >= 12 ? "PM" : "AM");
- break;
- case 'R':
- $output .= sprintf("%02d:%02d", $date->getHour(), $date->getMinute());
- break;
- case 'S':
- $output .= sprintf("%02d", $date->getSecond());
- break;
- case 't':
- $output .= "\t";
- break;
- case 'T':
- $output .= sprintf("%02d:%02d:%02d", $date->getHour(), $date->getMinute(), $date->getSecond());
- break;
- case 'w':
- $output .= $date->getDayOfWeek();
- break;
- case 'U':
- $output .= $date->getWeekOfYear();
- break;
- case 'y':
- $output .= substr($date->getYear() . '', 2);
- break;
- case 'Y':
- $output .= sprintf("%04d", $date->getYear());
- break;
- case 'Z':
- $output .= $date->getTimeZone()->isInDaylightTime() ? $date->getTimeZone()->getDSTShortName() : $date->getTimeZone()->getShortName();
- break;
- case '%':
- $output .= '%';
- break;
- default:
- $output .= $char . $nextchar;
- }
- $strpos++;
- }
- return $output;
- }
-
- function _assertLocale($locale)
- {
- if(!is_object($locale))
- throw new lmbException('locale object is required for this type of formatting');
- }
-
- function toISO($date)
- {
- //YYYY-MM-DD HH:MM:SS
- return $this->toString($date, "%Y-%m-%d %T", null);
- }
-
- function toDateISO($date)
- {
- //YYYY-MM-DD
- return $this->toString($date, "%Y-%m-%d", null);
- }
-
- function toTimeISO($date)
- {
- //YYYY-MM-DD
- return $this->toString($date, "%T", null);
- }
-}
-?>
\ No newline at end of file
Modified: 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php 2007-05-07 11:13:08 UTC (rev 5821)
+++ 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -11,11 +11,176 @@
*/
lmb_require('limb/core/src/exception/lmbException.class.php');
lmb_require('limb/datetime/src/lmbDate.class.php');
-lmb_require('limb/i18n/src/datetime/lmbDateFormat.class.php');
class lmbLocaleDate extends lmbDate
{
/**
+ * Formats the date in the given format according to locale settings, much like
+ * strftime(). Most strftime() attributes are supported.
+ *
+ * %a abbreviated weekday name (Sun, Mon, Tue)
+ * %A full weekday name (Sunday, Monday, Tuesday)
+ * %b abbreviated month name (Jan, Feb, Mar)
+ * %B full month name (January, February, March)
+ * %C century number (the year divided by 100 and truncated to an integer, range 00 to 99)
+ * %d day of month (range 00 to 31)
+ * %D same as "%m/%d/%y"
+ * %e day of month, single digit (range 0 to 31)
+ * %E number of days since unspecified epoch
+ * %H hour as decimal number (00 to 23)
+ * %I hour as decimal number on 12-hour clock (01 to 12)
+ * %j day of year (range 001 to 366)
+ * %m month as decimal number (range 01 to 12)
+ * %M minute as a decimal number (00 to 59)
+ * %n newline character (\n)
+ * %O dst-corrected timezone offset expressed as "+/-HH:MM"
+ * %o raw timezone offset expressed as "+/-HH:MM"
+ * %p either 'am' or 'pm' depending on the time
+ * %P either 'AM' or 'PM' depending on the time
+ * %r time in am/pm notation, same as "%I:%M:%S %p"
+ * %R time in 24-hour notation, same as "%H:%M"
+ * %S seconds as a decimal number (00 to 59)
+ * %t tab character (\t)
+ * %T current time, same as "%H:%M:%S"
+ * %w weekday as decimal (0 = Sunday)
+ * %U week number of current year, first sunday as first week
+ * %y year as decimal (range 00 to 99)
+ * %Y year as decimal including century (range 0000 to 9999)
+ * %% literal '%'
+ */
+ function localeStrftime($format, $locale=null)
+ {
+ $output = '';
+
+ for($strpos=0; $strpos < strlen($format); $strpos++)
+ {
+ $char = substr($format, $strpos, 1);
+ if($char != '%')
+ {
+ $output .= $char;
+ continue;
+ }
+
+ $nextchar = substr($format, $strpos + 1, 1);
+ switch($nextchar)
+ {
+ case 'a':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getDayName($this->getDayOfWeek(), true);
+ break;
+ case 'A':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getDayName($this->getDayOfWeek());
+ break;
+ case 'b':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getMonthName($this->getMonth() - 1, true);
+ break;
+ case 'B':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getMonthName($this->getMonth() - 1);
+ break;
+ case 'p':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getMeridiemName($this->getHour());
+ break;
+ case 'P':
+ $this->_ensureLocale($locale);
+ $output .= $locale->getMeridiemName($this->getHour(), true);
+ break;
+ case 'C':
+ $output .= sprintf("%02d", intval($this->getYear()/100));
+ break;
+ case 'd':
+ $output .= sprintf("%02d", $this->getDay());
+ break;
+ case 'D':
+ $output .= sprintf("%02d/%02d/%02d", $this->getMonth(), $this->getDay(), substr($this->getYear(), 2));
+ break;
+ case 'e':
+ $output .= $this->getDay();
+ break;
+ case 'E':
+ $output .= $this->dateToDays();
+ break;
+ case 'H':
+ $output .= sprintf("%02d", $this->getHour());
+ break;
+ case 'I':
+ $hour = ($this->getHour() + 1) > 12 ? $this->getHour() - 12 : $this->getHour();
+ $output .= sprintf("%02d", $hour==0 ? 12 : $hour);
+ break;
+ case 'j':
+ $output .= sprintf("%03d", $this->getDayOfYear());
+ break;
+ case 'm':
+ $output .= sprintf("%02d",$this->getMonth());
+ break;
+ case 'M':
+ $output .= sprintf("%02d",$this->getMinute());
+ break;
+ case 'n':
+ $output .= "\n";
+ break;
+ case 'O':
+ $offms = $this->getTimeZone()->getOffset($this);
+ $direction = $offms >= 0 ? '+' : '-';
+ $offmins = abs($offms) / 1000 / 60;
+ $hours = $offmins / 60;
+ $minutes = $offmins % 60;
+ $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
+ break;
+ case 'o':
+ $offms = $this->getTimeZone()->getRawOffset($this);
+ $direction = $offms >= 0 ? '+' : '-';
+ $offmins = abs($offms) / 1000 / 60;
+ $hours = $offmins / 60;
+ $minutes = $offmins % 60;
+ $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
+ break;
+ case 'r':
+ $hour = ($this->getHour() + 1) > 12 ? $this->getHour() - 12 : $this->getHour();
+ $output .= sprintf("%02d:%02d:%02d %s", $hour==0 ? 12 : $hour, $this->getMinute(), $this->getSecond(), $this->getHour() >= 12 ? "PM" : "AM");
+ break;
+ case 'R':
+ $output .= sprintf("%02d:%02d", $this->getHour(), $this->getMinute());
+ break;
+ case 'S':
+ $output .= sprintf("%02d", $this->getSecond());
+ break;
+ case 't':
+ $output .= "\t";
+ break;
+ case 'T':
+ $output .= sprintf("%02d:%02d:%02d", $this->getHour(), $this->getMinute(), $this->getSecond());
+ break;
+ case 'w':
+ $output .= $this->getDayOfWeek();
+ break;
+ case 'U':
+ $output .= $this->getWeekOfYear();
+ break;
+ case 'y':
+ $output .= substr($this->getYear() . '', 2);
+ break;
+ case 'Y':
+ $output .= sprintf("%04d", $this->getYear());
+ break;
+ case 'Z':
+ $output .= $this->getTimeZone()->isInDaylightTime() ? $this->getTimeZone()->getDSTShortName() : $this->getTimeZone()->getShortName();
+ break;
+ case '%':
+ $output .= '%';
+ break;
+ default:
+ $output .= $char . $nextchar;
+ }
+ $strpos++;
+ }
+ return $output;
+ }
+
+ /**
* Tries to guess time values in time string $time_string formatted with $fmt
* Returns an array('hour','minute','second','month','day','year')
* At this moment only most common tags are supported.
@@ -117,7 +282,6 @@
break;
}
}
-
return array('hour' => $hour, 'minute' => $minute, 'second' => $second, 'month' => $month, 'day' => $day, 'year' => $year);
}
@@ -160,8 +324,14 @@
return $time_array;
}
- function localStringToDate($locale, $string, $format = null)
+ protected function _ensureLocale(&$locale)
{
+ if(!is_object($locale))
+ $locale = lmbToolkit :: instance()->getLocaleObject();
+ }
+
+ static function localStringToDate($locale, $string, $format = null)
+ {
if(!$format)
$format = $locale->getShortDateFormat();
@@ -169,39 +339,11 @@
return new lmbDate($arr['hour'], $arr['minute'], $arr['second'], $arr['day'], $arr['month'], $arr['year']);
}
- static function localStringToISO($locale, $string)
+ static function isLocalStringValid($locale, $string, $format = null)
{
- $date = self :: localStringToDate($locale, $string);
- return $date->toString();
- }
-
- static function localStringToStamp($locale, $string)
- {
- $date = self :: localStringToDate($locale, $string);
- return $date->toTimestamp();
- }
-
- static function ISOToLocalString($locale, $iso_date)
- {
- $date = new lmbDate($iso_date);
- $format = new lmbDateFormat();
-
- return $format->toString($date, $locale->getShortDateFormat());
- }
-
- static function stampToLocalString($locale, $stamp)
- {
- $date = new lmbDate((int)$stamp);
- $format = new lmbDateFormat();
-
- return $format->toString($date, $locale->getShortDateFormat());
- }
-
- static function isLocalStringValid($locale, $string)
- {
try
{
- lmbLocaleDate :: localStringToDate($locale, $string);
+ lmbLocaleDate :: localStringToDate($locale, $string, $format);
return true;
}
catch(lmbException $e)
@@ -209,17 +351,6 @@
return false;
}
}
-
- static function localString($locale, $time = null, $format = null)
- {
- if(!$format)
- $format = $locale->getShortDateFormat();
-
- $date = new lmbDate($time);
- $format = new lmbDateFormat();
-
- return $format->toString($date, $locale->getShortDateFormat());
- }
}
?>
Modified: 3.x/trunk/limb/i18n/src/template/tags/i18n/date.filter.php
===================================================================
--- 3.x/trunk/limb/i18n/src/template/tags/i18n/date.filter.php 2007-05-07 11:13:08 UTC (rev 5821)
+++ 3.x/trunk/limb/i18n/src/template/tags/i18n/date.filter.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -9,8 +9,8 @@
* @version $Id$
* @package i18n
*/
-lmb_require('limb/datetime/src/lmbDate.class.php');
-lmb_require('limb/i18n/src/datetime/lmbDateFormat.class.php');
+lmb_require('limb/datetime/src/lmbLocaleDate.class.php');
+lmb_require('limb/i18n/src/datetime/lmbLocaleDateFormat.class.php');
/**
* @filter i18n_date
@@ -35,15 +35,12 @@
else
$locale = $toolkit->getLocaleObject();
- $this->date = new lmbDate();
+ $this->date = new lmbLocaleDate();
$this->_setDate();
- if ($this->isConstant())
- {
- $format = new lmbDateFormat();
- return $format->toString($this->date, $this->_getFormat($locale), $locale);
- }
+ if($this->isConstant())
+ return $this->date->localeStrftime($this->_getFormat($locale), $locale);
else
$this->raiseUnresolvedBindingError();
}
@@ -59,14 +56,14 @@
switch($date_type)
{
case 'string':
- $this->date = new lmbDate($value);
+ $this->date = new lmbLocaleDate($value);
break;
case 'stamp':
- $this->date = new lmbDate((int)$value);
+ $this->date = new lmbLocaleDate((int)$value);
break;
default:
- $this->date = new lmbDate($value);
+ $this->date = new lmbLocaleDate($value);
break;
}
}
@@ -92,8 +89,7 @@
$toolkit_var = $code->getTempVarRef();
$this->locale_var = $code->getTempVarRef();
- $code->writePHP("lmb_require('limb/datetime/src/lmbDate.class.php');");
- $code->writePHP("lmb_require('limb/i18n/src/datetime/lmbDateFormat.class.php');");
+ $code->writePHP("lmb_require('limb/datetime/src/lmbLocaleDate.class.php');");
$code->writePHP($toolkit_var . ' = lmbToolkit :: instance();' . "\n");
$code->writePHP($this->locale_var . ' = ');
@@ -107,10 +103,7 @@
}
$this->date_var = $code->getTempVarRef();
- $this->date_format_var = $code->getTempVarRef();
- $code->writePHP($this->date_format_var . ' = new lmbDateFormat();');
-
$this->_setDBEDate($code);
}
@@ -125,19 +118,19 @@
switch($date_type)
{
case 'stamp':
- $code->writePHP($this->date_var . ' = new lmbDate((int)');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDate((int)');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
case 'string':
- $code->writePHP($this->date_var . ' = new lmbDate(');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDate(');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
default:
- $code->writePHP($this->date_var . ' = new lmbDate((int)');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDate((int)');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
@@ -148,7 +141,7 @@
{
parent :: generateExpression($code);
- $code->writePHP($this->date_format_var . '->toString(' . $this->date_var . ', ');
+ $code->writePHP($this->date_var . '->localeStrftime(');
$this->_getDBEFormat($code);
$code->writePHP(' ,' . $this->locale_var . ')');
}
Deleted: 3.x/trunk/limb/i18n/tests/cases/datetime/lmbDateFormatTest.class.php
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/datetime/lmbDateFormatTest.class.php 2007-05-07 11:13:08 UTC (rev 5821)
+++ 3.x/trunk/limb/i18n/tests/cases/datetime/lmbDateFormatTest.class.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -1,67 +0,0 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright Copyright © 2004-2007 BIT
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- * @version $Id$
- * @package i18n
- */
-lmb_require('limb/datetime/src/lmbDate.class.php');
-lmb_require('limb/i18n/toolkit.inc.php');
-lmb_require('limb/i18n/src/datetime/lmbDateFormat.class.php');
-
-class lmbDateFormatTest extends UnitTestCase
-{
- function testFormat()
- {
- $date = new lmbDate('2005-01-02 23:05:03');
- $printer = new lmbDateFormat();
- $string = $printer->toString($date, '%C %d %D %e %E %H %I %j %m %M %n %R %S %U %y %Y %t %%');
-
- $this->assertEqual($string, "20 02 01/02/05 2 2453373 23 11 002 01 05 \n 23:05 03 53 05 2005 \t %");
- }
-
- function testLocalizedFormat()
- {
- $date = new lmbDate('2005-01-20 10:15:30');
-
- $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $printer = new lmbDateFormat();
-
- $toStringed_date = $printer->toString($date, $locale->getDateFormat(), $locale);
-
- $expected = 'Thursday 20 January 2005';
- $this->assertEqual($toStringed_date, $expected);
- }
-
- function testToISO()
- {
- $date = new lmbDate('2005-01-02 23:05:03');
- $printer = new lmbDateFormat();
- $string = $printer->toISO($date);
-
- $this->assertEqual($string, '2005-01-02 23:05:03');
- }
-
- function testToDateISO()
- {
- $date = new lmbDate('2005-01-02 23:05:03');
- $printer = new lmbDateFormat();
- $string = $printer->toDateISO($date);
-
- $this->assertEqual($string, '2005-01-02');
- }
-
- function testToTimeISO()
- {
- $date = new lmbDate('2005-01-02 23:05:03');
- $printer = new lmbDateFormat();
- $string = $printer->toTimeISO($date);
-
- $this->assertEqual($string, '23:05:03');
- }
-}
-?>
Copied: 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php (from rev 5817, 3.x/trunk/limb/i18n/tests/cases/datetime/lmbDateFormatTest.class.php)
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php (rev 0)
+++ 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright Copyright © 2004-2007 BIT
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version $Id$
+ * @package i18n
+ */
+lmb_require('limb/datetime/src/lmbLocaleDate.class.php');
+lmb_require('limb/i18n/toolkit.inc.php');
+
+class lmbLocaleDateFormatTest extends UnitTestCase
+{
+ function testFormatWithoutLocale()
+ {
+ $date = new lmbLocaleDate('2005-01-02 23:05:03');
+ $string = $date->localeStrftime('%C %d %D %e %E %H %I %j %m %M %n %R %S %U %y %Y %t %%');
+
+ $this->assertEqual($string, "20 02 01/02/05 2 2453373 23 11 002 01 05 \n 23:05 03 53 05 2005 \t %");
+ }
+
+ function testLocalizedFormat()
+ {
+ $date = new lmbLocaleDate('2005-01-20 10:15:30');
+
+ $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
+
+ $res = $date->localeStrftime($locale->getDateFormat(), $locale);
+
+ $expected = 'Thursday 20 January 2005';
+ $this->assertEqual($res, $expected);
+ }
+}
+?>
Modified: 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php 2007-05-07 11:13:08 UTC (rev 5821)
+++ 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php 2007-05-07 11:14:00 UTC (rev 5822)
@@ -47,20 +47,18 @@
catch(lmbException $e){}
}
- function testLocalizedDateStringToISODateString()
+ function testIsLocalStringValid()
{
- $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../ru.ini'));
+ $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $date_string = '24.10.2005';
- $this->assertEqual(lmbLocaleDate :: localStringToISO($locale, $date_string), '2005-10-24 00:00:00');
+ $this->assertTrue(lmbLocaleDate :: isLocalStringValid($locale, 'Mon 01', '%a %d'));
}
- function testIsoDateStringToLocalStringizedDateString()
+ function testIsLocalStringNotValid()
{
- $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../ru.ini'));
+ $locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $iso_date_string = '2005-10-24 00:00:00';
- $this->assertEqual(lmbLocaleDate :: ISOToLocalString($locale, $iso_date_string), '24.10.2005');
+ $this->assertFalse(lmbLocaleDate :: isLocalStringValid($locale, '02-29-2003', '%a %d %b %Y'));
}
}
?>
\ No newline at end of file
More information about the limb-svn
mailing list