Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Date Calculation

by davorg (Chancellor)
on Jan 30, 2007 at 14:40 UTC ( [id://597375]=note: print w/replies, xml ) Need Help??


in reply to Date Calculation

How do you define a business day? Is it weekdays? Or do you need to take into account public holidays and things like that?

Here's a naive approach that just leaves you needing to define an is_business_day() subroutine which takes a time (as an epoch seconds value) as an argument.

my $today = time; my $days_added; while (1) { $time += 24 * 60 * 60; # add a day $days_added++ if is_business_day($time); last if $days_added == 10; } print scalar localtime $time;

Update: As ikegami correctly points out below, there's a potential bug in this program if it's run across days that don't contain 24 hours (i.e. when switching to or from daylight saving time). The fix is to normalise the time to noon (assuming that timezone changes always occur overnight). This change is left as an exercise for the reader.

Replies are listed 'Best First'.
Re^2: Date Calculation
by ikegami (Patriarch) on Jan 30, 2007 at 15:31 UTC
    Not all days have 24 hours.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found