GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Date::Range(3) User Contributed Perl Documentation Date::Range(3)

Date::Range - work with a range of dates

  use Date::Range;

  my $range = Date::Range->new($date1, $date2);

  my $earliest = $range->start;
  my $latest   = $range->end;
  my $days     = $range->length;

  if ($range->includes($date3)) { ... }
  if ($range->includes($range2)) { ... }

  if ($range->overlaps($range2)) {
    my $range3 = $range->overlap($range2);
  }

  foreach my $date ($range->dates) { ... }

Quite often, when dealing with dates, we don't just want to know information about one particular date, but about a range of dates. For example, we may wish to know whether a given date is in a particular range, or what the overlap is between one range and another. This module lets you ask such questions.

  my $range = Date::Range->new($date1, $date2);

A range object is instantiated with two dates, which do not need to be in chronological order (we'll sort all that out internally).

These dates must be instances of the correct object. See want_class() below.

The class of which we expect the date objects to be objects. By default this is Date::Simple, but this could be any other date class. See Time::Piece::Range for an example of a subclass that uses a different date class.

  my $earliest = $range->start;
  my $latest   = $range->end;
  my $days     = $range->length;

These methods allow you retrieve the start and end dates of the range, and the number of days in the range.

  if ($range1->equals($range2)) { }

This tells you if two ranges are the same - i.e. start and end at the same dates.

  if ($range->includes($date3)) { ... }
  if ($range->includes($range2)) { ... }

These methods tell you if a given range includes a given date, or a given range.

  if ($range->overlaps($range2)) {
    my $range3 = $range->overlap($range2);
  }

These methods let you know whether one range overlaps another or not, and access this overlap range.

        my $range3 = $range->gap($range2);

This returns a new range representing the gap between two other ranges.

        if ($range->abuts($range2)) { ... }

This tells you whether or not two ranges are contiguous - i.e. there is no gap between them, but they do not overlap.

  foreach my $date ($range->dates) { ... }

This returns a list of each date in the range as a Date::Simple object.

Tony Bowden, based heavily on Martin Fowler's "Analysis Patterns 2" discussion and code at http://www.martinfowler.com/ap2/range.html

Please direct all correspondence regarding this module to: bug-Date-Range@rt.cpan.org

  Copyright (C) 2001-2006 Tony Bowden.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License; either version
  2 of the License, or (at your option) any later version.

  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.
2011-11-15 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.