Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How long 'tween now and then?

by Fastolfe (Vicar)
on Sep 14, 2000 at 20:56 UTC ( #32509=note: print w/ replies, xml ) Need Help??


in reply to How long 'tween now and then?

I agree with the other posters about using something already built into Windows, but Date::Manip also lets you do this fairly nicely:

use Date::Manip; my $now = time(); my $next = &UnixDate(&ParseDate("8am"), "%s"); $next += 24 * 60 * 60 if $next < $now; sleep($next - $now);
ParseDate() parses the "8am", and UnixDate() with the "%s" format gives us the number we want. We jump ahead 24 hours if the time parsed is before the current time. A more correct way to do this would be to re-do the ParseDate with "tomorrow at 8am" instead of "8am", since DST could muck this up. I can't find a way to tell ParseDate to use the next future occurrence of "8am" instead of assuming "today at 8am" without messing up the pre-8am case.

ParseDate is also somewhat slow.


Comment on Re: How long 'tween now and then?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://32509]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-09-23 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls