Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Time Question

by grashoper (Monk)
on Jan 15, 2009 at 02:26 UTC ( [id://736440]=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I have a requirement to switch logo's depending on the time of day and the sitecode being used, so that if during business hours a chat is offered if after a phone number is displayed. Initially I thought I could do this with an
<xsl:if> statement but its not working at all like I expected nothing +is being displayed regardless of results of the new if test.
so I thought how about making a modified transform hardcoding my other logo (graphic 2 whatever) and then calling that based on time..not elegant but needs to get done real quick for the client so I was wondering how the heck do I check the time? this is probably simple but I can't figure how to determine what time it is other than looking at my watch like an idiot. I know my xp will probably all vanish and I will be banished to negativeland.

Replies are listed 'Best First'.
Re: Time Question
by kyle (Abbot) on Jan 15, 2009 at 02:47 UTC
Re: Time Question
by ww (Archbishop) on Jan 15, 2009 at 03:21 UTC

    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.

Re: Time Question
by eighty-one (Curate) on Jan 15, 2009 at 03:12 UTC
Re: Time Question
by dHarry (Abbot) on Jan 15, 2009 at 11:02 UTC

    You give about zero details and it seems completely unrelated to Perl. If you use (E)XSLT and you want the date/time you could consider the

    date:date-time()

    function. Though it depends on your XSLT processor implementation/version if this function is actually implemented. See for example EXSLT for an XML-ish solution to your problem.

    HTP
    dHarry

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://736440]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found