NAME

App::Dochazka::REST::Holiday - non-database holiday and date routines

SYNOPSIS

use App::Dochazka::REST::Holiday qw( holidays_in_daterange );

my $holidays1 = holidays_in_daterange( 
    begin => '2001-01-02',
    end => '2001-12-24',
);
my $holidays2 = holidays_in_daterange( 
    begin => '2001-01-02',
    end => '2002-12-24',
);

*WARNING*: holidays_in_daterange() makes no attempt to validate the date range. It assumes this validation has already taken place, and that the dates are in YYYY-MM-DD format!

EXPORTS

FUNCTIONS

calculate_hours

Given a canonicalized tsrange, return the number of hours. For example, if the range is [ 2016-01-06 08:00, 2016-01-06 09:00 ), the return value will be 1. If the range is [ 2016-01-06 08:00, 2016-01-07 09:00 ), the return value will 25.

Returns 0 if there's a problem with the tsrange argument.

canon_date_diff

Compute difference (in days) between two canonical dates

canon_to_ymd

Takes canonical date YYYY-MM-DD and returns $y, $m, $d

holidays_in_daterange

Given a PARAMHASH containing two properties, begin and end, the values of which are canonicalized dates (possibly produced by the split_tsrange() function), determine the holidays that fall within this range. The function will always return a status object. Upon success, the payload will contain a hashref with the following structure:

{ '2015-01-01' => '', '2015-05-01' => '', }

The idea is that this hash can be used to quickly look up if a given date is a holiday.

is_weekend

Simple function that takes a canonicalized date string in the format YYYY-MM-DD and returns a true or false value indicating whether or not the date falls on a weekend.

get_tomorrow

Given a canonicalized date string in the format YYYY-MM-DD, return the next date (i.e. "tomorrow" from the perspective of the given date).

holidays_and_weekends

Given a date range (same as in holidays_in_daterange, above), return a reference to a hash of hashes that looks like this (for sample dates):

{
    '2015-01-01' => { holiday => 1 },
    '2015-01-02' => {},
    '2015-01-03' => { weekend => 1 },
    '2015-01-04' => { weekend => 1 },
    '2015-01-05' => {},
    '2015-01-06' => {},
}

Note that the range is always considered inclusive -- i.e. the bounding dates of the range will be included in the hash.

tsrange_to_dates_and_times

Takes a string that might be a canonicalized tsrange. Attempts to extract beginning and ending dates (YYYY-MM-DD) from it. If this succeeds, an OK status object is returned, the payload of which is a hash suitable for passing to holidays_and_weekends().

ymd_to_canon

Takes $y, $m, $d and returns canonical date YYYY-MM-DD