Debian Codegraph @

README

raw
1 NAME
2 Date::Range - work with a range of dates
3
4 SYNOPSIS
5 use Date::Range;
6
7 my $range = Date::Range->new($date1, $date2);
8
9 my $earliest = $range->start;
10 my $latest = $range->end;
11 my $days = $range->length;
12
13 if ($range->includes($date3)) { ... }
14 if ($range->includes($range2)) { ... }
15
16 if ($range->overlaps($range2)) {
17 my $range3 = $range->overlap($range2);
18 }
19
20 foreach my $date ($range->dates) { ... }
21
22 DESCRIPTION
23 Quite often, when dealing with dates, we don't just want to know
24 information about one particular date, but about a range of dates. For
25 example, we may wish to know whether a given date is in a particular
26 range, or what the overlap is between one range and another. This module
27 lets you ask such questions.
28
29 METHODS
30 new()
31 my $range = Date::Range->new($date1, $date2);
32
33 A range object is instantiated with two dates, which do not need to be
34 in chronological order (we'll sort all that out internally).
35
36 These dates must be instances of the correct object. See want_class()
37 below.
38
39 want_class
40 The class of which we expect the date objects to be objects. By default
41 this is Date::Simple, but this could be any other date class. See
42 Time::Piece::Range for an example of a subclass that uses a different
43 date class.
44
45 start / end / length
46 my $earliest = $range->start;
47 my $latest = $range->end;
48 my $days = $range->length;
49
50 These methods allow you retrieve the start and end dates of the range,
51 and the number of days in the range.
52
53 equals
54 if ($range1->equals($range2)) { }
55
56 This tells you if two ranges are the same - i.e. start and end at the
57 same dates.
58
59 includes
60 if ($range->includes($date3)) { ... }
61 if ($range->includes($range2)) { ... }
62
63 These methods tell you if a given range includes a given date, or a
64 given range.
65
66 overlaps / overlap
67 if ($range->overlaps($range2)) {
68 my $range3 = $range->overlap($range2);
69 }
70
71 These methods let you know whether one range overlaps another or not,
72 and access this overlap range.
73
74 gap
75 my $range3 = $range->gap($range2);
76
77 This returns a new range representing the gap between two other ranges.
78
79 abuts
80 if ($range->abuts($range2)) { ... }
81
82 This tells you whether or not two ranges are contiguous - i.e. there is
83 no gap between them, but they do not overlap.
84
85 dates
86 foreach my $date ($range->dates) { ... }
87
88 This returns a list of each date in the range as a Date::Simple object.
89
90 AUTHOR
91 Tony Bowden, based heavily on Martin Fowler's "Analysis Patterns 2"
92 discussion and code at http://www.martinfowler.com/ap2/range.html
93
94 BUGS and QUERIES
95 Please direct all correspondence regarding this module to:
96 [email protected]
97
98 COPYRIGHT AND LICENSE
99 Copyright (C) 2001-2006 Tony Bowden.
100
101 This program is free software; you can redistribute it and/or modify
102 it under the terms of the GNU General Public License; either version
103 2 of the License, or (at your option) any later version.
104
105 This program is distributed in the hope that it will be useful,
106 but WITHOUT ANY WARRANTY; without even the implied warranty of
107 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
108