[pod] [xml]

名前

Date::Simple - Date::Simple - 簡単な日付オブジェクト。

(訳註:Date::Simple 2.03は、次のDate::Simpleです。CPAN.pm で "install Date::Simple" でとれるのは、1.03です。)

概要

    use Date::Simple ('date', 'today');
    # Difference in days between two dates:
    $diff = date('2001-08-27') - date('1977-10-05');
    # Offset $n days from now:
    $date = today() + $n;
    print "$date\n";  # uses ISO 8601 format (YYYY-MM-DD)
    use Date::Simple ();
    my $date  = Date::Simple->new('1972-01-17');
    my $year  = $date->year;
    my $month = $date->month;
    my $day   = $date->day;
    use Date::Simple (':all');
    my $date2 = ymd($year, $month, $day);
    my $date3 = d8('19871218');
    my $today = today();
    my $tomorrow = $today + 1;
    if ($tomorrow->year != $today->year) {
        print "Today is New Year's Eve!\n";
    }
    if ($today > $tomorrow) {
        die "warp in space-time continuum";
    }
    print "Today is ";
    print(('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur')
          [$today->day_of_week]);
    print "day.\n";
    # you can also do this:
    ($date cmp "2001-07-01")
    # and this
    ($date <=> [2001, 7, 1])

説明

日付は、時間と時間帯なしでも、十分に複雑です。 このモジュールは、簡単な日付オブジェクトを作ります。次のものを取り扱います:

Date::Simpleは、時分秒、時間帯は取り扱いません

日付は、妥当な範囲の、年月日の数字によって、ユニークに特定されます。 このモジュールは、不当な日付のオブジェクトを作ることを許しません。 不当な日付で作ろうとすると、undefを返します。 月のナンバリングは、1月が1で始まります。Cや、Javaとは、違っています。 年は、4桁です。

9999年までのグレゴリオ日付が正確に取り扱われます。 ですが、現在の日付が要求された場合、Perlの組み込み関数のlocaltimeを当てにします。 プラットフォームの中には、localtimeは、 UNIX time_tの2038年1月の回り込みのように転覆する脆弱性があるかもしれません。

オーバーロードが使われているので、2つの日付を比較するか、引き算をするのに、 標準的な数値演算子、==のようなものを使うことが出来ます。 また、日付オブジェクトと数字の足し算は、別の日付ブジェクトになります。

Date::Simpleオブジェクトは、不変です。$date1$date2に割り当てた後、 $date1の変更は$date2にまったく影響を与えません。 このことは、たとえば、set_yearオペレーションのようなものがないと言うことを意味します。 $date++は、$dateに、新しいオブジェクトを割り当てます。

このモジュールは、さまざまなドキュメント化されていない関数を含んでいます。 それらは、全てのプラットフォームで利用可能でないし、将来のリリースで、変更するか、消えるかもしれません。 これらのいくつかを公にすべきと思うなら、作者に教えてください。

複数のコンストラクタ

いくつかの関数は、文字列か数字の表現をとり、対応する日付オブジェクトを返します。 もっとも一般的なのは、newです。newの引数リストは、空か (現在の日付を返します)、ISO 8601フォーマット(YYYY-MM-DD)の文字列か、 年月日の数字の配列または配列リファレンスか、日付オブジェクトです。

インスタンスメソッド

演算子

Date:Simpleインスタンスと一緒に、いくつかの演算子を使うことが出来ます。 式の片方が日付オブジェクトで、演算子が2つの日付オブジェクトを期待するなら、 もう片方がdate(ARG)として、解釈されます。 ですので、配列リファレンスかISO 8601の文字列ならば動くでしょう。

ユーティリティ

著者

(原文まま)

    Marty Pauley <marty@kasei.com>
    John Tobey <jtobey@john-edwin-tobey.org>

著作権

(原文まま)

      Copyright (C) 2001  Kasei
      Copyright (C) 2001 John Tobey.
      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.  You should have received a copy of the GNU General
         Public License along with this program; see the file COPYING.
         If not, write to the Free Software Foundation, Inc., 59
         Temple Place, Suite 330, Boston, MA 02111-1307 USA
      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.