[pLog-svn] r2382 - in plog/branches/plog-1.0.2: class/locale templates/rss

pwestbro at devel.plogworld.net pwestbro at devel.plogworld.net
Mon Aug 1 16:12:52 GMT 2005


Author: pwestbro
Date: 2005-08-01 16:12:51 +0000 (Mon, 01 Aug 2005)
New Revision: 2382

Modified:
   plog/branches/plog-1.0.2/class/locale/locale.class.php
   plog/branches/plog-1.0.2/templates/rss/rss20.template
Log:
Fixed bug http://bugs.plogworld.net/view.php?id=442

Now for rss2.0 feeds the dates are correctly converted to GMT

This change does not fix the other feeds.  I will do that in a later
checkin.

Also, this change doesn't handle the case where the time offset has been
set. But this change doesn't make it any worse.  The problem with that one
is that the date stored in the database has already been modified with the
offset.  So now the database does not contain local date/time.  

To fix this, the date in the database will need to be extracted, the offset
change would be undone, then it would be converted to GMT.  This will not
work if the offset is ever changed after a post is created.


Modified: plog/branches/plog-1.0.2/class/locale/locale.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/locale/locale.class.php	2005-08-01 13:10:55 UTC (rev 2381)
+++ plog/branches/plog-1.0.2/class/locale/locale.class.php	2005-08-01 16:12:51 UTC (rev 2382)
@@ -421,9 +421,9 @@
          *
          * @return A string with the ordinal representation of the day.
 		 */
-		function getDayOrdinal( $t )
+		function getDateOrdinal( $date )
 		{
-			$dayOrdinal = $t->getDay();
+			$dayOrdinal = $date;
 			$last_digit = substr( $dayOrdinal, -1 );
 			if( $dayOrdinal < 10 )
 				$dayOrdinal = $last_digit;
@@ -437,12 +437,19 @@
 					$dayOrdinal .= "."; break;
 				case "en":
 				default:
-					$dayOrdinal = $this->_getOrdinal( $t->getDay()); break;
+					$dayOrdinal = $this->_getOrdinal( $date); break;
 			}
 			
 			return $dayOrdinal;
-		}		
+		}	
 
