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.
"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Date Calculation
by ikegami (Patriarch) on Jan 30, 2007 at 15:31 UTC |