[pLog-svn] r4796 - in plog/branches/lifetype-1.2/class: locale test/tests/locale

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Feb 20 18:18:44 EST 2007


Author: oscar
Date: 2007-02-20 18:18:44 -0500 (Tue, 20 Feb 2007)
New Revision: 4796

Modified:
   plog/branches/lifetype-1.2/class/locale/locale.class.php
   plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php
Log:
Any usefulness unit tests might have is completely negated when the tests are too simple, which is what just happened to me. The parameters needed by strpos were swapped all over the place but my tests were so simple that this wasn't detected...


Modified: plog/branches/lifetype-1.2/class/locale/locale.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/locale/locale.class.php	2007-02-20 22:29:58 UTC (rev 4795)
+++ plog/branches/lifetype-1.2/class/locale/locale.class.php	2007-02-20 23:18:44 UTC (rev 4796)
@@ -512,23 +512,22 @@
                 $timeZoneSec += ( $timeDiff * 3600 );
             }				
 				
-			$text = $format;				
+			$text = $format;
 				
-			if( strpos( "%a", $text )  !== FALSE ) {
+			if( strpos( $text, "%a" ) !== FALSE ) {
 	            $weekdayId = $timeStamp->getWeekdayId();
 	            $weekday = $this->_messages["days"][$weekdayId];
 	            if( !empty( $this->_messages["weekdaysshort"] ) )
 	            	$shortWeekday = $this->_messages["weekdaysshort"][$weekdayId];
 	            else
-	            	$shortWeekday = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3 )) : substr($weekday, 0, 3);
-	
+	            	$shortWeekday = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3 )) : substr($weekday, 0, 3);	
 				$text = str_replace( "%a", $shortWeekday, $text );
 			}
