[limb-svn] r6535 - in 3.x/trunk/limb/i18n: src/datetime src/template/tags/i18n tests/cases/datetime tests/cases/template/tags/i18n
svn at limb-project.com
svn at limb-project.com
Thu Nov 22 10:25:47 MSK 2007
Author: pachanga
Date: 2007-11-22 10:25:47 +0300 (Thu, 22 Nov 2007)
New Revision: 6535
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6535
Added:
3.x/trunk/limb/i18n/src/datetime/lmbLocaleDateTime.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/lmbLocaleDateFormatTest.class.php
3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php
3.x/trunk/limb/i18n/tests/cases/template/tags/i18n/lmbI18NDateFilterTest.class.php
Log:
-- lmbLocaleDate is now obsolete, lmbLocaleDateTime should be used instead
Modified: 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php 2007-11-22 07:24:57 UTC (rev 6534)
+++ 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDate.class.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -6,386 +6,18 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/core/src/exception/lmbException.class.php');
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/i18n/src/datetime/lmbLocaleDateTime.class.php');
/**
- * class lmbLocaleDate.
+ * class lmbLocaleDateTime.
*
+ * This class is OBSOLETE, use lmbLocaleDateTime instead
+ *
* @package i18n
* @version $Id$
*/
-class lmbLocaleDate extends lmbDate
+class lmbLocaleDate extends lmbLocaleDateTime
{
- /**
- * 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':
- self :: _ensureLocale($locale);
- $output .= $locale->getDayName($this->getPhpDayOfWeek(), true);
- break;
- case 'A':
- self :: _ensureLocale($locale);
- $output .= $locale->getDayName($this->getPhpDayOfWeek());
- break;
- case 'b':
- self :: _ensureLocale($locale);
- $output .= $locale->getMonthName($this->getMonth() - 1, true);
- break;
- case 'B':
- self :: _ensureLocale($locale);
- $output .= $locale->getMonthName($this->getMonth() - 1);
- break;
- case 'p':
- self :: _ensureLocale($locale);
- $output .= $locale->getMeridiemName($this->getHour());
- break;
- case 'P':
- self :: _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->getDateDays();
- 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->getPhpDayOfWeek();
- 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;
- }
-
- 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 lmbLocaleDate($year_or_date, $month_or_tz, $day, $hour, $minute, $second, $tz);
- else
- return new lmbLocaleDate($year_or_date, $month_or_tz);
- }
-
- function getShortDateFormatted($locale = null)
- {
- self :: _ensureLocale($locale);
- return $this->localeStrftime($locale->short_date_format, $locale);
- }
-
- function getShortDateTimeFormatted($locale = null)
- {
- self :: _ensureLocale($locale);
- return $this->localeStrftime($locale->short_date_time_format, $locale);
- }
-
- static function createFromShortDateFormat($string, $locale = null)
- {
- self :: _ensureLocale($locale);
- return self :: localStringToDate($locale, $string, $locale->short_date_format);
- }
-
- static function createFromShortDateTimeFormat($string, $locale = null)
- {
- self :: _ensureLocale($locale);
- return self :: localStringToDate($locale, $string, $locale->short_date_time_format);
- }
-
- /**
- * 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.
- */
- static function parseTimeString($locale, $time_string, $fmt)
- {
- $hour = 0;
- $minute = 0;
- $second = 0;
- $month = 0;
- $day = 0;
- $year = 0;
-
- if(!($time_array = self :: explodeTimeStringByFormat($time_string, $fmt)))
- return -1;
-
- foreach($time_array as $time_char => $value)
- {
- switch($time_char)
- {
- case '%p':
- case '%P':
- if(strtolower($value) == $locale->getPmName())
- $hour += 12;
- break;
-
- case '%I':
- case '%H':
- $hour = (int)$value;
- break;
-
- case '%M':
- $minute = (int)$value;
- break;
-
- case '%S':
- $second = (int)$value;
- break;
-
- case '%m':
- $month = (int)$value;
- break;
-
- case '%b':
- case '%h':
- if(($index = array_search($value, $locale->getMonthNames(true))) !== false)
- {
- if($index !== false)
- $month = $index + 1;
- }
- break;
-
- case '%B':
- if(($index = array_search($value, $locale->getMonthNames())) !== false)
- {
- if($index !== false)
- $month = $index + 1;
- }
- break;
-
- case '%d':
- $day = (int)$value;
- break;
-
- case '%Y':
- $year = (int)$value;
- break;
- case '%y':
- if($value < 40)
- $year = 2000 + $value;
- else
- $year = 1900 + $value;
- break;
-
- case '%T':
- if ($regs = explode(':', $value))
- {
- $hour = (int)$regs[1];
- $minute = (int)$regs[2];
- $second = (int)$regs[3];
- }
- break;
-
- case '%D':
- if ($regs = explode('/', $value))
- {
- $hour = (int)$regs[1];
- $minute = (int)$regs[2];
- $second = (int)$regs[3];
- }
- break;
-
- case '%R':
- if ($regs = explode(':', $value))
- {
- $hour = (int)$regs[1];
- $minute = (int)$regs[2];
- }
- break;
- }
- }
- return array('hour' => $hour, 'minute' => $minute, 'second' => $second, 'month' => $month, 'day' => $day, 'year' => $year);
- }
-
- static function explodeTimeStringByFormat($time_string, $fmt)
- {
- $fmt_len = strlen($fmt);
- $time_string_len = strlen($time_string);
-
- $time_array = array();
-
- $fmt_pos = 0;
- $time_string_pos = 0;
-
- while(($fmt_pos = strpos($fmt, '%', $fmt_pos)) !== false)
- {
- $current_time_char = $fmt{++$fmt_pos};
-
- if(($fmt_pos+1) >= $fmt_len)
- $delimiter_pos = $time_string_len;
- elseif($time_string_pos <= $time_string_len)
- {
- $current_delimiter = $fmt{++$fmt_pos};
- $delimiter_pos = strpos($time_string, $current_delimiter, $time_string_pos);
- if($delimiter_pos === false)
- $delimiter_pos = $time_string_len;
- }
-
- $delimiter_len = $delimiter_pos - $time_string_pos;
-
- $value = substr($time_string, $time_string_pos, $delimiter_len);
-
- if(preg_match("/[-\/]/", $value))
- throw new lmbException("Wrong date format: $time_string does not matches $fmt format");
-
- $time_array['%' . $current_time_char] = $value;
-
- $time_string_pos += ($delimiter_len + 1);
- }
-
- return $time_array;
- }
-
- static protected function _ensureLocale(&$locale)
- {
- if(!is_object($locale))
- $locale = lmbToolkit :: instance()->getLocaleObject();
- }
-
- static function localStringToDate($locale, $string, $format = null)
- {
- if(!$format)
- $format = $locale->getShortDateFormat();
-
- $arr = self :: parseTimeString($locale, $string, $format);
- return new lmbLocaleDate($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']);
- }
-
- static function isLocalStringValid($locale, $string, $format = null)
- {
- try
- {
- lmbLocaleDate :: localStringToDate($locale, $string, $format);
- return true;
- }
- catch(lmbException $e)
- {
- return false;
- }
- }
}
Added: 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDateTime.class.php
===================================================================
--- 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDateTime.class.php (rev 0)
+++ 3.x/trunk/limb/i18n/src/datetime/lmbLocaleDateTime.class.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -0,0 +1,391 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/core/src/exception/lmbException.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
+
+/**
+ * class lmbLocaleDateTime.
+ *
+ * @package i18n
+ * @version $Id: lmbLocaleDateTime.class.php 6475 2007-10-31 09:30:46Z korchasa $
+ */
+class lmbLocaleDateTime extends lmbDateTime
+{
+ /**
+ * 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':
+ self :: _ensureLocale($locale);
+ $output .= $locale->getDayName($this->getPhpDayOfWeek(), true);
+ break;
+ case 'A':
+ self :: _ensureLocale($locale);
+ $output .= $locale->getDayName($this->getPhpDayOfWeek());
+ break;
+ case 'b':
+ self :: _ensureLocale($locale);
+ $output .= $locale->getMonthName($this->getMonth() - 1, true);
+ break;
+ case 'B':
+ self :: _ensureLocale($locale);
+ $output .= $locale->getMonthName($this->getMonth() - 1);
+ break;
+ case 'p':
+ self :: _ensureLocale($locale);
+ $output .= $locale->getMeridiemName($this->getHour());
+ break;
+ case 'P':
+ self :: _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->getDateDays();
+ 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->getPhpDayOfWeek();
+ 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;
+ }
+
+ 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 lmbLocaleDateTime($year_or_date, $month_or_tz, $day, $hour, $minute, $second, $tz);
+ else
+ return new lmbLocaleDateTime($year_or_date, $month_or_tz);
+ }
+
+ function getShortDateFormatted($locale = null)
+ {
+ self :: _ensureLocale($locale);
+ return $this->localeStrftime($locale->short_date_format, $locale);
+ }
+
+ function getShortDateTimeFormatted($locale = null)
+ {
+ self :: _ensureLocale($locale);
+ return $this->localeStrftime($locale->short_date_time_format, $locale);
+ }
+
+ static function createFromShortDateFormat($string, $locale = null)
+ {
+ self :: _ensureLocale($locale);
+ return self :: localStringToDate($locale, $string, $locale->short_date_format);
+ }
+
+ static function createFromShortDateTimeFormat($string, $locale = null)
+ {
+ self :: _ensureLocale($locale);
+ return self :: localStringToDate($locale, $string, $locale->short_date_time_format);
+ }
+
+ /**
+ * 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.
+ */
+ static function parseTimeString($locale, $time_string, $fmt)
+ {
+ $hour = 0;
+ $minute = 0;
+ $second = 0;
+ $month = 0;
+ $day = 0;
+ $year = 0;
+
+ if(!($time_array = self :: explodeTimeStringByFormat($time_string, $fmt)))
+ return -1;
+
+ foreach($time_array as $time_char => $value)
+ {
+ switch($time_char)
+ {
+ case '%p':
+ case '%P':
+ if(strtolower($value) == $locale->getPmName())
+ $hour += 12;
+ break;
+
+ case '%I':
+ case '%H':
+ $hour = (int)$value;
+ break;
+
+ case '%M':
+ $minute = (int)$value;
+ break;
+
+ case '%S':
+ $second = (int)$value;
+ break;
+
+ case '%m':
+ $month = (int)$value;
+ break;
+
+ case '%b':
+ case '%h':
+ if(($index = array_search($value, $locale->getMonthNames(true))) !== false)
+ {
+ if($index !== false)
+ $month = $index + 1;
+ }
+ break;
+
+ case '%B':
+ if(($index = array_search($value, $locale->getMonthNames())) !== false)
+ {
+ if($index !== false)
+ $month = $index + 1;
+ }
+ break;
+
+ case '%d':
+ $day = (int)$value;
+ break;
+
+ case '%Y':
+ $year = (int)$value;
+ break;
+ case '%y':
+ if($value < 40)
+ $year = 2000 + $value;
+ else
+ $year = 1900 + $value;
+ break;
+
+ case '%T':
+ if ($regs = explode(':', $value))
+ {
+ $hour = (int)$regs[1];
+ $minute = (int)$regs[2];
+ $second = (int)$regs[3];
+ }
+ break;
+
+ case '%D':
+ if ($regs = explode('/', $value))
+ {
+ $hour = (int)$regs[1];
+ $minute = (int)$regs[2];
+ $second = (int)$regs[3];
+ }
+ break;
+
+ case '%R':
+ if ($regs = explode(':', $value))
+ {
+ $hour = (int)$regs[1];
+ $minute = (int)$regs[2];
+ }
+ break;
+ }
+ }
+ return array('hour' => $hour, 'minute' => $minute, 'second' => $second, 'month' => $month, 'day' => $day, 'year' => $year);
+ }
+
+ static function explodeTimeStringByFormat($time_string, $fmt)
+ {
+ $fmt_len = strlen($fmt);
+ $time_string_len = strlen($time_string);
+
+ $time_array = array();
+
+ $fmt_pos = 0;
+ $time_string_pos = 0;
+
+ while(($fmt_pos = strpos($fmt, '%', $fmt_pos)) !== false)
+ {
+ $current_time_char = $fmt{++$fmt_pos};
+
+ if(($fmt_pos+1) >= $fmt_len)
+ $delimiter_pos = $time_string_len;
+ elseif($time_string_pos <= $time_string_len)
+ {
+ $current_delimiter = $fmt{++$fmt_pos};
+ $delimiter_pos = strpos($time_string, $current_delimiter, $time_string_pos);
+ if($delimiter_pos === false)
+ $delimiter_pos = $time_string_len;
+ }
+
+ $delimiter_len = $delimiter_pos - $time_string_pos;
+
+ $value = substr($time_string, $time_string_pos, $delimiter_len);
+
+ if(preg_match("/[-\/]/", $value))
+ throw new lmbException("Wrong date format: $time_string does not matches $fmt format");
+
+ $time_array['%' . $current_time_char] = $value;
+
+ $time_string_pos += ($delimiter_len + 1);
+ }
+
+ return $time_array;
+ }
+
+ static protected function _ensureLocale(&$locale)
+ {
+ if(!is_object($locale))
+ $locale = lmbToolkit :: instance()->getLocaleObject();
+ }
+
+ static function localStringToDate($locale, $string, $format = null)
+ {
+ if(!$format)
+ $format = $locale->getShortDateFormat();
+
+ $arr = self :: parseTimeString($locale, $string, $format);
+ return new lmbLocaleDateTime($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']);
+ }
+
+ static function isLocalStringValid($locale, $string, $format = null)
+ {
+ try
+ {
+ lmbLocaleDateTime :: localStringToDate($locale, $string, $format);
+ return true;
+ }
+ catch(lmbException $e)
+ {
+ return false;
+ }
+ }
+}
+
+
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-11-22 07:24:57 UTC (rev 6534)
+++ 3.x/trunk/limb/i18n/src/template/tags/i18n/date.filter.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -6,7 +6,7 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/i18n/src/datetime/lmbLocaleDate.class.php');
+lmb_require('limb/i18n/src/datetime/lmbLocaleDateTime.class.php');
/**
* @filter i18n_date
@@ -33,7 +33,7 @@
else
$locale = $toolkit->getLocaleObject();
- $this->date = new lmbLocaleDate();
+ $this->date = new lmbLocaleDateTime();
$this->_setDate();
@@ -54,14 +54,14 @@
switch($date_type)
{
case 'string':
- $this->date = new lmbLocaleDate($value);
+ $this->date = new lmbLocaleDateTime($value);
break;
case 'stamp':
- $this->date = new lmbLocaleDate((int)$value);
+ $this->date = new lmbLocaleDateTime((int)$value);
break;
default:
- $this->date = new lmbLocaleDate($value);
+ $this->date = new lmbLocaleDateTime($value);
break;
}
}
@@ -87,7 +87,7 @@
$toolkit_var = $code->getTempVarRef();
$this->locale_var = $code->getTempVarRef();
- $code->writePHP("lmb_require('limb/i18n/src/datetime/lmbLocaleDate.class.php');");
+ $code->writePHP("lmb_require('limb/i18n/src/datetime/lmbLocaleDateTime.class.php');");
$code->writePHP($toolkit_var . ' = lmbToolkit :: instance();' . "\n");
$code->writePHP($this->locale_var . ' = ');
@@ -116,19 +116,19 @@
switch($date_type)
{
case 'stamp':
- $code->writePHP($this->date_var . ' = new lmbLocaleDate((int)');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDateTime((int)');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
case 'string':
- $code->writePHP($this->date_var . ' = new lmbLocaleDate(');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDateTime(');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
default:
- $code->writePHP($this->date_var . ' = new lmbLocaleDate((int)');
+ $code->writePHP($this->date_var . ' = new lmbLocaleDateTime((int)');
$this->base->generateExpression($code);
$code->writePHP(');');
break;
Modified: 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
+++ 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateFormatTest.class.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -6,14 +6,14 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/i18n/src/datetime/lmbLocaleDate.class.php');
+lmb_require('limb/i18n/src/datetime/lmbLocaleDateTime.class.php');
lmb_require('limb/i18n/toolkit.inc.php');
-class lmbLocaleDateFormatTest extends UnitTestCase
+class lmbLocaleDateTimeFormatTest extends UnitTestCase
{
function testFormatWithoutLocale()
{
- $date = new lmbLocaleDate('2005-01-02 23:05:03');
+ $date = new lmbLocaleDateTime('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 1 05 2005 \t %");
@@ -21,7 +21,7 @@
function testLocalizedFormat()
{
- $date = new lmbLocaleDate('2005-01-20 10:15:30');
+ $date = new lmbLocaleDateTime('2005-01-20 10:15:30');
$locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
Modified: 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
+++ 3.x/trunk/limb/i18n/tests/cases/datetime/lmbLocaleDateTest.class.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -6,15 +6,15 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/i18n/src/datetime/lmbLocaleDate.class.php');
+lmb_require('limb/i18n/src/datetime/lmbLocaleDateTime.class.php');
-class lmbLocaleDateTest extends UnitTestCase
+class lmbLocaleDateTimeTest extends UnitTestCase
{
function testCreateByLocaleString()
{
$locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $date = lmbLocaleDate :: localStringToDate($locale, 'Thursday 20 January 2005', '%A %d %B %Y');
+ $date = lmbLocaleDateTime :: localStringToDate($locale, 'Thursday 20 January 2005', '%A %d %B %Y');
$this->assertEqual($date->getMonth(), 1);
$this->assertEqual($date->getYear(), 2005);
@@ -25,7 +25,7 @@
{
$locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $date = lmbLocaleDate :: localStringToDate($locale, 'Thu 20 Jan 2005', '%a %d %b %Y');
+ $date = lmbLocaleDateTime :: localStringToDate($locale, 'Thu 20 Jan 2005', '%a %d %b %Y');
$this->assertEqual($date->getMonth(), 1);
$this->assertEqual($date->getYear(), 2005);
@@ -38,7 +38,7 @@
try
{
- $date = lmbLocaleDate :: localStringToDate($locale, '02-29-2003', '%a %d %b %Y');
+ $date = lmbLocaleDateTime :: localStringToDate($locale, '02-29-2003', '%a %d %b %Y');
$this->assertTrue(false);
}
catch(lmbException $e){}
@@ -48,14 +48,14 @@
{
$locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $this->assertTrue(lmbLocaleDate :: isLocalStringValid($locale, 'Mon 01', '%a %d'));
+ $this->assertTrue(lmbLocaleDateTime :: isLocalStringValid($locale, 'Mon 01', '%a %d'));
}
function testIsLocalStringNotValid()
{
$locale = new lmbLocale('en', new lmbIni(dirname(__FILE__) . '/../en.ini'));
- $this->assertFalse(lmbLocaleDate :: isLocalStringValid($locale, '02-29-2003', '%a %d %b %Y'));
+ $this->assertFalse(lmbLocaleDateTime :: isLocalStringValid($locale, '02-29-2003', '%a %d %b %Y'));
}
}
Modified: 3.x/trunk/limb/i18n/tests/cases/template/tags/i18n/lmbI18NDateFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/i18n/tests/cases/template/tags/i18n/lmbI18NDateFilterTest.class.php 2007-11-22 07:24:57 UTC (rev 6534)
+++ 3.x/trunk/limb/i18n/tests/cases/template/tags/i18n/lmbI18NDateFilterTest.class.php 2007-11-22 07:25:47 UTC (rev 6535)
@@ -6,7 +6,7 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/datetime/src/lmbDate.class.php');
+lmb_require('limb/datetime/src/lmbDateTime.class.php');
class lmbI18NDateFilterTest extends lmbWactTestCase
{
@@ -29,7 +29,7 @@
function testSetDateByStampValue()
{
- $date = new lmbDate('2004-12-20 10:15:30');
+ $date = new lmbDateTime('2004-12-20 10:15:30');
$template = '{$"' . $date->getStamp() . '"|i18n_date:"en", "stamp"}';
@@ -42,7 +42,7 @@
function testFormatType()
{
- $date = new lmbDate('2005-01-20 10:15:30');
+ $date = new lmbDateTime('2005-01-20 10:15:30');
$template = '{$"' . $date->getStamp() . '"|i18n_date:"en", "stamp", "date"}';
@@ -66,7 +66,7 @@
function testDefinedFormat()
{
- $date = new lmbDate('2004-12-20 10:15:30');
+ $date = new lmbDateTime('2004-12-20 10:15:30');
$template = '{$"' . $date->getStamp() . '"|i18n_date:"en", "stamp", "", "%Y %m %d"}';
@@ -82,7 +82,7 @@
$toolkit = lmbToolkit :: save();
$toolkit->addLocaleObject(new lmbLocale('ru', new lmbIni(dirname(__FILE__) . '/../../../ru.ini')));
- $date = new lmbDate('2004-12-20 10:15:30');
+ $date = new lmbDateTime('2004-12-20 10:15:30');
$template = '{$"' . $date->getStamp() . '"|i18n_date:"ru", "stamp"}';
@@ -110,7 +110,7 @@
function testDBESetDateByStampValue()
{
- $date = new lmbDate('2004-12-20 10:15:30');
+ $date = new lmbDateTime('2004-12-20 10:15:30');
$template = '{$var|i18n_date:"en", "stamp"}';
@@ -125,7 +125,7 @@
function testDBEFormatType()
{
- $date = new lmbDate('2005-01-20 10:15:30');
+ $date = new lmbDateTime('2005-01-20 10:15:30');
$template = '{$var|i18n_date:"en", "stamp", "date"}';
@@ -140,7 +140,7 @@
function testDBEDefinedFormat()
{
- $date = new lmbDate('2005-01-20 10:15:30');
+ $date = new lmbDateTime('2005-01-20 10:15:30');
$template = '{$var|i18n_date:"en", "stamp", "", "%Y %m %d"}';
@@ -158,7 +158,7 @@
$toolkit = lmbToolkit :: save();
$toolkit->addLocaleObject(new lmbLocale('ru', new lmbIni(dirname(__FILE__) . '/../../../ru.ini')));
- $date = new lmbDate('2005-01-20 10:15:30');
+ $date = new lmbDateTime('2005-01-20 10:15:30');
$template = '{$var|i18n_date:"ru", "stamp"}';
@@ -175,7 +175,7 @@
function testComplexPathBasedDBEWithDefinedFormat()
{
- $date = new lmbDate('2005-01-20 10:15:30');
+ $date = new lmbDateTime('2005-01-20 10:15:30');
$template = '{$my.var|i18n_date:"en", "stamp", "", "%Y %m %d"}';
More information about the limb-svn
mailing list