[pLog-svn] r4789 - in plog/branches/lifetype-1.2/class: locale test/tests test/tests/locale
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Mon Feb 19 17:12:47 EST 2007
Author: oscar
Date: 2007-02-19 17:12:47 -0500 (Mon, 19 Feb 2007)
New Revision: 4789
Added:
plog/branches/lifetype-1.2/class/test/tests/locale/
plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php
Modified:
plog/branches/lifetype-1.2/class/locale/locale.class.php
Log:
strpos should be faster than ereg, and a unit test added to make sure I didn't break anything
Modified: plog/branches/lifetype-1.2/class/locale/locale.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/locale/locale.class.php 2007-02-19 21:15:41 UTC (rev 4788)
+++ plog/branches/lifetype-1.2/class/locale/locale.class.php 2007-02-19 22:12:47 UTC (rev 4789)
@@ -559,6 +559,7 @@
$values["%%"] = "%";
$values["%T"] = $this->getDayOrdinal( $timeStamp )." ".$this->tr("of")." ".$monthStr;
$values["%D"] = $this->getDayOrdinal( $timeStamp );
+
/* Start Hack By FiFtHeLeMeNt For Persian Language */
if ( $this->_code == 'fa_IR' )
{
@@ -575,7 +576,7 @@
$text = $format;
foreach( array_keys($values) as $key ) {
- if( ereg($key, $text) )
+ if( strpos( $text, $key ) !== FALSE )
$text = str_replace( $key, $values[$key], $text );
}
Added: plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php (rev 0)
+++ plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php 2007-02-19 22:12:47 UTC (rev 4789)
@@ -0,0 +1,72 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/locale/locale.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+
+ /**
+ * \ingroup Test
+ *
+ * Test cases for the Locale class.
+ */
+ class Locale_Test extends LifeTypeTestCase
+ {
+ var $l;
+
+ function setUp()
+ {
+ // let's use the English locale as the base one
+ $this->l = new Locale( "en_UK" );
+ }
+
+ /**
+ * test all the modifiers from the Locale::formatDate() method:
+ *
+ * <li>%a abbreviated weekday</li>
+ * <li>%A complete weekday</li>
+ * <li>%b abbreviated month</li>
+ * <li>%B long month</li>
+ * <li>%d day of the month, 2 digits with leading zero</li>
+ * <li>%j day of the month, numeric (without leading zero)</li>
+ * <li>%H hours, in 24-h format</li>
+ * <li>%I hours, in 12-h format (without leading zero)</li>
+ * <li>%p returns 'am' or 'pm'</li>
+ * <li>%P returns 'AM' or 'PM'</li>
+ * <li>%M minutes</li>
+ * <li>%m month number, from 00 to 12</li>
+ * <li>%S seconds</li>
+ * <li>%y 2-digit year representation</li>
+ * <li>%Y 4-digit year representation</li>
+ * <li>%O Difference to Greenwich time (GMT) in hours</li>
+ * <li>%% the '%' character
+ * </ul>
+ * (these have been added by myself and are therefore incompatible with php)<ul>
+ * <li>%T "_day_ of _month_", where the day is in ordinal form and 'month' is the name of the month</li>
+ * <li>%D cardinal representation of the day</li>
+ */
+ function testFormatDate()
+ {
+ $d = new Timestamp( "20070205230000" );
+
+ $this->assertEquals( "Mon", $this->l->formatDate( $d, "%a" ));
+ $this->assertEquals( "Monday", $this->l->formatDate( $d, "%A" ));
+ $this->assertEquals( "Feb", $this->l->formatDate( $d, "%b" ));
+ $this->assertEquals( "February", $this->l->formatDate( $d, "%B" ));
+ $this->assertEquals( "05", $this->l->formatDate( $d, "%d" ));
+ $this->assertEquals( "5", $this->l->formatDate( $d, "%j" ));
+ $this->assertEquals( "23", $this->l->formatDate( $d, "%H" ));
+ $this->assertEquals( "11", $this->l->formatDate( $d, "%I" ));
+ $this->assertEquals( "pm", $this->l->formatDate( $d, "%p" ));
+ $this->assertEquals( "PM", $this->l->formatDate( $d, "%P" ));
+ $this->assertEquals( "00", $this->l->formatDate( $d, "%M" ));
+ $this->assertEquals( "02", $this->l->formatDate( $d, "%m" ));
+ $this->assertEquals( "00", $this->l->formatDate( $d, "%S" ));
+ $this->assertEquals( "07", $this->l->formatDate( $d, "%y" ));
+ $this->assertEquals( "2007", $this->l->formatDate( $d, "%Y" ));
+ $this->assertEquals( "%", $this->l->formatDate( $d, "%%" ));
+ $this->assertEquals( "5th of February", $this->l->formatDate( $d, "%T" ));
+ $this->assertEquals( "5th", $this->l->formatDate( $d, "%D" ));
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list