Date::Simple - 簡単な日付オブジェクト
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])
このモジュールは、簡単な日付オブジェクトを作ります。 Unixの時間の範囲の日付しか扱いません。 このモジュールは、不当な日付のオブジェクトを作ることを許しません。 不当な日付で作ろうとすると、undefを返します。
my $date = Date::Simple->new('1972-01-17');
my $otherdate = Date::Simple->new(2000, 12, 25);
渡された値が妥当な日付を指定していたら、newメソッドは、日付オブジェクトを返します。
渡された値が不正であれば、メソッドは、undefを返します。
my $tomorrow = $today->next;
明日に相当するオブジェクトを返します。
my $yesterday = $today->prev;
昨日に相当するオブジェクトを返します。
my $year = $date->year;
日付オブジェクトが持っている日付の年を返します。
my $month = $date->month;
日付オブジェクトが持っている日付の月を返します。
my $day = $date->day;
日付オブジェクトが持っている日付の日を返します。
これらの関数は同等です。日付を表す文字列を、指定されたフォーマットで返します。 パラメータを渡さなければ、ISO8601フォーマットが返ります。
my $change_date = $date->format("%d %b %y");
my $iso_date1 = $date->format("%Y-%m-%d");
my $iso_date2 = $date->format;
フォーマットのパラメータは、srrftime(3)に渡すものと、似ています。 これは私たちが日付をフォーマットするためにそれを実際にstrftimeに渡すからです。
Date:Simpleインスタンスと一緒に、いくつかの演算子を使うことが出来ます。
(原文まま)
Marty Pauley <marty@kasei.com>
(原文まま)
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.