Others have provided alternatives to looking at your watch. The coding, if inelegant, is straightforward:
#!/usr/bin/perl -lw
use strict;
my $open = 0;
my $hour = 0;
my $x = localtime;
# $x was "Wed Jan 14 21:59:45 2009" as this was written
if ( $x=~ /(Mon|Tue|Wed|Thu|Fri)\s\w{3}\s\d{1,2}\s(\d\d):/ ) {
my $weekday = $1;
$hour = $2;
}
if ( (7 <= $hour) && ($hour < 17) ) {
my $open = 1;
print "Open is true"; # debug only
# print <img src = "open.gif" ...;
} else {
#print <img src = "closed.gif ...;
print "Live chat available 7am - 5pm (appropriate TZ)";
}
integrating with CGI is left as an exercise...
Afterthought: Of course (duh!) you'll also have to test for holidays which might be accomplished by testing (with another regex) localtime against a hash of holiday_name = holiday_date, updated each year.
Update: Fixed day names. |