Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / Date::Calc::Object.3
.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "OBJECT 1"
.TH OBJECT 1 "2002-09-28" "perl v5.8.0" "User Contributed Perl Documentation"
.SH "NAME"
Date::Calc::Object \- Object\-oriented add\-on for Date::Calc with overloaded operators
.SH "MOTTO"
.IX Header "MOTTO"
Make frequent things easy and infrequent or hard things possible
.SH "PREFACE"
.IX Header "PREFACE"
Note that you do \fB\s-1NOT\s0\fR need to "\f(CW\*(C`use Date::Calc qw(...);\*(C'\fR" in
addition to this module.
.PP
Simply
.PP
.Vb 1
\& use Date::Calc::Object qw(...);
.Ve
.PP
\&\fB\s-1INSTEAD\s0 \s-1OF\s0\fR
.PP
.Vb 1
\& use Date::Calc qw(...);
.Ve
.PP
with the same "\f(CW\*(C`qw(...)\*(C'\fR\*(L" as you would with the \*(R"Date::Calc\*(L"
module, and then forget about \*(R"Date::Calc::Object" altogether.
.PP
The rest of your existing code doesn't change at all.
.PP
Note also that in order to create a new date object, you do not
need to use
.PP
.Vb 1
\& $date_object = Date::Calc::Object->new(...);
.Ve
.PP
(but you may), and should use
.PP
.Vb 1
\& $date_object = Date::Calc->new(...);
.Ve
.PP
instead (saves you some typing and is a trifle faster).
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Sh "Export tags"
.IX Subsection "Export tags"
.Vb 3
\& :all - all functions from Date::Calc
\& :aux - auxiliary functions shift_*
\& :ALL - both :all and :aux
.Ve
.Sh "Functions"
.IX Subsection "Functions"
See \fIDate::Calc\fR\|(3) for a list of available functions.
.PP
.Vb 4
\& $year = shift_year(\e@_);
\& ($year,$mm,$dd) = shift_date(\e@_);
\& ($hrs,$min,$sec) = shift_time(\e@_);
\& ($year,$mm,$dd,$hrs,$min,$sec) = shift_datetime(\e@_);
.Ve
.Sh "Methods"
.IX Subsection "Methods"
.Vb 5
\& $old = Date::Calc->accurate_mode([FLAG]);
\& $old = Date::Calc->number_format([NUMBER|CODEREF]);
\& $old = Date::Calc->delta_format([NUMBER|CODEREF]); # global default
\& $old = Date::Calc->date_format([NUMBER|CODEREF]); # global default
\& $old = Date::Calc->language([LANGUAGE]); # global default
.Ve
.PP
.Vb 5
\& $old = $date->accurate_mode([FLAG]); # is global nevertheless!
\& $old = $date->number_format([NUMBER|CODEREF]); # is global nevertheless!
\& $old = $date->delta_format([NUMBER|CODEREF]); # individual override
\& $old = $date->date_format([NUMBER|CODEREF]); # individual override
\& $old = $date->language([LANGUAGE]); # individual override
.Ve
.PP
.Vb 5
\& $flag = $date->is_delta();
\& $flag = $date->is_date();
\& $flag = $date->is_short(); # i.e., has no time part
\& $flag = $date->is_long(); # i.e., has time part
\& $flag = $date->is_valid();
.Ve
.PP
.Vb 6
\& $date = Date::Calc->new([TYPE]);
\& $date = Date::Calc->new([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]);
\& $date = Date::Calc->new($arrayref);
\& $newdate = $somedate->new([TYPE]);
\& $newdate = $somedate->new([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]);
\& $newdate = $somedate->new($arrayref);
.Ve
.PP
.Vb 4
\& $datecopy = $date->clone();
\& $targetdate->copy($sourcedate);
\& $targetdate->copy($arrayref);
\& $targetdate->copy(@list);
.Ve
.PP
.Vb 6
\& ($year,$month,$day) = $date->date([TYPE]);
\& ($year,$month,$day) = $date->date([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]);
\& ($year,$month,$day) = $date->date($arrayref);
\& ([$hrs,$min,$sec]) = $date->time([TYPE]);
\& ($hrs,$min,$sec) = $date->time([TYPE,]HRS,MIN,SEC);
\& ([$hrs,$min,$sec]) = $date->time($arrayref);
.Ve
.PP
.Vb 4
\& ($year,$month,$day,$hrs,$min,$sec) =
\& $date->datetime([TYPE]);
\& ($year,$month,$day,$hrs,$min,$sec) =
\& $date->datetime([TYPE,]YEAR,MONTH,DAY[,HRS,MIN,SEC]);
.Ve
.PP
.Vb 7
\& $date = Date::Calc->today([FLAG]);
\& $date = Date::Calc->now([FLAG]); # shorthand for --+
\& $date = Date::Calc->today_and_now([FLAG]); # <-----+
\& $date = Date::Calc->gmtime([time]); # UTC/GMT
\& $date = Date::Calc->localtime([time]); # local time
\& $delta = Date::Calc->tzoffset([time]);
\& $date = Date::Calc->time2date([time]); # UTC/GMT
.Ve
.PP
.Vb 7
\& $date->today([FLAG]); # updates the date part only
\& $date->now([FLAG]); # updates the time part only
\& $date->today_and_now([FLAG]); # updates both date and time
\& $date->gmtime([time]); # updates both date and time (UTC/GMT)
\& $date->localtime([time]); # updates both date and time (local time)
\& $delta->tzoffset([time]); # updates both date and time
\& $date->time2date([time]); # updates both date and time (UTC/GMT)
.Ve
.PP
.Vb 2
\& $time = Date::Calc->mktime(); # same as "$time = CORE::time();"
\& $time = Date::Calc->date2time(); # same as "$time = CORE::time();"
.Ve
.PP
.Vb 2
\& $time = $date->mktime(); # converts into Unix time (local time)
\& $time = $date->date2time(); # converts into Unix time (UTC/GMT)
.Ve
.PP
.Vb 6
\& $year = $date->year([YEAR]);
\& $month = $date->month([MONTH]);
\& $day = $date->day([DAY]);
\& $hours = $date->hours([HRS]);
\& $minutes = $date->minutes([MIN]);
\& $seconds = $date->seconds([SEC]);
.Ve
.PP
.Vb 2
\& $number = $date->number([NUMBER|CODEREF]);
\& $string = $date->string([NUMBER|CODEREF][,LANGUAGE]);
.Ve
.PP
.Vb 1
\& $delta->normalize(); # renormalizes a delta vector
.Ve
.Sh "Overloaded Operators"
.IX Subsection "Overloaded Operators"
.Vb 4
\& #####################################################
\& # Scalar operands are always converted into a delta #
\& # vector with that many days, i.e., [1,0,0,SCALAR] #
\& #####################################################
.Ve
.Sh "Comparison Operators:"
.IX Subsection "Comparison Operators:"
.Vb 6
\& if ($date1 < $date2) { # compares date part only
\& if ($date1 <= $date2) { # compares date part only
\& if ($date1 > $date2) { # compares date part only
\& if ($date1 >= $date2) { # compares date part only
\& if ($date1 == $date2) { # compares date part only
\& if ($date1 != $date2) { # compares date part only
.Ve
.PP
.Vb 1
\& $comp = $date1 <=> $date2; # compares date part only
.Ve
.PP
.Vb 6
\& if ($date1 lt $date2) { # compares both date and time
\& if ($date1 le $date2) { # compares both date and time
\& if ($date1 gt $date2) { # compares both date and time
\& if ($date1 ge $date2) { # compares both date and time
\& if ($date1 eq $date2) { # compares both date and time
\& if ($date1 ne $date2) { # compares both date and time
.Ve
.PP
.Vb 1
\& $comp = $date1 cmp $date2; # compares both date and time
.Ve
.PP
Note that you can of course also compare two deltas,
but not a date and a delta!
.PP
.Vb 4
\& ##################################################
\& # Default TYPE for array refs in comparisons is: #
\& # Same as other operand #
\& ##################################################
.Ve
.PP
.Vb 2
\& if ([2000,4,1] == $date) {
\& if ($today > [2000,4,1]) {
.Ve
.PP
.Vb 1
\& if ($now ge [2000,3,26,2,0,0]) {
.Ve
.PP
.Vb 2
\& if ($delta == [18,0,0]) {
\& if ($delta == -1) {
.Ve
.Sh "Plus:"
.IX Subsection "Plus:"
.Vb 5
\& $date2 = $date1 + $delta;
\& $date2 = $delta + $date1;
\& $date += $delta;
\& $this = $date++;
\& $next = ++$date;
.Ve
.PP
.Vb 5
\& $delta3 = $delta1 + $delta2;
\& $delta1 += $delta2;
\& $delta += $date; # beware of implicit type change!
\& $delta++;
\& ++$delta;
.Ve
.PP
.Vb 4
\& #####################################################
\& # Default TYPE for array refs in '+' operations is: #
\& # Opposite of other operand #
\& #####################################################
.Ve
.PP
.Vb 6
\& $date2 = [2000,3,26] + $delta;
\& $date2 = $date1 + [+1,0,0];
\& $date2 = [0,0,-1] + $date1;
\& $date2 = $date1 + 1;
\& $date += [0,0,+1];
\& $date += 2;
.Ve
.PP
.Vb 6
\& $delta3 = [1,+1,0,-1] + $delta2;
\& $delta3 = $delta1 + [1,0,0,+1];
\& $delta3 = $delta1 + 1;
\& $delta += [1,0,+1,0];
\& $delta += [2000,3,26]; # beware of implicit type change!
\& $delta += 7;
.Ve
.Sh "Unary Minus:"
.IX Subsection "Unary Minus:"
.Vb 1
\& $delta2 = -$delta1;
.Ve
.Sh "Minus:"
.IX Subsection "Minus:"
.Vb 6
\& $delta = $date2 - $date1;
\& $date2 = $date1 - $delta;
\& $date -= $delta;
\& $date2 -= $date1; # beware of implicit type change!
\& $this = $date--;
\& $prev = --$date;
.Ve
.PP
.Vb 4
\& $delta3 = $delta2 - $delta1;
\& $delta2 -= $delta1;
\& $delta--;
\& --$delta;
.Ve
.PP
.Vb 4
\& #####################################################
\& # Default TYPE for array refs in '-' operations is: #
\& # Always a date #
\& #####################################################
.Ve
.PP
.Vb 8
\& $delta = $today - [2000,3,26];
\& $delta = [2000,4,1] - $date;
\& $date2 = [2000,3,26] - $delta;
\& $date2 = $date1 - [1,0,0,+7];
\& $date2 = $date1 - 7;
\& $date -= [1,0,0,+1]; # better add [0,0,-1] instead!
\& $date2 -= [2000,3,26]; # beware of implicit type change!
\& $date2 -= 1;
.Ve
.PP
.Vb 4
\& $delta3 = [1,0,+1,0] - $delta1;
\& $delta3 = $delta2 - [1,0,0,-1];
\& $delta -= [1,0,0,+1];
\& $delta -= 7;
.Ve
.Sh "Miscellaneous Operators:"
.IX Subsection "Miscellaneous Operators:"
.Vb 2
\& $string = "$date";
\& $string = "$delta";
.Ve
.PP
.Vb 2
\& print "$date\en";
\& print "$delta\en";
.Ve
.PP
.Vb 2
\& if ($date) { # date is valid
\& if ($delta) { # delta is valid
.Ve
.PP
.Vb 2
\& $days = abs($date);
\& $diff = abs($delta); # can be negative!
.Ve
.PP
.Vb 1
\& $diff = abs(abs($delta)); # always positive
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
.IP "\(bu" 2
\&\s-1FLAG\s0
.Sp
\&\*(L"\s-1FLAG\s0\*(R" is either 0 (for \*(L"false\*(R") or 1 (for \*(L"true\*(R").
.Sp
In the case of "\f(CW\*(C`accurate_mode()\*(C'\fR\*(L", this switches \*(R"accurate mode"
on and off (see further below for an explanation of what that is).
.Sp
In the case of "\f(CW\*(C`today()\*(C'\fR\*(L", \*(R"\f(CW\*(C`now()\*(C'\fR\*(L" and \*(R"\f(CW\*(C`today_and_now()\*(C'\fR\*(L",
a \*(R"true\*(L" value indicates \*(R"\s-1GMT\s0" (Greenwich Mean Time), as opposed
to local time, which is the default.
.IP "\(bu" 2
\&\s-1NUMBER\s0
.Sp
\&\*(L"\s-1NUMBER\s0\*(R" is a number between 0 and 2 (for \*(L"\fInumber_format()\fR\*(R" and \*(L"\fInumber()\fR\*(R")
or between 0 and 3 (for \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIstring()\fR\*(R"),
indicating which of the three/four predefined formats, respectively,
should be used for converting a date into numeric representation
(needed for comparing dates, for instance) or string representation.
.Sp
Format #0 is the default at startup and the simplest of all (and
should be fastest to calculate, too).
.Sp
The string representation of dates in format #0 also has the advantage of
being sortable in chronological order (and of complying with \s-1ISO\s0\ 8601).
.Sp
(The numeric formats are (trivially) always sortable in chronological
order of course.)
.Sp
The other formats are increasingly more sophisticated (in terms of
esthetics and computation time) with increasing number:
.Sp
.Vb 1
\& Delta number formats (short):
.Ve
.Sp
.Vb 3
\& 0 13603
\& 1 13603
\& 2 13603
.Ve
.Sp
.Vb 1
\& Delta string formats (short):
.Ve
.Sp
.Vb 4
\& 0 '+0+0+13603'
\& 1 '+0 +0 +13603'
\& 2 '+0Y +0M +13603D'
\& 3 '+0 Y +0 M +13603 D'
.Ve
.Sp
.Vb 1
\& Date number formats (short):
.Ve
.Sp
.Vb 3
\& 0 20010401
\& 1 730576
\& 2 730576
.Ve
.Sp
.Vb 1
\& Date string formats (short):
.Ve
.Sp
.Vb 4
\& 0 '20010401'
\& 1 '01-Apr-2001'
\& 2 'Sun 1-Apr-2001'
\& 3 'Sunday, April 1st 2001'
.Ve
.Sp
.Vb 1
\& Delta number formats (long):
.Ve
.Sp
.Vb 3
\& 0 13603.012959
\& 1 13603.012959
\& 2 13603.0624884259
.Ve
.Sp
.Vb 1
\& Delta string formats (long):
.Ve
.Sp
.Vb 4
\& 0 '+0+0+13603+1+29+59'
\& 1 '+0 +0 +13603 +1 +29 +59'
\& 2 '+0Y +0M +13603D +1h +29m +59s'
\& 3 '+0 Y +0 M +13603 D +1 h +29 m +59 s'
.Ve
.Sp
.Vb 1
\& Date number formats (long):
.Ve
.Sp
.Vb 3
\& 0 20010401.082959
\& 1 730576.082959
\& 2 730576.354155093
.Ve
.Sp
.Vb 1
\& Date string formats (long):
.Ve
.Sp
.Vb 4
\& 0 '20010401082959'
\& 1 '01-Apr-2001 08:29:59'
\& 2 'Sun 1-Apr-2001 08:29:59'
\& 3 'Sunday, April 1st 2001 08:29:59'
.Ve
.Sp
If a number outside of the permitted range is specified, or if the value
is not a code reference (see also the next section below for more details),
the default format #0 is used instead.
.IP "\(bu" 2
\&\s-1CODEREF\s0
.Sp
\&\*(L"\s-1CODEREF\s0\*(R" is the reference of a subroutine which can be passed to the
methods \*(L"\fInumber_format()\fR\*(R", \*(L"\fIdelta_format()\fR\*(R" and \*(L"\fIdate_format()\fR\*(R" in order
to install a callback function which will be called subsequently whenever
a date (or delta) object needs to be (implicitly) converted into a number
or string.
.Sp
This happens for instance when you compare two date objects, or when you
put a date object reference in a string between double quotes.
.Sp
Such a \*(L"\s-1CODEREF\s0\*(R" can also be passed to the methods \*(L"\fInumber()\fR\*(R" and
\&\*(L"\fIstring()\fR\*(R" for explicitly converting a date object as desired.
.IP "\(bu" 2
\&\s-1LANGUAGE\s0
.Sp
\&\*(L"\s-1LANGUAGE\s0\*(R" is either a number in the range \f(CW\*(C`[1..Languages()]\*(C'\fR,
or one of the strings "\f(CW\*(C`Language_to_Text(1..Languages())\*(C'\fR"
(see also \fIDate::Calc\fR\|(3)).
.IP "\(bu" 2
\&\s-1TYPE\s0
.Sp
\&\*(L"\s-1TYPE\s0\*(R" is 0 for a regular date and 1 for a delta vector (a list of
year, month, day and optionally hours, minutes and seconds offsets).
.IP "\(bu" 2
Storage
.Sp
\&\*(L"Date::Calc\*(R" objects are implemented as two nested arrays.
.Sp
The \*(L"blessed\*(R" array (whose reference is the object reference
you receive when calling the \*(L"\fInew()\fR\*(R" method) contains an
anonymous array at position zero and the object's data in
its remaining fields.
.Sp
The embedded anonymous array is used for storing the object's
attributes (flags).
.Sp
Dates and delta vectors always comprise either 3 or 6 data values:
Year, month, day plus (optionally) hours, minutes and seconds.
.Sp
These values are stored in the \*(L"blessed\*(R" array at positions 1..3
or 1..6, respectively.
.Sp
An object without the time values is therefore called \*(L"short\*(R",
and an object having time values is called \*(L"long\*(R" throughout
this manual.
.Sp
Hint: Whenever possible, if you do not need the time values, omit
them, i.e., always use the \*(L"short\*(R" form of the object if possible,
this will speed up calculations a little (the short form uses
different (faster) functions for all calculations internally).
.Sp
The embedded anonymous array contains various flags:
.Sp
At position zero, it contains the \*(L"\s-1TYPE\s0\*(R" indicator which determines
whether the object is a date or a delta vector.
.Sp
At position 1, the object stores the \*(L"\s-1NUMBER\s0\*(R" of one of the delta
vector formats, or the reference of a callback function which converts
the contents of the object into string representation if it's a delta
vector, or \*(L"undef\*(R" if the global settings apply.
.Sp
At position 2, the object stores the \*(L"\s-1NUMBER\s0\*(R" of one of the date formats,
or the reference of a callback function which converts the contents of
the object into string representation if it's a date, or \*(L"undef\*(R" if the
global settings apply.
.Sp
At position 3, the object stores the \*(L"\s-1LANGUAGE\s0\*(R" to be used for all
conversions into strings (where applicable), or \*(L"undef\*(R" if the global
language setting applies.
.Sp
Note that your callback functions (see the section \*(L"Callback Functions\*(R"
further below for more details) do not need to pay attention to the
value at position 3, the language (of the \*(L"Date::Calc\*(R" module)
will automatically be set to this value whenever the callback
functions are called, and automatically reset to its former value
after the callback.
.Sp
So if your callback functions use the \*(L"*_to_Text*\*(R" functions from
the \*(L"Date::Calc\*(R" module, they will automatically use the correct
language.
.Sp
Be reminded though that you should \fB\s-1NEVER\s0\fR access the object's
internal data directly, i.e., through their positional numbers,
but \fB\s-1ALWAYS\s0\fR through their respective accessor methods, e.g.:
.Sp
.Vb 16
\& year()
\& month()
\& day()
\& hours()
\& minutes()
\& seconds()
\& date()
\& time()
\& datetime()
\& is_delta()
\& is_date()
\& is_short()
\& is_long()
\& delta_format()
\& date_format()
\& language()
.Ve
.Sp
And although position 4 and onward in the embedded anonymous array is
currently unused, it might not stay so in future releases of this module.
.Sp
Therefore, in case you need more attributes in a subclass of the
\&\*(L"Date::Calc[::Object]\*(R" class, I suggest using values starting at
positions a bit further up, e.g. 6, 8 or 10.
.IP "\(bu" 2
Invalid Dates
.Sp
Only \*(L"\fInew()\fR\*(R" allows to create objects containing possibly invalid
dates (needed for reading in and evaluating user input, for example).
.IP "\(bu" 2
Usage
.Sp
The methods
.Sp
.Vb 14
\& accurate_mode()
\& number_format()
\& delta_format()
\& date_format()
\& language()
\& date()
\& time()
\& datetime()
\& year()
\& month()
\& day()
\& hours()
\& minutes()
\& seconds()
.Ve
.Sp
are used for reading as well as for setting attributes. They simply
return the values in question if they are called without parameters.
.Sp
The methods
.Sp
.Vb 5
\& accurate_mode()
\& number_format()
\& delta_format()
\& date_format()
\& language()
.Ve
.Sp
always return the previous value if a new value is set. This allows
you to change these values temporarily and to restore their old value
afterwards more easily (but you can also override the \*(L"format\*(R" and
\&\*(L"language\*(R" settings directly when calling the \*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R"
method).
.Sp
The methods
.Sp
.Vb 9
\& date()
\& time()
\& datetime()
\& year()
\& month()
\& day()
\& hours()
\& minutes()
\& seconds()
.Ve
.Sp
always return the new values when the corresponding values have
been changed.
.Sp
The method \*(L"\fIdate()\fR\*(R" \s-1NEVER\s0 returns the time values (hours, minutes,
seconds) even if they have just been set using this method (which
the method optionally allows). Otherwise it would be very hard to
predict the exact number of values it returns, which might lead
to errors (wrong number of parameters) elsewhere in your program.
.Sp
The method \*(L"\fIdatetime()\fR\*(R" \s-1ALWAYS\s0 returns the time values (hours,
minutes, seconds) even if the object in question lacks a time
part. In that case, zeros are returned for hours, minutes and
seconds instead (but the stored time part is left unchanged,
whether it exists or not).
.Sp
If you do not provide values for hours, minutes and seconds when
using the method \*(L"\fIdate()\fR\*(R" to set the values for year, month and
day, the time part will not be changed (whether it exists or not).
.Sp
If you do not provide values for hours, minutes and seconds when
using the method \*(L"\fIdatetime()\fR\*(R" to set the values for year, month
and day, the time part will be filled with zeros (the time part
will be created if necessary).
.Sp
If the object is short, i.e., if it does not have any time values,
the method \*(L"\fItime()\fR\*(R" returns an empty list.
.Sp
If the object is short and the methods \*(L"\fIhours()\fR\*(R", \*(L"\fIminutes()\fR\*(R" or
\&\*(L"\fIseconds()\fR\*(R" are used to set any of these time values, the object
is automatically promoted to the \*(L"long\*(R" form, and the other two
time values are filled with zeros.
.Sp
The following methods can also return \*(L"undef\*(R" under certain
circumstances:
.Sp
.Vb 13
\& delta_format()
\& date_format()
\& language()
\& is_delta()
\& is_date()
\& is_short()
\& is_long()
\& is_valid()
\& hours()
\& minutes()
\& seconds()
\& number()
\& string()
.Ve
.Sp
The methods \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIlanguage()\fR\*(R"
return \*(L"undef\*(R" when they are called as object methods and no
individual override has been defined for the object in question.
.Sp
The \*(L"is_*()\*(R" predicate methods return \*(L"undef\*(R" if the object in
question does not have the expected internal structure. This can
happen for instance when you create an empty object with \*(L"\fInew()\fR\*(R".
.Sp
When called without parameters, the methods \*(L"\fIhours()\fR\*(R", \*(L"\fIminutes()\fR\*(R"
and \*(L"\fIseconds()\fR\*(R" return \*(L"undef\*(R" if the object in question does not
have a time part.
.Sp
The methods \*(L"\fInumber()\fR\*(R" and \*(L"\fIstring()\fR\*(R" return \*(L"undef\*(R" if the object
in question is not valid (i.e., if \*(L"\fIis_valid()\fR\*(R" returns \*(L"undef\*(R" or
false).
.Sp
And finally, the methods
.Sp
.Vb 9
\& copy()
\& today()
\& now()
\& today_and_now()
\& gmtime()
\& localtime()
\& tzoffset()
\& time2date()
\& normalize()
.Ve
.Sp
return the object reference of the (target) object in question
for convenience.
.IP "\(bu" 2
Import/Export
.Sp
Note that you can import and export Unix \*(L"time\*(R" values using the
methods \*(L"\fIgmtime()\fR\*(R", \*(L"\fIlocaltime()\fR\*(R", \*(L"\fImktime()\fR\*(R", \*(L"\fIdate2time()\fR\*(R" and
\&\*(L"\fItime2date()\fR\*(R", both as local time or as \s-1UTC/GMT\s0.
.IP "\(bu" 2
Accurate Mode
.Sp
The method \*(L"\fIaccurate_mode()\fR\*(R" controls the internal flag which
determines which of two modes of operation is used.
.Sp
When set to true (the default at startup), delta vectors are
calculated to give the exact difference in days between two
dates. The \*(L"year\*(R" and \*(L"month\*(R" entries in the resulting delta
vector are always zero in that case.
.Sp
If \*(L"accurate mode\*(R" is switched off (when the corresponding
flag is set to false), delta vectors are calculated with
year and month differences.
.Sp
E.g., the difference between \f(CW\*(C`[1999,12,6]\*(C'\fR and \f(CW\*(C`[2000,6,24]\*(C'\fR
is \f(CW\*(C`[+0 +0 +201]\*(C'\fR (plus 201 days) in accurate mode and
\&\f(CW\*(C`[+1 \-6 +18]\*(C'\fR (plus one year, minus 6 months, plus 18 days)
when accurate mode is switched off.
.Sp
(The delta vector is calculated by simply taking the difference
in years, the difference in months and the difference in days.)
.Sp
Because years and months have varying lengths in terms of days,
the latter is less accurate than the former because it depends
on the context of the two dates of which it represents the
difference. Added to a different date, the latter delta vector
may yield a different offset in terms of days.
.Sp
Beware also that \- for the same reason \- the absolute value
("\f(CW\*(C`abs()\*(C'\fR\*(L") of a delta vector returns a fictitious number
of days if the delta vector contains non-zero values for
\&\*(R"year\*(L" and/or \*(R"month" (see also next section below for
more details).
.Sp
Example:
.Sp
The difference between \f(CW\*(C`[2000,1,1]\*(C'\fR and \f(CW\*(C`[2000,3,1]\*(C'\fR is
\&\f(CW\*(C`[+0 +0 +60]\*(C'\fR in accurate mode and \f(CW\*(C`[+0 +2 +0]\*(C'\fR else (one
could also call this \*(L"year\-month\-day mode\*(R" or \*(L"\s-1YMD\s0 mode\*(R" for
short).
.Sp
When added to the date \f(CW\*(C`[2000,4,1]\*(C'\fR, the \*(L"accurate\*(R" delta
vector yields the date \f(CW\*(C`[2000,5,31]\*(C'\fR, whereas the other delta
vector yields the date \f(CW\*(C`[2000,6,1]\*(C'\fR.
.Sp
Moreover, when added to the date \f(CW\*(C`[1999,1,1]\*(C'\fR, the \*(L"accurate\*(R"
delta vector yields the date \f(CW\*(C`[1999,3,2]\*(C'\fR, whereas the \*(L"inaccurate\*(R"
delta vector yields the date \f(CW\*(C`[1999,3,1]\*(C'\fR.
.Sp
Depending on what you want, the one or the other mode may suit
you better.
.IP "\(bu" 2
Absolute Value
.Sp
Note that "\f(CW\*(C`abs($date)\*(C'\fR\*(L" and \*(R"\f(CW\*(C`abs($delta)\*(C'\fR\*(L" are just shorthands
for \*(R"\f(CW\*(C`$date\->number()\*(C'\fR\*(L" and \*(R"\f(CW\*(C`$delta\->number()\*(C'\fR".
.Sp
The operator "\f(CW\*(C`abs()\*(C'\fR", when applied to a date or delta vector,
returns the corresponding number of days (see below for an exception
to this), with the time part (if available) represented by a fraction
after the decimal point.
.Sp
In the case of dates, the absolute value (to the left of the
decimal point) is the number of days since the 1st of January
1\ A.D. (by extrapolating the Gregorian calendar back beyond
its \*(L"natural\*(R" limit of 1582 A.D.) \fB\s-1PLUS\s0 \s-1ONE\s0\fR.
.Sp
(I.e., the absolute value of the 1st of January 1 A.D. is 1.)
.Sp
Exception:
.Sp
If the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 0 (the default
setting), the absolute value of a date to the left of the decimal
point is \*(L"yyyymmdd\*(R", i.e., the number in which the uppermost four
digits correspond to the year, the next lower two digits to the
month and the lowermost two digits to the day.
.Sp
In the case of delta vectors, the absolute value (to the left
of the decimal point) is simply the difference in days (but
see also below).
.Sp
Note that the absolute value of a delta vector can be negative!
.Sp
If you want a positive value in all cases, apply the "\f(CW\*(C`abs()\*(C'\fR\*(L"
operator again, i.e., \*(R"\f(CW\*(C`$posdiff = abs(abs($delta));\*(C'\fR".
.Sp
If the delta vector contains non-zero values for \*(L"year\*(R" and/or
\&\*(L"month\*(R" (see also the discussion of \*(L"Accurate Mode\*(R" in the section
above), an exact representation in days cannot be calculated,
because years and months do not have fixed equivalents in days.
.Sp
If nevertheless you attempt to calculate the absolute value of
such a delta vector, a fictitious value is returned, which is
calculated by simply multiplying the year difference with 12,
adding the month difference, multiplying this sum with 31 and
finally adding the day difference.
.Sp
Beware that because of this, the absolute values of delta
vectors are not necessarily contiguous.
.Sp
Moreover, since there is more than one way to express the
difference between two dates, comparisons of delta vectors
may not always yield the expected result.
.Sp
Example:
.Sp
The difference between the two dates \f(CW\*(C`[2000,4,30]\*(C'\fR and
\&\f(CW\*(C`[2001,5,1]\*(C'\fR can be expressed as \f(CW\*(C`[+1 +1 \-29]\*(C'\fR, or as
\&\f(CW\*(C`[+1 +0 +1]\*(C'\fR.
.Sp
The first delta vector has an absolute value of 374,
whereas the latter delta vector has an absolute value
of only 373 (while the true difference in days between
the two dates is 366).
.Sp
If the date or delta vector has a time part, the time is returned
as a fraction of a full day after the decimal point as follows:
.Sp
If the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 0 (the default
setting) or 1, this fraction is simply \*(L".hhmmss\*(R", i.e., the
two digits after the decimal point represent the hours, the
next two digits the minutes and the last two digits the seconds.
.Sp
Note that you cannot simply add and subtract these values to
yield meaningful dates or deltas again, you can only use them
for comparisons (equal, not equal, less than, greater than,
etc.). If you want to add/subtract, read on:
.Sp
Only when the \*(L"\s-1NUMBER\s0\*(R" or \*(L"\fInumber_format()\fR\*(R" is set to 2, this
fraction will be the equivalent number of seconds (i.e.,
\&\f(CW\*(C`(((hours * 60) + minutes) * 60) + seconds\*(C'\fR) divided by the
number of seconds in a full day (i.e., \f(CW\*(C`24*60*60 = 86400\*(C'\fR),
or \f(CW\*(C`0/86400\*(C'\fR, \f(CW\*(C`1/86400\*(C'\fR, ... , \f(CW\*(C`86399/86400\*(C'\fR.
.Sp
In other words, the (mathematically correct) fraction of a day.
.Sp
You can safely perform arithmetics with these values as far
as the internal precision of your vendor's implementation
of the C run-time library (on which Perl depends) will permit.
.IP "\(bu" 2
Renormalizing Delta Vectors
.Sp
When adding or subtracting delta vectors to/from one another,
the addition or subtraction takes place component by component.
.Sp
Example:
.Sp
.Vb 2
\& [+0 +0 +0 +3 +29 +50] + [+0 +0 +0 +0 +55 +5] = [+0 +0 +0 +3 +84 +55]
\& [+0 +0 +0 +3 +29 +50] - [+0 +0 +0 +0 +55 +5] = [+0 +0 +0 +3 -26 +45]
.Ve
.Sp
This may result in time values outside the usual ranges (\f(CW\*(C`[\-23..+23]\*(C'\fR
for hours and \f(CW\*(C`[\-59..+59]\*(C'\fR for minutes and seconds).
.Sp
Note that even though the delta value for days will often become quite large,
it is impossible to renormalize this value because there is no constant
conversion factor from days to months (should it be 28, 29, 30 or 31?).
.Sp
If accurate mode (see further above for what that is) is switched off,
delta vectors can also contain non-zero values for years and months. If
you add or subtract these, the value for months can lie outside the
range \f(CW\*(C`[\-11..11]\*(C'\fR, which isn't wrong, but may seem funny.
.Sp
Therefore, the \*(L"\fInormalize()\fR\*(R" method will also renormalize the \*(L"months\*(R"
value, if and only if accurate mode has been switched off. (!)
.Sp
(Hence, switch accurate mode \fB\s-1ON\s0\fR temporarily if you \fB\s-1DON\s0'T\fR want
the renormalization of the \*(L"months\*(R" value to happen.)
.Sp
If you want to force the time values from the example above back into
their proper ranges, use the \*(L"\fInormalize()\fR\*(R" method as follows:
.Sp
.Vb 3
\& print "[$delta]\en";
\& $delta->normalize();
\& print "[$delta]\en";
.Ve
.Sp
This will print
.Sp
.Vb 2
\& [+0 +0 +0 +3 +84 +55]
\& [+0 +0 +0 +4 +24 +55]
.Ve
.Sp
for the first and
.Sp
.Vb 2
\& [+0 +0 +0 +3 -26 +45]
\& [+0 +0 +0 +2 +34 +45]
.Ve
.Sp
for the second delta vector from the example further above.
.Sp
Note that the values for days, hours, minutes and seconds are
guaranteed to have the same sign after the renormalization.
.Sp
Under \*(L"normal\*(R" circumstances, i.e., when accurate mode is on (the
default), this method only has an effect on the time part of the
delta vector.
.Sp
If the delta vector in question does not have a time part, nothing
is done.
.Sp
If accurate mode is off, the \*(L"months\*(R" value is also normalized,
i.e., if it lies outside of the range \f(CW\*(C`[\-11..11]\*(C'\fR, integer
multiples of 12 are added to the \*(L"years\*(R" value and subtracted
from the \*(L"months\*(R" value. Moreover, the \*(L"months\*(R" value is
guaranteed to have the same sign as the values for days,
hours, minutes and seconds, unless the \*(L"months\*(R" value is zero
or the values for days, hours, minutes and seconds are all zero.
.Sp
If the object in question is a date and if warnings are enabled,
the message \*(L"normalizing a date is a no\-op\*(R" will be printed to
\&\s-1STDERR\s0.
.Sp
If the object in question is not a valid \*(L"Date::Calc\*(R" object,
nothing is done.
.Sp
The method returns its object's reference, which allows chaining
of method calls, as in the following example:
.Sp
.Vb 1
\& @time = $delta->normalize()->time();
.Ve
.IP "\(bu" 2
Callback Functions
.Sp
Note that you are not restricted to the built-in formats
(numbered from 0 to 2 for \*(L"\fInumber_format()\fR\*(R" and \*(L"\fInumber()\fR\*(R"
and from 0 to 3 for \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and
\&\*(L"\fIstring()\fR\*(R") for converting a date or delta object into a
number or string.
.Sp
You can also provide your own function(s) for doing so, in
order to suit your own taste or needs, by passing a subroutine
reference to the appropriate method, i.e., \*(L"\fInumber_format()\fR\*(R",
\&\*(L"\fInumber()\fR\*(R", \*(L"\fIdelta_format()\fR\*(R", \*(L"\fIdate_format()\fR\*(R" and \*(L"\fIstring()\fR\*(R".
.Sp
You can pass a handler to only one or more of these methods,
or to all of them, as you like. You can use different callback
functions, or the same for all.
.Sp
In order to facilitate the latter, and in order to make the
decoding of the various cases easier for you, the callback
function receives a uniquely identifying function code as
its second parameter:
.Sp
.Vb 8
\& 0 = TO_NUMBER | IS_DATE | IS_SHORT (number[_format])
\& 1 = TO_NUMBER | IS_DATE | IS_LONG (number[_format])
\& 2 = TO_NUMBER | IS_DELTA | IS_SHORT (number[_format])
\& 3 = TO_NUMBER | IS_DELTA | IS_LONG (number[_format])
\& 4 = TO_STRING | IS_DATE | IS_SHORT (string|date_format)
\& 5 = TO_STRING | IS_DATE | IS_LONG (string|date_format)
\& 6 = TO_STRING | IS_DELTA | IS_SHORT (string|delta_format)
\& 7 = TO_STRING | IS_DELTA | IS_LONG (string|delta_format)
.Ve
.Sp
The first parameter of the callback function is of course the
handle of the object in question itself (therefore, the callback
function can actually be an object method \- but not a class method,
for obvious reasons).
.Sp
The handler should return the resulting number or string, as
requested.
.Sp
\&\s-1BEWARE\s0 that you should \s-1NEVER\s0 rely upon any knowledge of the
object's internal structure, as this may be subject to change!
.Sp
\&\s-1ALWAYS\s0 use the test and access methods provided by this module!
.Sp
Example:
.Sp
.Vb 3
\& sub handler
\& {
\& my($self,$code) = @_;
.Ve
.Sp
.Vb 48
\& if ($code == 0) # TO_NUMBER | IS_DATE | IS_SHORT
\& {
\& return Date_to_Days( $self->date() );
\& }
\& elsif ($code == 1) # TO_NUMBER | IS_DATE | IS_LONG
\& {
\& return Date_to_Days( $self->date() ) +
\& ( ( $self->hours() * 60 +
\& $self->minutes() ) * 60 +
\& $self->seconds() ) / 86400;
\& }
\& elsif ($code == 2) # TO_NUMBER | IS_DELTA | IS_SHORT
\& {
\& return ( $self->year() * 12 +
\& $self->month() ) * 31 +
\& $self->day();
\& }
\& elsif ($code == 3) # TO_NUMBER | IS_DELTA | IS_LONG
\& {
\& return ( $self->year() * 12 +
\& $self->month() ) * 31 +
\& $self->day() +
\& ( ( $self->hours() * 60 +
\& $self->minutes() ) * 60 +
\& $self->seconds() ) / 86400;
\& }
\& elsif ($code == 4) # TO_STRING | IS_DATE | IS_SHORT
\& {
\& return join( "/", $self->date() );
\& }
\& elsif ($code == 5) # TO_STRING | IS_DATE | IS_LONG
\& {
\& return join( "/", $self->date() ) . " " .
\& join( ":", $self->time() );
\& }
\& elsif ($code == 6) # TO_STRING | IS_DELTA | IS_SHORT
\& {
\& return join( "|", $self->date() );
\& }
\& elsif ($code == 7) # TO_STRING | IS_DELTA | IS_LONG
\& {
\& return join( "|", $self->datetime() );
\& }
\& else
\& {
\& die "internal error";
\& }
\& }
.Ve
.Sp
.Vb 3
\& Date::Calc->number_format(\e&handler);
\& Date::Calc->delta_format(\e&handler);
\& Date::Calc->date_format(\e&handler);
.Ve
.Sp
This sets our handler to take care of all automatic conversions,
such as needed when comparing dates or when interpolating a string
in double quotes which contains a date object.
.Sp
To deactivate a handler, simply pass a valid format number to the
method in question, e.g.:
.Sp
.Vb 3
\& Date::Calc->number_format(0);
\& Date::Calc->delta_format(2);
\& Date::Calc->date_format(3);
.Ve
.Sp
When calling the \*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R" method explicitly, you can
pass a different format number (than the global setting), like this:
.Sp
.Vb 2
\& $number = $date->number(2);
\& $string = $date->string(1);
.Ve
.Sp
You can also pass a handler's reference, like so:
.Sp
.Vb 2
\& $number = $date->number(\e&handler);
\& $string = $date->string(\e&handler);
.Ve
.Sp
This overrides the global setting for the duration of the call of
\&\*(L"\fInumber()\fR\*(R" or \*(L"\fIstring()\fR\*(R" (but doesn't change the global setting
itself).
.Sp
Moreover, you can also define individual overrides for the date and
the delta vector formats (but not the number format) for individual
objects, e.g.:
.Sp
.Vb 2
\& $date->delta_format(1);
\& $date->date_format(2);
.Ve
.Sp
.Vb 2
\& $date->delta_format(\e&handler);
\& $date->date_format(\e&handler);
.Ve
.Sp
In order to deactivate an individual handler for an object, and/or
in order to deactivate any override altogether (so that the global
settings apply again), you have to pass \*(L"undef\*(R" explicitly to the
method in question:
.Sp
.Vb 2
\& $date->delta_format(undef);
\& $date->date_format(undef);
.Ve
.Sp
You can also define a language for individual objects (see the
next section immediately below for more details).
.Sp
If such an individual language override has been set, and if your
callback handlers only use the \*(L"*_to_Text*\*(R" functions from the
\&\*(L"Date::Calc\*(R" module to produce any text, the text produced will
automatically be in the desired language.
.Sp
This is because the language is set to the value determined by
the individual override before the callback handler is executed,
and reset to its previous value afterwards.
.IP "\(bu" 2
Languages
.Sp
Note that this module is completely transparent to the setting
of a language in \*(L"Date::Calc\*(R". This means that you can choose a
language in \*(L"Date::Calc\*(R" (with the \*(L"\fILanguage()\fR\*(R" function) and all
dates subsequently printed by this module will automatically be
in that language \- provided that you use the built-in formats of
this module, or that you use the \*(L"*to_Text*\*(R" functions from the
\&\*(L"Date::Calc\*(R" module in your formatting handler (callback function).
.Sp
However, this global language setting can be overridden for
individual date (or delta) objects by using the \fB\s-1OBJECT\s0\fR method
.Sp
.Vb 1
\& $oldlang = $date->language($newlang);
.Ve
.Sp
(The global setting is not altered by this in any way.)
.Sp
In order to deactivate such an individual language setting
(so that the global setting applies again), simply pass the
value \*(L"undef\*(R" explicitly to the \*(L"\fIlanguage()\fR\*(R" object method:
.Sp
.Vb 1
\& $date->language(undef);
.Ve
.Sp
The \fB\s-1CLASS\s0\fR method
.Sp
.Vb 1
\& $oldlang = Date::Calc->language($newlang);
.Ve
.Sp
is just a convenient wrapper around the \*(L"\fILanguage()\fR\*(R" function,
which allows you to enter language numbers (as returned by the
\&\*(L"\fIDecode_Language()\fR\*(R" function) or strings (as returned by the
\&\*(L"\fILanguage_to_Text()\fR\*(R" function), at your option.
.Sp
The \*(L"\fIlanguage()\fR\*(R" method (both class and object) always returns
the \fB\s-1NAME\s0\fR (one of "\f(CW\*(C`Language_to_Text(1..Languages())\*(C'\fR") of
the current setting (and never its number).
.IP "\(bu" 2
Exported Functions
.Sp
The \*(L"Date::Calc::Object\*(R" package imports \*(L":all\*(R" functions exported
by the \*(L"Date::Calc\*(R" module and re-exports them, for conveniency.
.Sp
This allows you to write
.Sp
.Vb 1
\& use Date::Calc::Object qw(...);
.Ve
.Sp
instead of
.Sp
.Vb 1
\& use Date::Calc qw(...);
.Ve
.Sp
but with exactly the same semantics. The difference is that
the object-oriented frontend is loaded additionally in the
first case.
.Sp
As with \*(L"Date::Calc\*(R" you can use the \*(L":all\*(R" tag to import all
of \*(L"Date::Calc\*(R"'s functions:
.Sp
.Vb 1
\& use Date::Calc::Object qw(:all);
.Ve
.Sp
In addition to the functions exported by \*(L"Date::Calc\*(R", the
\&\*(L"Date::Calc::Object\*(R" package offers some utility functions
of its own for export:
.Sp
.Vb 4
\& $year = shift_year(\e@_);
\& ($year,$mm,$dd) = shift_date(\e@_);
\& ($hrs,$min,$sec) = shift_time(\e@_);
\& ($year,$mm,$dd,$hrs,$min,$sec) = shift_datetime(\e@_);
.Ve
.Sp
These functions enable your subroutines or methods to accept
a \*(L"Date::Calc\*(R" (or subclass) date object, an (anonymous) array
or a list (containing the necessary values) as parameters
\&\fB\s-1INTERCHANGEABLY\s0\fR.
.Sp
You can import all of these auxiliary functions by using an
\&\*(L":aux\*(R" tag:
.Sp
.Vb 1
\& use Date::Calc::Object qw(:aux);
.Ve
.Sp
If you want to import both all of the \*(L"Date::Calc\*(R" functions
as well as all these auxiliary functions, use the \*(L":ALL\*(R" tag:
.Sp
.Vb 1
\& use Date::Calc::Object qw(:ALL);
.Ve
.IP "\(bu" 2
Subclassing
.Sp
In case you want to subclass \*(L"Date::Calc\*(R" objects and to add
new attributes of your own, it is recommended that you proceed
as follows (the following will be considered as a part of the
module's \*(L"contract of use\*(R" \- which might be subject to change
in the future, however):
.Sp
Define a constant for the index of each attribute you want to
add, currently starting no lower than \*(L"4\*(R", at the top of your
subclass:
.Sp
.Vb 4
\& use constant ATTRIB1 => 4;
\& use constant ATTRIB2 => 5;
\& use constant ATTRIB3 => 6;
\& ...
.Ve
.Sp
It is recommended that you use constants (which are easy to
change), because I someday might want to require the element
with index \*(L"4\*(R" for a new attribute of my own... \f(CW\*(C`:\-)\*(C'\fR
.Sp
Then access your attributes like so (e.g. after calling
"\f(CW\*(C`$self = SUPER\->new();\*(C'\fR" in your constructor method):
.Sp
.Vb 4
\& $self->[0][ATTRIB1] = 'value1';
\& $self->[0][ATTRIB2] = 'value2';
\& $self->[0][ATTRIB3] = 'value3';
\& ...
.Ve
.Sp
Beware that if you put anything other than numbers or strings
into your attributes, the methods \*(L"\fIclone()\fR\*(R" and \*(L"\fIcopy()\fR\*(R" might
not work as expected anymore!
.Sp
Especially if your attributes contain references to other data
structures, only the references will be copied, but not the data
structures themselves.
.Sp
This may not be what you want.
.Sp
(You will have to override these two methods and write some
of your own if not.)
.Sp
In order for the overloaded operators and the \*(L"shift_*()\*(R"
auxiliary functions from the \*(L"Date::Calc::Object\*(R" package
to work properly (the latter of which are heavily used in
the \*(L"Date::Calendar[::Year]\*(R" modules, for instance), the
package name of your subclass (= the one your objects will
be blessed into) is \fB\s-1REQUIRED\s0\fR to contain a \*(L"::\*(R".
.Sp
Note that you should \fB\s-1ONLY\s0\fR subclass \*(L"Date::Calc\*(R", \fB\s-1NEVER\s0\fR
\&\*(L"Date::Calc::Object\*(R", since subclassing the latter is less
efficient (because \*(L"Date::Calc::Object\*(R" is just an empty class
which inherits from \*(L"Date::Calc\*(R" \- subclassing \*(L"Date::Calc::Object\*(R"
would thus just introduce an additional name space layer to search
during Perl's runtime method binding process).
.Sp
If you give your subclass a package name below/inside the
\&\*(L"Date::\*(R" namespace, you will also benefit from the fact that
all error messages produced by the \*(L"Date::Calc[::Object]\*(R" module
(and also the \*(L"Date::Calendar[::Year]\*(R" modules, by the way)
will appear to have originated from the place outside of all
"\f(CW\*(C`/^Date::/\*(C'\fR\*(L" modules (including yours) where one of the \*(R"Date::\*(L"
modules was first called \- i.e., all errors are always blamed
on the user, no matter how deeply nested inside the \*(R"Date::\*(L"
modules they occur, and do not usually refer to places inside
any of the \*(R"Date::\*(L" modules (this assumes that there are no
bugs in the \*(R"Date::" modules, and that all errors are always
the user's fault \f(CW\*(C`:\-)\*(C'\fR).
.Sp
Moreover, your module's own error messages will behave in the
same way if you "\f(CW\*(C`use Carp::Clan qw(^Date::);\*(C'\fR\*(L" at the top of
your module and if you produce all error messages using \*(R"\fIcarp()\fR\*(L"
and \*(R"\fIcroak()\fR\*(L" (instead of \*(R"\fIwarn()\fR\*(L" and \*(R"\fIdie()\fR", respectively).
.SH "EXAMPLES"
.IX Header "EXAMPLES"
.IP "1)" 3
.Vb 7
\& # Switch to summer time:
\& $now = Date::Calc->now();
\& if (($now ge [2000,3,26,2,0,0]) and
\& ($now lt [2000,3,26,3,0,0]))
\& {
\& $now += [0,0,0,1,0,0];
\& }
.Ve
.IP "2)" 3
.Vb 1
\& use Date::Calc::Object qw(:all);
.Ve
.Sp
.Vb 1
\& Date::Calc->date_format(3);
.Ve
.Sp
.Vb 21
\& $date = 0;
\& while (!$date)
\& {
\& print "Please enter the date of your birthday (day-month-year): ";
\& $date = Date::Calc->new( Decode_Date_EU( scalar(<STDIN>) ) );
\& if ($date)
\& {
\& $resp = 0;
\& while ($resp !~ /^\es*[YyNn]/)
\& {
\& print "Your birthday is: $date\en";
\& print "Is that correct? (yes/no) ";
\& $resp = <STDIN>;
\& }
\& $date = 0 unless ($resp =~ /^\es*[Yy]/)
\& }
\& else
\& {
\& print "Unable to parse your birthday. Please try again.\en";
\& }
\& }
.Ve
.Sp
.Vb 4
\& if ($date + [18,0,0] <= [Today()])
\& { print "Ok, you are over 18.\en"; }
\& else
\& { print "Sorry, you are under 18!\en"; }
.Ve
.PP
For more examples, see the \*(L"examples\*(R" subdirectory in this distribution,
and their descriptions in the file \*(L"\s-1EXAMPLES\s0.txt\*(R".
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIDate::Calc\fR\|(3), \fIDate::Calendar\fR\|(3),
\&\fIDate::Calendar::Year\fR\|(3), \fIDate::Calendar::Profiles\fR\|(3).
.SH "VERSION"
.IX Header "VERSION"
This man page documents \*(L"Date::Calc::Object\*(R" version 5.3.
.SH "AUTHOR"
.IX Header "AUTHOR"
.Vb 3
\& Steffen Beyer
\& mailto:sb@engelschall.com
\& http://www.engelschall.com/u/sb/download/
.Ve
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c) 2000 \- 2002 by Steffen Beyer. All rights reserved.
.SH "LICENSE"
.IX Header "LICENSE"
This package is free software; you can redistribute it and/or
modify it under the same terms as Perl itself, i.e., under the
terms of the \*(L"Artistic License\*(R" or the \*(L"\s-1GNU\s0 General Public License\*(R".
.PP
Please refer to the files \*(L"Artistic.txt\*(R" and \*(L"\s-1GNU_GPL\s0.txt\*(R"
in this distribution for details!
.SH "DISCLAIMER"
.IX Header "DISCLAIMER"
This package is distributed in the hope that it will be useful,
but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.
.PP
See the \*(L"\s-1GNU\s0 General Public License\*(R" for more details.