-			if( strpos( "%A", $text ) !== FALSE ) {
+			if( strpos( $text, "%A" ) !== FALSE ) {
 	            $weekdayId = $timeStamp->getWeekdayId();	
 				$text = str_replace( "%A", $this->_messages["days"][$weekdayId], $text );	
 			}
-			if( strpos( "%b", $text ) !== FALSE ) {
+			if( strpos( $text, "%b" ) !== FALSE ) {
 	            $monthId    = (int)$timeStamp->getMonth();
 	            $monthStr   = $this->_messages["months"][$monthId-1];
 	            if( !empty( $this->_messages["monthsshort"] ) )
@@ -538,47 +537,47 @@
 
 				$text = str_replace( "%b", $shortMonthStr, $text );				
 			}
-			if( strpos( "%B", $text ) !== FALSE ) {
-	            $monthId    = (int)$timeStamp->getMonth();
+			if( strpos( $text, "%B" ) !== FALSE ) {
+	            $monthId = (int)$timeStamp->getMonth();
 				$text = str_replace( "%B", $this->_messages["months"][$monthId-1], $text );				
 			}	
-			if( strpos( "%d", $text ) !== FALSE ) {
+			if( strpos( $text, "%d" ) !== FALSE ) {
 				$text = str_replace( "%d", ($timeStamp->getDay() < 10) ? "0".$timeStamp->getDay() : $timeStamp->getDay(), $text );
 			}
-			if( strpos( "%e", $text ) !== FALSE ) {
+			if( strpos( $text, "%e" ) !== FALSE ) {
 				$text = str_replace( "%e", intval($timeStamp->getDay()), $text );
 			}
-			if( strpos( "%j", $text ) !== FALSE ) {
+			if( strpos( $text, "%j" ) !== FALSE ) {
 				$text = str_replace( "%j", $timeStamp->getDay(), $text );
 			}
-			if( strpos( "%H", $text ) !== FALSE ) {
+			if( strpos( $text, "%H" ) !== FALSE ) {
 				$text = str_replace( "%H", $timeStamp->getHour(), $text );				
 			}			
-			if( strpos( "%I", $text ) !== FALSE ) {
+			if( strpos( $text, "%I" ) !== FALSE ) {
 				$text = str_replace( "%I", ($timeStamp->getHour() != 0) ? ($timeStamp->getHour() > 12) ? $timeStamp->getHour()-12 : $timeStamp->getHour()+0 : 12, $text );	
 			}
-			if( strpos( "%p", $text ) !== FALSE ) {
+			if( strpos( $text, "%p" ) !== FALSE ) {
 				$text = str_replace( "%p", $timeStamp->getHour() >= 12 ? "pm" : "am", $text );					
 			}
-			if( strpos( "%P", $text ) !== FALSE ) {
+			if( strpos( $text, "%P" ) !== FALSE ) {
 				$text = str_replace( "%P", $timeStamp->getHour() >= 12 ? "PM" : "AM", $text );				
 			}
-			if( strpos( "%M", $text ) !== FALSE ) {
+			if( strpos( $text, "%M" ) !== FALSE ) {
 				$text = str_replace( "%M",  $timeStamp->getMinutes(), $text );					
 			}
-			if( strpos( "%m", $text ) !== FALSE ) {
+			if( strpos( $text, "%m" ) !== FALSE ) {
 				$text = str_replace( "%m", $timeStamp->getMonth(), $text );				
 			}
-			if( strpos( "%S", $text ) !== FALSE ) {
+			if( strpos( $text, "%S" ) !== FALSE ) {
 				$text = str_replace( "%S", $timeStamp->getSeconds(), $text );					
 			}
-			if( strpos( "%y", $text ) !== FALSE ) {
+			if( strpos( $text, "%y" ) !== FALSE ) {
 				$text = str_replace( "%y", substr($timeStamp->getYear(), 2, 4 ), $text );									
 			}
-			if( strpos( "%Y", $text ) !== FALSE ) {
+			if( strpos( $text, "%Y" ) !== FALSE ) {
 				$text = str_replace( "%Y", $timeStamp->getYear(), $text );				
 			}
-			if( strpos( "%O", $text ) !== FALSE ) {
+			if( strpos( $text, "%O" ) !== FALSE ) {
 	            // Now convert the time zone seconds to hours and minutes
 	            $timeZoneHours = intval( abs($timeZoneSec) / 3600 );
 	            $timeZoneMins = intval(( abs($timeZoneSec) % 3600 ) / 60 );
@@ -586,16 +585,16 @@
 				
 				$text = str_replace( "%O", sprintf( "%s%02d%02d", $timeZoneDirection, $timeZoneHours, $timeZoneMins ), $text );				
 			}					
-			if( strpos( "%%", $text ) !== FALSE ) {
+			if( strpos( $text, "%%" ) !== FALSE ) {
 				$text = str_replace( "%%", "%", $text );				
 			}
-			if( strpos( "%T", $text ) !== FALSE ) {
+			if( strpos( $text, "%T" ) !== FALSE ) {
 	            $monthId    = (int)$timeStamp->getMonth();
 	            $monthStr   = $this->_messages["months"][$monthId-1];				
 	
 				$text = str_replace( "%T", $this->getDayOrdinal( $timeStamp )." ".$this->tr("of")." ".$monthStr, $text );				
 			}			
-			if( strpos( "%D", $text ) !== FALSE ) {
+			if( strpos( $text, "%D" ) !== FALSE ) {
 				$text = str_replace( "%D", $this->getDayOrdinal( $timeStamp ), $text );				
 			}
 			
@@ -604,22 +603,22 @@
 	    		lt_include( PLOG_CLASS_PATH."class/data/jalalicalendar.class.php" );
 	            list( $jyear, $jmonth, $jday ) = JalaliCalendar::gregorian_to_jalali(gmdate( "Y", $time ), gmdate( "m", $time ), gmdate( "d", $time ));
 	
-				if( strpos( "%q", $text ) !== FALSE ) {
+				if( strpos( $text, "%q" ) !== FALSE ) {
 		      		$text = str_replace( "%q", JalaliCalendar::Convertnumber2farsi($jyear), $text );				
 				}			
-				if( strpos( "%w", $text ) !== FALSE ) {
+				if( strpos( $text, "%w" ) !== FALSE ) {
 		      		$text = str_replace( "%w", JalaliCalendar::Convertnumber2farsi($jmonth), $text );
 				}			
-				if( strpos( "%o", $text ) !== FALSE ) {
+				if( strpos( $text, "%o" ) !== FALSE ) {
 		      		$text = str_replace( "%o", JalaliCalendar::Convertnumber2farsi($jday), $text );
 				}			
-				if( strpos( "%R", $text ) !== FALSE ) {
+				if( strpos( $text, "%R" ) !== FALSE ) {
 		      		$text = str_replace( "%R", JalaliCalendar::monthname($jmonth), $text );
 				}			
-				if( strpos( "%T", $text ) !== FALSE ) {
+				if( strpos( $text, "%T" ) !== FALSE ) {
 		      		$text = str_replace( "%T", JalaliCalendar::Convertnumber2farsi($timeStamp->getHour()), $text );					
 				}			
-				if( strpos( "%U", $text ) !== FALSE ) {
+				if( strpos( $text, "%U" ) !== FALSE ) {
 		      		$text = str_replace( "%U", JalaliCalendar::Convertnumber2farsi($timeStamp->getMinutes()), $text );
 				}
 			}			
@@ -688,7 +687,7 @@
 				
 			$text = $format;				
 				
-			if( strpos( "%a", $text )  !== FALSE ) {
+			if( strpos( $text, "%a" )  !== FALSE ) {
             	$weekdayId = gmdate( "w", $time );
 	            $weekday = $this->_messages["days"][$weekdayId];
 	            if( !empty( $this->_messages["weekdaysshort"] ) )
@@ -698,11 +697,11 @@
 	
 				$text = str_replace( "%a", $shortWeekday, $text );
 			}
-			if( strpos( "%A", $text ) !== FALSE ) {
+			if( strpos( $text, "%A" ) !== FALSE ) {
             	$weekdayId = gmdate( "w", $time );
 				$text = str_replace( "%A", $this->_messages["days"][$weekdayId], $text );	
 			}
-			if( strpos( "%b", $text ) !== FALSE ) {
+			if( strpos( $text, "%b" ) !== FALSE ) {
             	$monthId = gmdate( "n", $time );
 	            $monthStr   = $this->_messages["months"][$monthId-1];
 	            if( !empty( $this->_messages["monthsshort"] ) )
@@ -712,59 +711,59 @@
 
 				$text = str_replace( "%b", $shortMonthStr, $text );				
 			}
-			if( strpos( "%B", $text ) !== FALSE ) {
+			if( strpos( $text, "%B" ) !== FALSE ) {
             	$monthId = gmdate( "n", $time );
 				$text = str_replace( "%B", $this->_messages["months"][$monthId-1], $text );				
 			}	
-			if( strpos( "%d", $text ) !== FALSE ) {
+			if( strpos( $text, "%d" ) !== FALSE ) {
 				$text = str_replace( "%d", gmdate( "d", $time ), $text );
 			}
-			if( strpos( "%e", $text ) !== FALSE ) {
+			if( strpos( $text, "%e" ) !== FALSE ) {
 				$text = str_replace( "%e", intval(gmdate( "d", $time )), $text );
 			}
-			if( strpos( "%j", $text ) !== FALSE ) {
+			if( strpos( $text, "%j" ) !== FALSE ) {
 				$text = str_replace( "%j", gmdate( "j", $time ), $text );
 			}
-			if( strpos( "%H", $text ) !== FALSE ) {
+			if( strpos( $text, "%H" ) !== FALSE ) {
 				$text = str_replace( "%H", gmdate( "H", $time ), $text );				
 			}			
-			if( strpos( "%I", $text ) !== FALSE ) {
+			if( strpos( $text, "%I" ) !== FALSE ) {
 				$text = str_replace( "%I", gmdate( "g", $time ), $text );	
 			}
-			if( strpos( "%p", $text ) !== FALSE ) {
+			if( strpos( $text, "%p" ) !== FALSE ) {
 				$text = str_replace( "%p", gmdate( "a", $time ), $text );					
 			}
-			if( strpos( "%P", $text ) !== FALSE ) {
+			if( strpos( $text, "%P" ) !== FALSE ) {
 				$text = str_replace( "%P", gmdate( "A", $time ), $text );				
 			}
-			if( strpos( "%M", $text ) !== FALSE ) {
+			if( strpos( $text, "%M" ) !== FALSE ) {
 				$text = str_replace( "%M",  gmdate( "i", $time ), $text );					
 			}
-			if( strpos( "%m", $text ) !== FALSE ) {
+			if( strpos( $text, "%m") !== FALSE ) {
 				$text = str_replace( "%m", gmdate( "m", $time ), $text );				
 			}
-			if( strpos( "%S", $text ) !== FALSE ) {
+			if( strpos( $text, "%S" ) !== FALSE ) {
 				$text = str_replace( "%S", gmdate( "s", $time ), $text );					
 			}
-			if( strpos( "%y", $text ) !== FALSE ) {
+			if( strpos( $text, "%y" ) !== FALSE ) {
 				$text = str_replace( "%y", gmdate( "y", $time ), $text );									
 			}
-			if( strpos( "%Y", $text ) !== FALSE ) {
+			if( strpos( $text, "%Y" ) !== FALSE ) {
 				$text = str_replace( "%Y", gmdate( "Y", $time ), $text );				
 			}
-			if( strpos( "%O", $text ) !== FALSE ) {
+			if( strpos( $text, "%O" ) !== FALSE ) {
 				$text = str_replace( "%O", "+0000", $text );				
 			}					
-			if( strpos( "%%", $text ) !== FALSE ) {
+			if( strpos( $text, "%%" ) !== FALSE ) {
 				$text = str_replace( "%%", "%", $text );
 			}
-			if( strpos( "%T", $text ) !== FALSE ) {
+			if( strpos( $text, "%T" ) !== FALSE ) {
 	            $monthId    = (int)$timeStamp->getMonth();
 	            $monthStr   = $this->_messages["months"][$monthId-1];				
 	
 				$text = str_replace( "%T", $this->getDateOrdinal( gmdate( "d", $time ))." ".$this->tr("of")." ".$monthStr, $text );				
 			}			
-			if( strpos( "%D", $text ) !== FALSE ) {
+			if( strpos( $text, "%D" ) !== FALSE ) {
 				$text = str_replace( "%D", $this->getDateOrdinal( gmdate( "d", $time )), $text );
 			}
 			
@@ -773,22 +772,22 @@
 	    		lt_include( PLOG_CLASS_PATH."class/data/jalalicalendar.class.php" );
 	            list( $jyear, $jmonth, $jday ) = JalaliCalendar::gregorian_to_jalali(gmdate( "Y", $time ), gmdate( "m", $time ), gmdate( "d", $time ));
 	
-				if( strpos( "%q", $text ) !== FALSE ) {
+				if( strpos( $text, "%q" ) !== FALSE ) {
 		      		$text = str_replace( "%q", JalaliCalendar::Convertnumber2farsi($jyear), $text );				
 				}			
-				if( strpos( "%w", $text ) !== FALSE ) {
+				if( strpos( $text, "%w" ) !== FALSE ) {
 		      		$text = str_replace( "%w", JalaliCalendar::Convertnumber2farsi($jmonth), $text );
 				}			
-				if( strpos( "%o", $text ) !== FALSE ) {
+				if( strpos( $text, "%o" ) !== FALSE ) {
 		      		$text = str_replace( "%o", JalaliCalendar::Convertnumber2farsi($jday), $text );
 				}			
-				if( strpos( "%R", $text ) !== FALSE ) {
+				if( strpos( $text, "%R" ) !== FALSE ) {
 		      		$text = str_replace( "%R", JalaliCalendar::monthname($jmonth), $text );
 				}			
-				if( strpos( "%T", $text ) !== FALSE ) {
+				if( strpos( $text, "%T" ) !== FALSE ) {
 		      		$text = str_replace( "%T", JalaliCalendar::Convertnumber2farsi(gmdate( "H", $time )), $text );
 				}			
-				if( strpos( "%U", $text ) !== FALSE ) {
+				if( strpos( $text, "%U" ) !== FALSE ) {
 		      		$text = str_replace( "%U", JalaliCalendar::Convertnumber2farsi(gmdate( "i", $time )), $text );
 				}
 			}			

Modified: 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	2007-02-20 22:29:58 UTC (rev 4795)
+++ plog/branches/lifetype-1.2/class/test/tests/locale/locale_test.class.php	2007-02-20 23:18:44 UTC (rev 4796)
@@ -67,6 +67,12 @@
 			$this->assertEquals( "%", $this->l->formatDate( $d, "%%" ));
 			$this->assertEquals( "5th of February", $this->l->formatDate( $d, "%T" ));			
 			$this->assertEquals( "5th", $this->l->formatDate( $d, "%D" ));						
+			
+			// a longer format test
+			$this->assertEquals( "Feb ", $this->l->formatDate( $d, "%b " ));
+			$this->assertEquals( "Feb 5", $this->l->formatDate( $d, "%b %j" ));
+			$this->assertEquals( "05/02/2007", $this->l->formatDate( $d, "%d/%m/%Y" ));
+			$this->assertEquals( "05 February, 2007 23:00", $this->l->formatDate( $d, "%d %B, %Y %H:%M" ));
 		}
 		
 		/**
@@ -94,7 +100,13 @@
 			$this->assertEquals( "2007", $this->l->formatDateGMT( $d, "%Y" ));
 			$this->assertEquals( "%", $this->l->formatDateGMT( $d, "%%" ));
 			$this->assertEquals( "5th of February", $this->l->formatDateGMT( $d, "%T" ));			
-			$this->assertEquals( "5th", $this->l->formatDateGMT( $d, "%D" ));						
+			$this->assertEquals( "5th", $this->l->formatDateGMT( $d, "%D" ));	
+			
+			// a longer format test
+			$this->assertEquals( "Feb ", $this->l->formatDateGMT( $d, "%b " ));
+			$this->assertEquals( "Feb 5", $this->l->formatDateGMT( $d, "%b %j" ));
+			$this->assertEquals( "05/02/2007", $this->l->formatDateGMT( $d, "%d/%m/%Y" ));
+			$this->assertEquals( "05 February, 2007 21:00", $this->l->formatDateGMT( $d, "%d %B, %Y %H:%M" ));								
 		}		
 	}
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list