#!/usr/bin/perl use strict; use warnings; use Time::Local qw( timelocal_nocheck ); my @events = ( # It's good to remove or comment out past events in order to use less CPU. # Some local conventions: # Start time is sometimes a guess. # 2006 [ 'Ad-Astra', timelocal_nocheck(0, 0, 18, 25, 5-1, 2006) ], [ 'Anime North', timelocal_nocheck(0, 0, 18, 25, 5-1, 2006) ], [ 'Toronto Trek', timelocal_nocheck(0, 0, 18, 7, 7-1, 2006) ], [ 'Northern Anime Festival', timelocal_nocheck(0, 0, 9, 22, 7-1, 2006) ], [ 'Hobbystar\'s FanExpo', timelocal_nocheck(0, 0, 16, 1, 9-1, 2006) ], # 2007 [ 'Anime North', timelocal_nocheck(0, 0, 18, 24, 5-1, 2007) ], #[ 'Toronto Trek', timelocal_nocheck(0, 0, ?, ?, ?-1, 2007) ], #[ 'Northern Anime Festival', timelocal_nocheck(0, 0, ?, ?, ?-1, 2007) ], #[ 'Hobbystar\'s FanExpo', timelocal_nocheck(0, 0, ?, ?, ?-1, 2007) ], ); my $now = time; my @now = localtime($now); sub format_time_left { my ($date) = @_; use integer; my $diff = $date - $now; my $days = $diff / (24*60*60); my $hours = $diff % (24*60*60) / ( 60*60); my $mins = $diff % ( 60*60) / ( 60); my $secs = $diff % ( 60); my $found = 0; my $rv = ""; if ($days > 0) { $rv .= "$days day"; $rv .= "s" if $days != 1; $found = 1; } if ($found || $hours > 0) { $rv .= ", " if $found; $rv .= "$hours hour"; $rv .= "s" if $hours != 1; $found = 1; } if ($found || $mins > 0) { $rv .= ", " if $found; $rv .= "$mins minute"; $rv .= "s" if $mins != 1; $found = 1; } $rv .= " and " if $found; $rv .= "$secs second"; $rv .= "s" if $secs != 1; return $rv; } sub format_time_left_announcements { my ($event_name, $date) = @_; my $formatted_time_left = format_time_left($date); return qq{
$event_name is in $formatted_time_left.
\n}; } sub time_left_announcements { my @target = @now; $target[4] += 2; # Announce events 2 months in advance. my $target = timelocal_nocheck(@target); foreach my $event (@events) { if ($event->[1] > $now && $event->[1] <= $target) { print(format_time_left_announcements(@$event)); } } } # Print HTTP headers here if called via CGI. print(qq{
\n}); time_left_announcements(); print(qq{
\n});