NAME

Date::ISO - an ISO 8601 date object

SYNOPSIS

my $date  = Date::ISO->new($year, $month, $date) or die "Invalid date $!";
my $year  = $date->year;
my $month = $date->month;
my $day   = $date->day;

my $today = Date::ISO->new;
my $tomorrow = $today + 1;
print "Tomorrow's date (in ISO 8601 format) is $tomorrow.\n";
if ($tomorrow->year != $today->year) {
    print "Today is New Year's Eve!\n";
}

if ($today > $tomorrow) {
    die "warp in space-time continuum";
}

if (Date::ISO::leap_year(2000)) {
    print "366 days in 2000\n";
}

DESCRIPTION

This module may be used to create ISO 8601 date objects. It only deals with dates within the Unix epoch. It will only allow the creation of objects for valid dates. Attempting to create an invalid date will return undef.

This class is not part of the ISO 8601 standard :-)

FACTORY METHODS

new($year, $month, $day)

my $date = Date::ISO->new('1972-01-17');
my $otherdate = Date::ISO->new(2000, 12, 25);

The new method will return a date object if the values passed in specify a valid date. If an invalid date is passed, the method returns undef.

FUNCTIONS

leap_year

my $days_in_year_n = 365 + Date::ISO::leap_year($n);

Returns 1 when passed an integer value which refers to a leap year, 0 otherwise. You can use this as a boolean, or just add it to 365.

days_in_month

my $n = Date::ISO::days_in_month($year, $month);

Returns the number of days in the specified month.

INSTANCE METHODS

next

my $tomorrow = $today->next;

Returns an object representing tomorrow.

prev

my $yesterday = $today->prev;

Returns an object representing yesterday.

year

my $year  = $date->year;

Return the year of the date held in this date object

month

my $month = $date->month;

Return the month of the date held in this date object

day

my $day   = $date->day;

Return the day of the date held in this date object

format

Returns a string representing the date, in the format specified. If you don't pass a parameter, an ISO 8601 formatted date is returned.

my $change_date = $date->format("%d %b %y");
my $iso_date1 = $date->format("%Y-%m-%d");
my $iso_date2 = $date->format;

The formatting parameter is uncannily similar to one you would pass to strftime(3). This is probably because we actually do pass it to strftime to format the date.

OPERATORS

Some operators can be used with Date::ISO instances:

  • You can increment or decrement a date by a number of days using the += and -= operators

  • You can construct new dates offset by a number of days using the + and - operators.

  • You can subtract two dates ($d1 - $d2) to find the number of days between them.

  • You can compare two dates using the arithmetic comparison operators.

  • You can interpolate a date instance directly into a string, in the format specified by ISO 8601 (eg: 2000-01-17).

AUTHOR

Marty Pauley <marty@kasei.com>

COPYRIGHT

Copyright (C) 2001 Kasei

This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. b) the Perl Artistic License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.