+		function getDayOrdinal( $t )
+		{
+			$dayOrdinal = $t->getDay();
+			return $this->getDateOrdinal( $dayOrdinal );
+		}	
+
+
         /**
 		 * Formats the date of a Timestamp object according to the given format:
 		 *
@@ -489,7 +496,7 @@
 				$format = $this->_dateFormat;
 
             // now we can continue normally
-            $values["%a"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3 )) : substr($weekday, 0, 2 );
+            $values["%a"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3 )) : substr($weekday, 0, 3 );
 			$values["%A"] = $weekday;
 			$values["%b"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($monthStr), 0, 3 )) : substr($monthStr, 0, 3);
 			$values["%B"] = $monthStr;
@@ -527,6 +534,110 @@
 			return $text;
 		}
 		
+        /**
+		 * Formats the date of a Timestamp object according to the given format:
+		 * This function assumes that the timestamp is local and it converts it
+		 * to GMT before formatting.
+		 *
+         * (compatible with PHP):<ul>
+		 * <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>%%	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>
+         * </ul>
+		 */
+        function formatDateGMT( $timeStamp, $format = null )
+        {
+            // load the file if it hadn't been loaded yet       
+            if( !is_array($this->_messages))
+                $this->_loadLocaleFile();       
+        
+            // Convert this timestamp to on that is in GMT
+            $strTimeStamp = $timeStamp->getTimestamp();
+            // Now have a local time stamp 
+            // Is this step really necessary, since we previously had a time stamp
+            $time = mktime(
+                substr($strTimeStamp,8,2),
+                substr($strTimeStamp,10,2),
+                substr($strTimeStamp,12,2),
+                substr($strTimeStamp,4,2),
+                substr($strTimeStamp,6,2),
+                substr($strTimeStamp,0,4)
+            );
+
+            // This does not take into account the time offset that the user
+            // specified, since we are converting the time to GMT.  Since the
+            // offset is just used to handle time zone differences, it is not 
+            // necessary, as the time GMT is still the same.
+            
+            // timestamp only returns the values in english, so we should translate
+            // them before using
+            $monthId = gmdate( "n", $time );
+            $monthStr   = $this->_messages["months"][$monthId-1];
+            //print("monthstr: $monthStr");
+            // and the same for the weekdays
+            $weekdayId = gmdate( "w", $time );
+            $weekday = $this->_messages["days"][$weekdayId];
+            
+            // if the user did not specify a format, let's use the default one
+            if( $format == null )
+                $format = $this->_dateFormat;
+
+            // now we can continue normally
+            $values["%a"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($weekday), 0, 3 )) : substr($weekday, 0, 3 );
+            $values["%A"] = $weekday;
+            $values["%b"] = function_exists('html_entity_decode') ? htmlentities(substr(html_entity_decode($monthStr), 0, 3 )) : substr($monthStr, 0, 3);
+            $values["%B"] = $monthStr;
+            $values["%d"] = gmdate( "d", $time );
+            $values["%e"] = intval(gmdate( "d", $time ));
+            $values["%j"] = gmdate( "j", $time );
+            $values["%H"] = gmdate( "H", $time );
+            $values["%I"] = gmdate( "g", $time );
+            $values["%p"] = gmdate( "a", $time );
+            $values["%P"] = gmdate( "A", $time );
+            $values["%M"] = gmdate( "i", $time );
+            $values["%m"] = gmdate( "m", $time );
+            $values["%S"] = gmdate( "s", $time );
+            $values["%y"] = gmdate( "y", $time );
+            $values["%Y"] = gmdate( "Y", $time );
+            $values["%%"] = "%";
+            $values["%T"] = $this->getDateOrdinal( gmdate( "d", $time ) )." ".$this->tr("of")." ".$monthStr;
+            $values["%D"] = $this->getDateOrdinal( gmdate( "d", $time )  );
+            /* Start Hack By FiFtHeLeMeNt For Persian Language */
+            list( $jyear, $jmonth, $jday ) = JalaliCalendar::gregorian_to_jalali(gmdate( "Y", $time ), gmdate( "m", $time ), gmdate( "d", $time ));
+            $values["%q"] = JalaliCalendar::Convertnumber2farsi($jyear);
+            $values["%w"]= JalaliCalendar::Convertnumber2farsi($jmonth);
+            $values["%o"] = JalaliCalendar::Convertnumber2farsi($jday);
+            $values["%R"] = JalaliCalendar::monthname($jmonth);
+            $values["%T"] = JalaliCalendar::Convertnumber2farsi(gmdate( "H", $time ));
+            $values["%U"] = JalaliCalendar::Convertnumber2farsi(gmdate( "i", $time ));
+            /* End Hack By FiFtHeLeMeNt For Persian Language */     
+
+            $text = $format;
+            foreach( array_keys($values) as $key ) {
+                if( ereg($key, $text) )
+                    $text = str_replace( $key, $values[$key], $text );
+            }
+
+            return $text;
+        }
+		
 		/**
 		 * merges two locales
 		 */

Modified: plog/branches/plog-1.0.2/templates/rss/rss20.template
===================================================================
--- plog/branches/plog-1.0.2/templates/rss/rss20.template	2005-08-01 13:10:55 UTC (rev 2381)
+++ plog/branches/plog-1.0.2/templates/rss/rss20.template	2005-08-01 16:12:51 UTC (rev 2382)
@@ -9,7 +9,7 @@
   <title>{$blog->getBlog()|escape}</title>
   <link>{$url->blogLink()}</link>
   <description>{$blog->getAbout()|escape}</description>
-  <pubDate>{$locale->formatDate($now, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+  <pubDate>{$locale->formatDateGMT($now, "%a, %d %b %Y %H:%M:%S GMT")}</pubDate>
   <generator>http://www.plogworld.net</generator>
   {foreach from=$posts item=post}
   <item>
@@ -26,7 +26,7 @@
     <category>{$category->getName()|escape}</category>
    {/foreach}
    {assign var="postDate" value=$post->getDateObject()}
-   <pubDate>{$locale->formatDate($postDate, "%a, %d %b %Y %H:%M:%S")}</pubDate>
+   <pubDate>{$locale->formatDateGMT($postDate, "%a, %d %b %Y %H:%M:%S GMT")}</pubDate>
    <source url="{$url->rssLink("rss20")}">{$blog->getBlog()|escape}</source>
    {foreach from=$post->getArticleResources() item=resource}
     {** please uncomment the line below if you'd like to server everything but images, instead of




More information about the pLog-svn mailing list