changeset 84:c7f71166bc90

Simplified the handling of dates & times a little via Date::Format.
author Steve Kemp <steve@steve.org.uk>
date Tue, 11 Dec 2007 23:07:00 +0000
parents 2b56674bde84
children f3b73f970dd2
files bin/chronicle
diffstat 1 files changed, 35 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/bin/chronicle	Tue Dec 11 17:53:36 2007 +0000
+++ b/bin/chronicle	Tue Dec 11 23:07:00 2007 +0000
@@ -806,9 +806,9 @@
         }
         $year = $1;
 
-        push( @$months, { month => $2,
-                month_name => $names[$2-1],
-                count => $entry_dates{$date} } );
+        push( @$months, { month      => $2,
+                          month_name => $names[$2-1],
+                          count      => $entry_dates{$date} } );
 
     }
 
@@ -1421,49 +1421,44 @@
     #
     if ( ! defined($date) ||( !length( $date ) ) )
     {
-        my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
-        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-          localtime(time);
-
-        $year += 1900;
-
-        $date = "$mday $abbr[$mon] $year";
+        my @lt = localtime(time);
+        $date = strftime( "%d %B %Y", @lt);
     }
 
     #
-    #  Make an entry date for the XML feed
+    #  Make an entry date for the XML feed, if we have a date.
     #
-    if ( $date )
+    my $time = str2time($date);
+    if ( $time )
     {
-        my $time = str2time($date);
-        if ( $time )
-        {
-            #
-            #  Get the details of the file.
-            #
-            my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
-                $atime,$mtime,$ctime,$blksize,$blocks)
-              = stat($filename);
-
-            #
-            #  Get the modification hours.
-            #
-            my ($sec,$min,$hour) = localtime( $mtime );
-
-            #
-            #  Pad
-            #
-            $sec  = "0$sec" if ( length( $sec ) < 2 );
-            $min  = "0$min" if ( length( $min ) < 2 );
-            $hour = "0$hour" if ( length( $hour ) < 2 );
-            
-
-            #
-            $entry{'pubdate'} = time2str("%a, %e %b %Y $hour:$min:$sec GMT", $time );
-            $entry{'pubdate'} =~ s/  / /g;
-        }
+        #
+        #  Get the details of the file.
+        #
+        my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+            $atime,$mtime,$ctime,$blksize,$blocks)
+          = stat($filename);
+
+        #
+        #  Get the modification hours.
+        #
+        my ($sec,$min,$hour) = localtime( $mtime );
+
+        #
+        #  Pad to two digits for each of the hours, minutes, and seconds.
+        #
+        my $hms = sprintf("%02d:%02d:%02d", $hour, $min, $sec );
+
+        #
+        #  Store the published date & time away.  Collapsing multiple
+        # spaces
+        #
+        $entry{'pubdate'} = time2str("%a, %e %b %Y $hms GMT", $time );
+        $entry{'pubdate'} =~ s/  +/ /g;
     }
-
+    else
+    {
+        print "Failed to parse date: '$date' to generate pubDate of entry.\n";
+    }
 
     #
     #  Store the entry.