# lib-rf-date.pl # by Gav Ford # revford@blueyonder.co.uk # http://revford.pwp.blueyonder.co.uk # 2008-03-28, updated 2008-09-26 # a collection of date related subroutines # There are two date formats supported here, they are: # ISO 8601 - used for HTML - 2008-09-26T13:29:04Z # - 2008-09-26 # RFC-822 - used for RSS - Mon, 06 Oct 2008 13:29:04 GMT %months = (Jan => '01', Feb => '02', Mar => '03', Apr => '04', May => '05', Jun => '06', Jul => '07', Aug => '08', Sep => '09', Oct => '10', Nov => '11', Dec => '12'); sub builddate {return(' ')} sub datestamp {return('
' . rssdate() . '
')} sub cleandate # ISO 8601 standard format { $daysago = $_[0]; $longdate = gmtime(time() - ( 24 * 60 * 60 * $daysago)); # remove 24 hours, 60 mins, 60 sec * $daysago $longdate =~ s/\ \ /\ /; ($day, $month, $mday, $fullTime, $year) = split(/ /, $longdate); $mday = sprintf "%02d", "$mday"; $monthnumber = $months{$month}; return ("$year-$monthnumber-$mday"); } sub cleandatelong # ISO 8601 standard format { $daysago = $_[0]; $longdate = gmtime(time() - ( 24 * 60 * 60 * $daysago)); # remove 24 hours, 60 mins, 60 sec * $daysago $longdate =~ s/\ \ /\ /; ($day, $month, $mday, $fullTime, $year) = split(/ /, $longdate); $mday = sprintf "%02d", "$mday"; $monthnumber = $months{$month}; return ($year . '-' . $monthnumber . '-' . $mday . 'T' . $fullTime . 'Z'); } sub rssdate # RFC-822 standard format, GMT { $daysago = $_[0]; $longdate = gmtime(time() - ( 24 * 60 * 60 * $daysago)); $longdate =~ s/\ \ /\ /; ($day, $month, $mday, $fullTime, $year) = split(/ /, $longdate); $mday = sprintf "%02d", "$mday"; return ("$day, $mday $month $year $fullTime GMT"); } sub fulldate # RFC-822 standard format, localtime { $daysago = $_[0]; $longgmtdate = gmtime(time() - ( 24 * 60 * 60 * $daysago)); $longgmtdate =~ s/\ \ /\ /; ($null, $null, $null, $fullTimeGMT) = split(/ /, $longgmtdate); $longdate = localtime(time() - ( 24 * 60 * 60 * $daysago)); $longdate =~ s/\ \ /\ /; ($day, $month, $mday, $fullTime, $year) = split(/ /, $longdate); if ($fullTime eq $fullTimeGMT) {$timezone = "GMT"} # Options for either the BST code or the difference from GMT, +0100 #else {$timezone = "BST"} else {$timezone = "+0100"} $mday = sprintf "%02d", "$mday"; return ("$day, $mday $month $year $fullTime $timezone"); } sub moddate # turn an RSS date into a moddate, for sorting the posts list { my $thisdate = $_[0]; $thisdate =~ s/\ \ /\ /; ($day, $mday, $month, $year, $fullTime) = split(/ /, $thisdate); $fullTime =~ s/://g; return ("$year$months{$month}$mday$fullTime"); } 1;