Forum Moderators: coopster & phranque

Message Too Old, No Replies

Open/Closed sign - need to check the day to close at weekends

         

walker

11:28 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Hi

I am using the following code to display open/closed sign during office hours using the server time, I need to be able to say if its Saturday or Sunday display closed.

Any help would really be appreaciated

THE CODE:

#!/usr/bin/perl

use strict;
use FindBin qw($Bin);

# get current time
my($min,$hour,$day,$Week_Day,$mon) = (localtime)[1...5];
my $time = sprintf("%02d%02d", $hour, $min);
$mon++;

# get open/closed sign
my $sign_file;
if (900 <= $time && $time <= 1800) { $sign_file = "mast_opensign_open.gif"; }
else { $sign_file = "mast_opensign_closed.gif"; }

# set as closed for holidays
if ($mon == 12 && $day == 25) { $sign_file = "mast_opensign_closed.gif"; }
if ($mon == 12 && $day == 26) { $sign_file = "mast_opensign_closed.gif"; }
if ($mon == 1 && $day == 1) { $sign_file = "mast_opensign_closed.gif"; }

# load sign
my $data;
open(FILE,"<$Bin/$sign_file") ¦¦ die $!;
binmode(FILE);
read(FILE,$data, -s FILE);
close(FILE);

# output image
binmode(STDOUT);
print "Content-type: image/gif\n";
print "Cache-Control: no-cache\n";
print "Pragma: no-cache\n";
print "Expires: -1\n";
print "\n";
print $data;
exit;

Kind Regards

Walker

Rup

2:38 am on Mar 11, 2004 (gmt 0)

10+ Year Member



Haven't tested this, but something like below should work...

-----

my $weekday = (localtime)[6];

if ($weekday == 0) { $sign_file = "mast_opensign_closed.gif"; } ### Sunday

if ($weekday == 6) { $sign_file = "mast_opensign_closed.gif"; } ### Saturday

-----

Hope this helps.

walker

10:57 am on Mar 11, 2004 (gmt 0)

10+ Year Member



Thank you, Thank you, Thank you!

That works really well!

Kind Regards

Walker