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

pwestbro at devel.plogworld.net pwestbro at devel.plogworld.net
Fri Aug 19 07:20:21 GMT 2005


Author: pwestbro
Date: 2005-08-19 07:20:20 +0000 (Fri, 19 Aug 2005)
New Revision: 2415

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

Now the dates are output in local time of the poster, and not the server.
If the blog info is passed into formatDate, the timeoffset is used to
correct the time zone offset.  Printing the dates in local time zone, allow
additional information to be available, that is lost when converting to GMT.

There may still be a problem when dealing with the boundary with daylight
saving time.  If the current date has DST in effect, and the post date does
not, the time zone offset may be incorrect.  This could potentially be
solved by passing the date that is being parsed into the date("Z") call.
The documentation doesn't say what happens in this case.

Also, fixed a mistake in my last checkin.  There was a conditional that was
always true, so I just removed the conditional


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-18 21:12:48 UTC (rev 2414)
+++ plog/branches/plog-1.0.2/class/locale/locale.class.php	2005-08-19 07:20:20 UTC (rev 2415)
@@ -475,6 +475,7 @@
 		 * <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>
@@ -482,7 +483,7 @@
          * <li>%D	cardinal representation of the day</li>
          * </ul>
 		 */
-		function formatDate( $timeStamp, $format = null )
+		function formatDate( $timeStamp, $format = null, $blog = null )
 		{
 			// load the file if it hadn't been loaded yet		
 			if( !is_array($this->_messages))
@@ -496,6 +497,26 @@
             // and the same for the weekdays
             $weekdayId = $timeStamp->getWeekdayId();
             $weekday = $this->_messages["days"][$weekdayId];
+            
+            // Get the time zone offset for the server
+            $timeZoneSec = date("Z");
+            if ( $blog ) {
+                //
+                // The blog was specified.  Use it to get the time offset
+                //
+                $timeDiff = 0;
+                $blogSettings = $blog->getSettings();
+                $timeDiff = $blogSettings->getValue( 'time_offset' );
+                
+                // The following line relies on the fact that the result will
+                // be an int.
+                $timeZoneSec += ( $timeDiff * 3600 );
+            }
+            // Now convert the time zone seconds to hours and minutes
+            $timeZoneHours = intval( abs($timeZoneSec) / 3600 );
+            $timeZoneMins = intval(( abs($timeZoneSec) % 3600 ) / 60 );
+            $timeZoneDirection = ($timeZoneSec < 0 ) ? "-" : "+";
+            
 			
 			// if the user did not specify a format, let's use the default one
 			if( $format == null )
@@ -518,6 +539,7 @@
 			$values["%S"] = $timeStamp->getSeconds();
 			$values["%y"] = substr($timeStamp->getYear(), 2, 4 );
 			$values["%Y"] = $timeStamp->getYear();
+			$values["%O"] = sprintf( "%s%02d%02d", $timeZoneDirection, $timeZoneHours, $timeZoneMins );
 			$values["%%"] = "%";
             $values["%T"] = $this->getDayOrdinal( $timeStamp )." ".$this->tr("of")." ".$monthStr;
             $values["%D"] = $this->getDayOrdinal( $timeStamp );
@@ -561,6 +583,7 @@
 		 * <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 (Will always be +0000)</li>
 		 * <li>%%	the '%' character
          * </ul>
          * (these have been added by myself and are therefore incompatible with php)<ul>
@@ -579,11 +602,9 @@
                 // The blog was specified.  Use it to get the time offset
                 //
                 $timeDiff = 0;
-                if( $this->_blogInfo == null ) {
-                    $blogSettings = $blog->getSettings();
-                    $timeDiff = $blogSettings->getValue( 'time_offset' );
-                    $timeDiff *= -1;
-                }
+                $blogSettings = $blog->getSettings();
+                $timeDiff = $blogSettings->getValue( 'time_offset' );
+                $timeDiff *= -1;
                 
                 if( $timeDiff > 0 )
                     $timeStamp->addSeconds( $timeDiff * 3600 );
@@ -639,6 +660,7 @@
             $values["%S"] = gmdate( "s", $time );
             $values["%y"] = gmdate( "y", $time );
             $values["%Y"] = gmdate( "Y", $time );
+            $values["%O"] = "+0000";
             $values["%%"] = "%";
             $values["%T"] = $this->getDateOrdinal( gmdate( "d", $time ) )." ".$this->tr("of")." ".$monthStr;
             $values["%D"] = $this->getDateOrdinal( gmdate( "d", $time )  );

Modified: plog/branches/plog-1.0.2/templates/rss/atom.template
===================================================================
--- plog/branches/plog-1.0.2/templates/rss/atom.template	2005-08-18 21:12:48 UTC (rev 2414)
+++ plog/branches/plog-1.0.2/templates/rss/atom.template	2005-08-19 07:20:20 UTC (rev 2415)
@@ -3,7 +3,7 @@
 <title>{$blog->getBlog()|escape}</title> 
 <link rel="alternate" type="text/html" href="{$url->blogLink()}" /> 
 {assign var="newestDate" value=$posts[0]->getDateObject()} 
-<modified>{$locale->formatDateGMT($newestDate, "%Y-%m-%dT%H:%M:%S-00:00", $blog)}</modified> 
+<modified>{$locale->formatDate($newestDate, "%Y-%m-%dT%H:%M:%S%O", $blog)}</modified> 
 <tagline>{$blog->getAbout()|escape}</tagline> 
 <generator url="http://www.plogworld.net/" version="1.0.1">pLog</generator> 
 {assign var="blogOwner" value=$posts[0]->getUserInfo()} 
@@ -14,9 +14,9 @@
  <title>{$post->getTopic()|escape}</title> 
  <link rel="alternate" type="text/html" href="{$url->postPermalink($post)}" /> 
  {assign var="postDate" value=$post->getDateObject()} 
- <modified>{$locale->formatDateGMT($postDate, "%Y-%m-%dT%H:%M:%S-00:00", $blog)}</modified> 
- <issued>{$locale->formatDateGMT($postDate, "%Y-%m-%dT%H:%M:%S-00:00", $blog)}</issued> 
- <created>{$locale->formatDateGMT($postDate, "%Y-%m-%dT%H:%M:%S-00:00", $blog)}</created> 
+ <modified>{$locale->formatDate($postDate, "%Y-%m-%dT%H:%M:%S%O", $blog)}</modified> 
+ <issued>{$locale->formatDate($postDate, "%Y-%m-%dT%H:%M:%S%O", $blog)}</issued> 
+ <created>{$locale->formatDate($postDate, "%Y-%m-%dT%H:%M:%S%O", $blog)}</created> 
  <summary type="text/plain">{$post->getText()|strip_tags|truncate:200:" ..."|escape:"html"}</summary> 
  <author> 
  {assign var="postOwner" value=$post->getUserInfo()} 

Modified: plog/branches/plog-1.0.2/templates/rss/rss090.template
===================================================================
--- plog/branches/plog-1.0.2/templates/rss/rss090.template	2005-08-18 21:12:48 UTC (rev 2414)
+++ plog/branches/plog-1.0.2/templates/rss/rss090.template	2005-08-19 07:20:20 UTC (rev 2415)
@@ -16,7 +16,7 @@
    <description>{$post->getText()|escape}</description>
    <link>{$url->postPermalink($post)}</link>
    {assign var="postDate" value=$post->getDateObject()}
-   <pubDate>{$locale->formatDateGMT($postDate, "%a, %d %b %Y %H:%M:%S GMT", $blog)}</pubDate>   
+   <pubDate>{$locale->formatDate($postDate, "%a, %d %b %Y %H:%M:%S %O", $blog)}</pubDate>   
   </item>
   {/foreach}
 </rdf:RDF>

Modified: plog/branches/plog-1.0.2/templates/rss/rss20.template
===================================================================
--- plog/branches/plog-1.0.2/templates/rss/rss20.template	2005-08-18 21:12:48 UTC (rev 2414)
+++ plog/branches/plog-1.0.2/templates/rss/rss20.template	2005-08-19 07:20:20 UTC (rev 2415)
@@ -9,7 +9,7 @@
   <title>{$blog->getBlog()|escape}</title>
   <link>{$url->blogLink()}</link>
   <description>{$blog->getAbout()|escape}</description>
-  <pubDate>{$locale->formatDateGMT($now, "%a, %d %b %Y %H:%M:%S GMT")}</pubDate>
+  <pubDate>{$locale->formatDate($now, "%a, %d %b %Y %H:%M:%S %O")}</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->formatDateGMT($postDate, "%a, %d %b %Y %H:%M:%S GMT", $blog)}</pubDate>
+   <pubDate>{$locale->formatDate($postDate, "%a, %d %b %Y %H:%M:%S %O", $blog)}</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