Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Date::Simple.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Date::Simple 3"
132.TH Date::Simple 3 "2002-12-06" "perl v5.8.0" "User Contributed Perl Documentation"
133.SH "NAME"
134Date::Simple \- a simple date object
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& use Date::Simple ('date', 'today');
139.Ve
140.PP
141.Vb 2
142\& # Difference in days between two dates:
143\& $diff = date('2001-08-27') - date('1977-10-05');
144.Ve
145.PP
146.Vb 3
147\& # Offset $n days from now:
148\& $date = today() + $n;
149\& print "$date\en"; # uses ISO 8601 format (YYYY-MM-DD)
150.Ve
151.PP
152.Vb 5
153\& use Date::Simple ();
154\& my $date = Date::Simple->new('1972-01-17');
155\& my $year = $date->year;
156\& my $month = $date->month;
157\& my $day = $date->day;
158.Ve
159.PP
160.Vb 8
161\& use Date::Simple (':all');
162\& my $date2 = ymd($year, $month, $day);
163\& my $date3 = d8('19871218');
164\& my $today = today();
165\& my $tomorrow = $today + 1;
166\& if ($tomorrow->year != $today->year) {
167\& print "Today is New Year's Eve!\en";
168\& }
169.Ve
170.PP
171.Vb 3
172\& if ($today > $tomorrow) {
173\& die "warp in space-time continuum";
174\& }
175.Ve
176.PP
177.Vb 4
178\& print "Today is ";
179\& print(('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur')
180\& [$today->day_of_week]);
181\& print "day.\en";
182.Ve
183.PP
184.Vb 4
185\& # you can also do this:
186\& ($date cmp "2001-07-01")
187\& # and this
188\& ($date <=> [2001, 7, 1])
189.Ve
190.SH "DESCRIPTION"
191.IX Header "DESCRIPTION"
192Dates are complex enough without times and timezones. This module may
193be used to create simple date objects. It handles:
194.IP "Validation." 4
195.IX Item "Validation."
196Reject 1999\-02\-29 but accept 2000\-02\-29.
197.IP "Interval arithmetic." 4
198.IX Item "Interval arithmetic."
199How many days were between two given dates? What date comes N days
200after today?
201.IP "Day-of-week calculation." 4
202.IX Item "Day-of-week calculation."
203What day of the week is a given date?
204.PP
205It does \fBnot\fR deal with hours, minutes, seconds, and time zones.
206.PP
207A date is uniquely identified by year, month, and day integers within
208valid ranges. This module will not allow the creation of objects for
209invalid dates. Attempting to create an invalid date will return
210undef. Month numbering starts at 1 for January, unlike in C and Java.
211Years are 4\-digit.
212.PP
213Gregorian dates up to year 9999 are handled correctly, but we rely on
214Perl's builtin \f(CW\*(C`localtime\*(C'\fR function when the current date is
215requested. On some platforms, \f(CW\*(C`localtime\*(C'\fR may be vulnerable to
216rollovers such as the Unix \f(CW\*(C`time_t\*(C'\fR wraparound of 18 January 2038.
217.PP
218Overloading is used so you can compare or subtract two dates using
219standard numeric operators such as \f(CW\*(C`==\*(C'\fR, and the sum of a date object
220and an integer is another date object.
221.PP
222Date::Simple objects are immutable. After assigning \f(CW$date1\fR to
223\&\f(CW$date2\fR, no change to \f(CW$date1\fR can affect \f(CW$date2\fR. This means,
224for example, that there is nothing like a \f(CW\*(C`set_year\*(C'\fR operation, and
225\&\f(CW\*(C`$date++\*(C'\fR assigns a new object to \f(CW$date\fR.
226.PP
227This module contains various undocumented functions. They may not be
228available on all platforms and are likely to change or disappear in
229future releases. Please let the author know if you think any of them
230should be public.
231.SH "CONSTRUCTORS"
232.IX Header "CONSTRUCTORS"
233Several functions take a string or numeric representation and generate
234a corresponding date object. The most general is \f(CW\*(C`new\*(C'\fR, whose
235argument list may be empty (returning the current date), a string in
236format YYYY-MM-DD or \s-1YYYYMMDD\s0, a list or arrayref of year, month, and
237day number, or an existing date object.
238.IP "Date::Simple\->new ([\s-1ARG\s0, ...])" 4
239.IX Item "Date::Simple->new ([ARG, ...])"
240.PD 0
241.IP "date ([\s-1ARG\s0, ...])" 4
242.IX Item "date ([ARG, ...])"
243.PD
244.Vb 1
245\& my $date = Date::Simple->new('1972-01-17');
246.Ve
247.Sp
248The \f(CW\*(C`new\*(C'\fR method will return a date object if the values passed in
249specify a valid date. (See above.) If an invalid date is passed, the
250method returns undef. If the argument is invalid in form as opposed
251to numeric range, \f(CW\*(C`new\*(C'\fR dies.
252.Sp
253The \f(CW\*(C`date\*(C'\fR function provides the same functionality but must be
254imported or qualified as \f(CW\*(C`Date::Simple::date\*(C'\fR. (To import all public
255functions, do \f(CW\*(C`use Date::Simple (':all');\*(C'\fR.) This function returns
256undef on all invalid input, rather than dying in some cases like
257\&\f(CW\*(C`new\*(C'\fR.
258.IP "\fItoday()\fR" 4
259.IX Item "today()"
260Returns the current date according to \f(CW\*(C`localtime\*(C'\fR.
261.Sp
262\&\fBCaution:\fR To get tomorrow's date (or any fixed offset from today),
263do not use \f(CW\*(C`today + 1\*(C'\fR. Perl parses this as \f(CW\*(C`today(+1)\*(C'\fR. You need
264to put empty parentheses after the function: \f(CW\*(C`today() + 1\*(C'\fR.
265.IP "ymd (\s-1YEAR\s0, \s-1MONTH\s0, \s-1DAY\s0)" 4
266.IX Item "ymd (YEAR, MONTH, DAY)"
267Returns a date object with the given year, month, and day numbers. If
268the arguments do not specify a valid date, undef is returned.
269.Sp
270Example:
271.Sp
272.Vb 2
273\& use Date::Simple ('ymd');
274\& $pbd = ymd(1987, 12, 18);
275.Ve
276.IP "d8 (\s-1STRING\s0)" 4
277.IX Item "d8 (STRING)"
278Parses \s-1STRING\s0 as \*(L"\s-1YYYYMMDD\s0\*(R" and returns the corresponding date object,
279or undef if \s-1STRING\s0 has the wrong format or specifies an invalid date.
280.Sp
281Example:
282.Sp
283.Vb 2
284\& use Date::Simple ('d8');
285\& $doi = d8('17760704');
286.Ve
287.Sp
288Mnemonic: The string matches \f(CW\*(C`/\ed{8}/\*(C'\fR. Also, \*(L"d8\*(R" spells \*(L"date\*(R", if
2898 is expanded phonetically.
290.SH "INSTANCE METHODS"
291.IX Header "INSTANCE METHODS"
292.IP "\s-1DATE\-\s0>next" 4
293.IX Item "DATE->next"
294.Vb 1
295\& my $tomorrow = $today->next;
296.Ve
297.Sp
298Returns an object representing tomorrow.
299.IP "\s-1DATE\-\s0>prev" 4
300.IX Item "DATE->prev"
301.Vb 1
302\& my $yesterday = $today->prev;
303.Ve
304.Sp
305Returns an object representing yesterday.
306.IP "\s-1DATE\-\s0>year" 4
307.IX Item "DATE->year"
308.Vb 1
309\& my $year = $date->year;
310.Ve
311.Sp
312Return the year of \s-1DATE\s0 as an integer.
313.IP "\s-1DATE\-\s0>month" 4
314.IX Item "DATE->month"
315.Vb 1
316\& my $month = $date->month;
317.Ve
318.Sp
319Return the month of \s-1DATE\s0 as an integer from 1 to 12.
320.IP "\s-1DATE\-\s0>day" 4
321.IX Item "DATE->day"
322.Vb 1
323\& my $day = $date->day;
324.Ve
325.Sp
326Return the \s-1DATE\s0's day of the month as an integer from 1 to 31.
327.IP "\s-1DATE\-\s0>day_of_week" 4
328.IX Item "DATE->day_of_week"
329Return a number representing \s-1DATE\s0's day of the week from 0 to 6, where
3300 means Sunday.
331.IP "\s-1DATE\-\s0>as_ymd" 4
332.IX Item "DATE->as_ymd"
333.Vb 1
334\& my ($year, $month, $day) = $date->as_ymd;
335.Ve
336.Sp
337Returns a list of three numbers: year, month, and day.
338.IP "\s-1DATE\-\s0>as_d8" 4
339.IX Item "DATE->as_d8"
340Returns the \*(L"d8\*(R" representation (see \f(CW\*(C`d8\*(C'\fR), like
341\&\f(CW\*(C`$date\->format("%Y%m%d")\*(C'\fR.
342.IP "\s-1DATE\-\s0>format (\s-1STRING\s0)" 4
343.IX Item "DATE->format (STRING)"
344.PD 0
345.IP "\s-1DATE\-\s0>strftime (\s-1STRING\s0)" 4
346.IX Item "DATE->strftime (STRING)"
347.PD
348These functions are equivalent. Return a string representing the
349date, in the format specified. If you don't pass a parameter, an \s-1ISO\s0
3508601 formatted date is returned.
351.Sp
352.Vb 3
353\& my $change_date = $date->format("%d %b %y");
354\& my $iso_date1 = $date->format("%Y-%m-%d");
355\& my $iso_date2 = $date->format;
356.Ve
357.Sp
358The formatting parameter is similar to one you would pass to
359\&\fIstrftime\fR\|(3). This is because we actually do pass it to strftime to
360format the date. This may result in differing behavior across
361platforms and locales and may not even work everywhere.
362.SH "OPERATORS"
363.IX Header "OPERATORS"
364Some operators can be used with Date::Simple instances. If one side
365of an expression is a date object, and the operator expects two date
366objects, the other side is interpreted as \f(CW\*(C`date(ARG)\*(C'\fR, so an array
367reference or \s-1ISO\s0 8601 string will work.
368.IP "\s-1DATE\s0 + \s-1NUMBER\s0" 4
369.IX Item "DATE + NUMBER"
370.PD 0
371.IP "\s-1DATE\s0 \- \s-1NUMBER\s0" 4
372.IX Item "DATE - NUMBER"
373.PD
374You can construct a new date offset by a number of days using the \f(CW\*(C`+\*(C'\fR
375and \f(CW\*(C`\-\*(C'\fR operators.
376.IP "\s-1DATE1\s0 \- \s-1DATE2\s0" 4
377.IX Item "DATE1 - DATE2"
378You can subtract two dates to find the number of days between them.
379.IP "\s-1DATE1\s0 == \s-1DATE2\s0" 4
380.IX Item "DATE1 == DATE2"
381.PD 0
382.IP "\s-1DATE1\s0 < \s-1DATE2\s0" 4
383.IX Item "DATE1 < DATE2"
384.IP "\s-1DATE1\s0 <=> \s-1DATE2\s0" 4
385.IX Item "DATE1 <=> DATE2"
386.IP "\s-1DATE1\s0 cmp \s-1DATE2\s0" 4
387.IX Item "DATE1 cmp DATE2"
388.IP "etc." 4
389.IX Item "etc."
390.PD
391You can compare two dates using the arithmetic or string comparison
392operators. Equality tests (\f(CW\*(C`==\*(C'\fR and \f(CW\*(C`eq\*(C'\fR) return false when one of
393the expressions can not be converted to a date. Other comparison
394tests die in such cases. This is intentional, because in a sense, all
395non-dates are not \*(L"equal\*(R" to all dates, but in no sense are they
396\&\*(L"greater\*(R" or \*(L"less\*(R" than dates.
397.IP "\s-1DATE\s0 += \s-1NUMBER\s0" 4
398.IX Item "DATE += NUMBER"
399.PD 0
400.IP "\s-1DATE\s0 \-= \s-1NUMBER\s0" 4
401.IX Item "DATE -= NUMBER"
402.PD
403You can increment or decrement a date by a number of days using the +=
404and \-= operators. This actually generates a new date object and is
405equivalent to \f(CW\*(C`$date = $date + $number\*(C'\fR.
406.ie n .IP """$date""" 4
407.el .IP "``$date''" 4
408.IX Item "$date"
409You can interpolate a date instance directly into a string, in the
410format specified by \s-1ISO\s0 8601 (eg: 2000\-01\-17).
411.SH "UTILITIES"
412.IX Header "UTILITIES"
413.IP "leap_year (\s-1YEAR\s0)" 4
414.IX Item "leap_year (YEAR)"
415Returns true if \s-1YEAR\s0 is a leap year.
416.IP "days_in_month (\s-1YEAR\s0, \s-1MONTH\s0)" 4
417.IX Item "days_in_month (YEAR, MONTH)"
418Returns the number of days in \s-1MONTH\s0, \s-1YEAR\s0.
419.SH "AUTHOR"
420.IX Header "AUTHOR"
421.Vb 2
422\& Marty Pauley <marty@kasei.com>
423\& John Tobey <jtobey@john-edwin-tobey.org>
424.Ve
425.SH "COPYRIGHT"
426.IX Header "COPYRIGHT"
427.Vb 2
428\& Copyright (C) 2001 Kasei
429\& Copyright (C) 2001,2002 John Tobey.
430.Ve
431.PP
432.Vb 2
433\& This program is free software; you can redistribute it and/or
434\& modify it under the terms of either:
435.Ve
436.PP
437.Vb 6
438\& a) the GNU General Public License;
439\& either version 2 of the License, or (at your option) any later
440\& version. You should have received a copy of the GNU General
441\& Public License along with this program; see the file COPYING.
442\& If not, write to the Free Software Foundation, Inc., 59
443\& Temple Place, Suite 330, Boston, MA 02111-1307 USA
444.Ve
445.PP
446.Vb 1
447\& b) the Perl Artistic License.
448.Ve
449.PP
450.Vb 3
451\& This program is distributed in the hope that it will be useful,
452\& but WITHOUT ANY WARRANTY; without even the implied warranty of
453\& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
454.Ve