Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

So I ended up using Date::Manip since we wanted to easily correct for holidays, weekends, etc.

use strict; use Date::Manip; &Date_Init("PersonalCNF=holidays.cnf","TZ=PST8PDT"); my $now = &ParseDate("now"); my $date = &ParseDate($ARGV[0]); $date = &Date_NextWorkDay(&ParseDate($date),0) unless $ARGV[1]; # Anything past the first argument acts as an "override" print &UnixDate($date,"Sleeping until %T on %F.\n"); my $delta = &DateCalc($now,$date); my $secs = &Delta_Format($delta,0,"%sh"); if ($secs < 0) { print "Hey, that's in the past--you can't fool me!\n" +; exit; } print "(that's $secs seconds...)\n"; sleep $secs;

So now one can feed it nearly any date/time format with the following caveats: Days of the week are considered to be days of the *current* week, so you should always use "next <day of week>". Also, it will automagically skip holidays/weekends unless you specify something (anything) as other arguments (i.e., scalar @ARGV > 1).

The reference to holidays.cnf is a customized Date::Manip configuration file with our business holidays in it.

As a little test matrix, I ran the following (with the actual sleeping part commented out, naturally):

C:\sleep>for /F "tokens=*" %x in (testmatrix.txt) do sleepuntil %x

C:\sleep>sleepuntil "8:00 next monday"
Sleeping until 08:00:00 on Monday, October  9, 2000.
(that's 228992 seconds...)

C:\sleep>sleepuntil "14:36:24 tomorrow"
Sleeping until 14:36:24 on Monday, October  9, 2000.
(that's 252775 seconds...)

C:\sleep>sleepuntil "tomorrow" really
Sleeping until 16:23:29 on Saturday, October  7, 2000.
(that's 86400 seconds...)

C:\sleep>sleepuntil "4th thursday in november"
Sleeping until 00:00:00 on Monday, November 27, 2000.
(that's 4433790 seconds...)

C:\sleep>sleepuntil "4th thursday in november" even if it's Thanksgiving
Sleeping until 00:00:00 on Thursday, November 23, 2000.
(that's 4088190 seconds...)

C:\sleep>sleepuntil "yesterday"
Sleeping until 16:23:31 on Thursday, October  5, 2000.
Hey, that's in the past--you can't fool me!

C:\sleep>sleepuntil "2pm Dec 1, 2006"
Sleeping until 14:00:00 on Friday, December  1, 2006.
(that's 194132189 seconds...)

...and as you can see, it works beautimously. :-)


In reply to RE: How long 'tween now and then? (Solved!) by myocom
in thread How long 'tween now and then? by myocom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (16)
    As of 2014-07-25 18:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (174 votes), past polls