Date-Components

 view release on metacpan or  search on metacpan

lib/Date/Components.pm  view on Meta::CPAN

# This allows declaration use Date::Components ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = (
                    'all' => [ @EXPORT_OK, @EXPORT ],
                   );

use version; our $VERSION = qv('0.2.1');


# According to the Royal Greenwich Observatory, the calendar year is 365 days
# long, unless the year is exactly divisible by four, then an extra day is
# added to February so the year is 366 days long. If the year is the last year
# of a century, e.g., 2000, 2100, 2200, 2300, 2400, then it is only a leap
# year if it is exactly divisible by 400. So, 2100 won't be a leap year but
# 2000 is. The next century year, exactly divisible by 400, won't occur until
# 2400--400 years away.




lib/Date/Components.pm  view on Meta::CPAN

###############################################################################
# Usage      : date_offset_in_weekdays( SCALAR, SCALAR )
# Purpose    : find a WEEKDAY date in the future or past offset by the number of weekdays from the given starting WEEKDAY date
# Returns    : - date of the WEEKDAY day offset from the given WEEKDAY date if successful
# Parameters : (
#            :   WEEKDAY date in any format,
#            :   number of weekdays offset, positive is future date, negative is past date, zero is current date (no offset)
#            : )
# Throws     : Throws exception for any invalid input INCLUDING weekend dates
# Comments   : This effectively functions as if ALL weekend dates were removed
#            : from the calendar.  This function accepts ONLY weekday dates and
#            : outputs ONLY weekday dates
# See Also   : N/A
###############################################################################
sub date_offset_in_weekdays
   {
   my (
       $date_in_05,
       $date_delta_01
      )
       = @_;

lib/Date/Components.pm  view on Meta::CPAN

Subroutines providing operations specific to the standard 400 year cycle are
included also.

The module is not object oriented.  Rather, it supplies a variety of
useful functions to analyze, process and format complete dates and the four
date components of I<month>, I<day-of-month>, I<year> and I<day-of-week>.
B<ALL> representations of time and related parameters are ignored, including
hours, minutes, seconds, time zones, daylight savings time, etc.

Leap year standard is used.  According to the Royal Greenwich Observatory, the
calendar year is 365 days long, unless the year is exactly divisible by four,
then an extra day is added to February so the year is 366 days long. If the
year is the last year of a century, e.g., 2000, 2100, 2200, 2300, 2400, then it
is only a leap year if it is exactly divisible by 400. So, 2100 won't be a leap
year but 2000 is. The next century year, exactly divisible by 400, won't occur
until 2400--400 years away.

Subroutines C<is_valid_date>, C<format_date> and C<get_numeric_day_of_week>
are overloaded to accept either a list of date components or a single SCALAR
date string to enable more flexible usage.

lib/Date/Components.pm  view on Meta::CPAN

 - Weekday date string in any format
 - Integer number of weekdays, positive or negative

=item Throws:

 Throws exception for any invalid input INCLUDING weekend dates

=item Comments:

 This effectively functions as if ALL weekend dates were removed
 from the calendar.  This function accepts ONLY weekday dates and
 outputs ONLY weekday dates

=item Examples:

 date_offset_in_weekdays('Mon Jul 11 08:50:51 1977', -7);  # Returns '06/30/1977'
 date_offset_in_weekdays('Tue Jul 12 08:50:51 1977', -3);  # Returns '07/07/1977'
 date_offset_in_weekdays('Wed Jul 13 08:50:51 1977',  0);  # Returns '07/13/1977'
 date_offset_in_weekdays('Thu Jul 14 08:50:51 1977',  3);  # Returns '07/19/1977'
 date_offset_in_weekdays('Fri Jul 15 08:50:51 1977',  7);  # Returns '07/26/1977'

t/get_number_of_day_within_400yr_cycle.t  view on Meta::CPAN

eval {get_number_of_day_within_400yr_cycle('February', [],1888)};
ok(($@),      'Hash references are NOT allowed');

eval {get_number_of_day_within_400yr_cycle('Nov', '',1587)};
ok(($@),      'NULL value for day of month is NOT allowed.');





is(get_number_of_day_within_400yr_cycle(2,1,2000),                                         32,   'date  2, 1,2000  is day number                                    32 within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(2,1,2001),                                        398,   'date  2, 1,2001  is day number                                   398 within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(12,31,1999),          ((300 * 365) + (100 * 366) - 3),   'date 12,31,1999  is day number       ((300 * 365) + (100 * 366) - 3) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(12,31,199),           ((150 * 365) +  (50 * 366) - 1),   'date 12,31, 199  is day number       ((150 * 365) +  (50 * 366) - 1) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(12,31,-201),          ((150 * 365) +  (50 * 366) - 1),   'date 12,31,-201  is day number       ((150 * 365) +  (50 * 366) - 1) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(12,31,-1),            ((300 * 365) + (100 * 366) - 3),   'date 12,31,  -1  is day number       ((300 * 365) + (100 * 366) - 3) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(1,1,0),                                           (1),   'date  1, 1,   0  is day number                                   (1) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(12,30,-201),      ((150 * 365) +  (50 * 366) - 1 - 1),   'date 12,30,-201  is day number   ((150 * 365) +  (50 * 366) - 1 - 1) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle(11,25,-201),     ((150 * 365) +  (50 * 366) - 1 - 36),   'date 11,25,-201  is day number  ((150 * 365) +  (50 * 366) - 1 - 36) within the 400 year calendar cycle');
is(get_number_of_day_within_400yr_cycle('Feb',1,1999),  ((300 * 365) + (100 * 366) - 3 - 333),   'date Feb,1,1999  is day number ((300 * 365) + (100 * 366) - 3 - 333) within the 400 year calendar cycle');



( run in 0.411 second using v1.01-cache-2.11-cpan-c333fce770f )