Marty Pauley > Date-Simple-1.03 > Date::Simple

Download:
Date-Simple-1.03.tar.gz

Dependencies

Annotate this POD

Related Modules

Date::Calc
Date::Manip
Class::DBI
Time::Local
Data::Dumper
Text::CSV
Class::Date
Scalar::Util
Text::Table
List::Util
more...
By perlmonks.org

CPAN RT

New  10
Open  2
View Bugs
Report a bug
Module Version: 1.03   Source  

NAME ^

Date::Simple - a simple date object

SYNOPSIS ^

    my $date  = Date::Simple->new('1972-01-17');
    my $year  = $date->year;
    my $month = $date->month;
    my $day   = $date->day;
    my $date2 = Date::Simple->new($year, $month, $day);

    my $today = Date::Simple->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";
    }

    # you can also do this:
    ($date cmp "2001-07-01")
    # and this
    ($date <=> [2001, 7, 1])

DESCRIPTION ^

This module may be used to create simple date objects. It only handles dates within the range of Unix time. It will only allow the creation of objects for valid dates. Attempting to create an invalid date will return undef.

CONSTRUCTOR ^

new

    my $date = Date::Simple->new('1972-01-17');
    my $otherdate = Date::Simple->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.

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 similar to one you would pass to strftime(3). This is because we actually do pass it to strftime to format the date.

OPERATORS ^

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

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;
     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.