|
Packit |
95306a |
# Copyright (c) 2008-2017 Sullivan Beck. All rights reserved.
|
|
Packit |
95306a |
# This program is free software; you can redistribute it and/or modify it
|
|
Packit |
95306a |
# under the same terms as Perl itself.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=pod
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 NAME
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Date::Manip::Obj - Base class for Date::Manip objects
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 SYNOPSIS
|
|
Packit |
95306a |
|
|
Packit |
95306a |
The Date::Manip::Obj class is the base class used for the following
|
|
Packit |
95306a |
Date::Manip classes:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=over 4
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item L<Date::Manip::Base>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item L<Date::Manip::TZ>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item L<Date::Manip::Date>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item L<Date::Manip::Delta>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item L<Date::Manip::Recur>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=back
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This module is not intended to be called directly and performs no
|
|
Packit |
95306a |
useful function by itself. Instead, use the various derived classes
|
|
Packit |
95306a |
which inherit from it.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 DESCRIPTION
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This module contains a set of methods used by all Date::Manip classes
|
|
Packit |
95306a |
listed above.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
You should be familiar with the L<Date::Manip::Objects> and
|
|
Packit |
95306a |
L<Date::Manip::Config> documentation.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
In the method descriptions below, L<Date::Manip::Date> objects will
|
|
Packit |
95306a |
usually be used as examples, but (unless otherwise stated), all of the
|
|
Packit |
95306a |
classes listed above have the same methods, and work in the same
|
|
Packit |
95306a |
fashion.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 METHODS FOR CREATING OBJECTS
|
|
Packit |
95306a |
|
|
Packit |
95306a |
In the examples below, any C<$date> (C<$date>, C<$date1>, C<$date2>, ...) variable
|
|
Packit |
95306a |
is a L<Date::Manip::Date> object. Similarly, C<$delta>, C<$recur>, C<$tz>, and
|
|
Packit |
95306a |
C<$base> refer to objects in the appropriate class.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Any C<$obj> variable refers to an object in any of the classes.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=over 4
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<new>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
There are two ways to use the new method. They are:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$obj2 = new CLASS ($obj1,$string,[@parse_opts,]\@opts);
|
|
Packit |
95306a |
$obj2 = $obj1->new($string,[@parse_opts,]\@opts)
|
|
Packit |
95306a |
|
|
Packit |
95306a |
In both cases, all arguments are optional.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Here, CLASS is the class of the new object. For example:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date;
|
|
Packit |
95306a |
$delta = new Date::Manip::Delta;
|
|
Packit |
95306a |
|
|
Packit |
95306a |
if C<$obj1> is available, the new object will share as much information
|
|
Packit |
95306a |
from the old object as possible. The class of the new object may
|
|
Packit |
95306a |
be derived from the old object as well.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
For example, if you call either of these:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date2 = new Date::Manip::Date $date1;
|
|
Packit |
95306a |
$date2 = $date1->new();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
the new date object will use the same embedded L<Date::Manip::TZ> object. In
|
|
Packit |
95306a |
the second case, the class of the new object (C<$date2>) is L<Date::Manip::Date>
|
|
Packit |
95306a |
because that is the class of the original object.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
When specifying CLASS and including an old object, objects do not need to
|
|
Packit |
95306a |
be of the same class. For example, the following are all valid:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date $delta;
|
|
Packit |
95306a |
$date = new Date::Manip::Date $tz;
|
|
Packit |
95306a |
|
|
Packit |
95306a |
You can even do:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date $base;
|
|
Packit |
95306a |
|
|
Packit |
95306a |
but this will have to create a completely new L<Date::Manip::TZ> object,
|
|
Packit |
95306a |
which means that optimal performance may not be achieved if a
|
|
Packit |
95306a |
L<Date::Manip::TZ> object already exists.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
There are two special cases. Either of the following will create
|
|
Packit |
95306a |
a new L<Date::Manip::Base> object for handling multiple configurations:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base2 = new Date::Manip::Base $base1;
|
|
Packit |
95306a |
$base2 = $base1->new();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Either of the following will create a new L<Date::Manip::TZ> object with
|
|
Packit |
95306a |
the same L<Date::Manip::Base> object embedded in it:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$tz2 = new Date::Manip::TZ $tz1;
|
|
Packit |
95306a |
$tz2 = $tz1->new();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
The new base object will initially have the same configuration as the
|
|
Packit |
95306a |
original base object, but changing it's configuration will not
|
|
Packit |
95306a |
affect the original base object.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
If the C<\@opts> argument is passed in, it is a list reference containing
|
|
Packit |
95306a |
a list suitable for passing to the B<config> method (described below). In
|
|
Packit |
95306a |
this case, a new L<Date::Manip::Base> object (and perhaps L<Date::Manip::TZ>
|
|
Packit |
95306a |
object) will be created. The new Base object will start as identical
|
|
Packit |
95306a |
to the original one (if a previously defined object was used to create
|
|
Packit |
95306a |
the new object) with the additional options in C<@opts> added.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
In other words, the following are equivalent:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date $obj,\@opts;
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base = $obj->base();
|
|
Packit |
95306a |
$base2 = $base->new();
|
|
Packit |
95306a |
$date = new Date::Manip::Date $base2;
|
|
Packit |
95306a |
$date->config(@opts);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
It should be noted that the options are applied to the NEW object,
|
|
Packit |
95306a |
not the old one. That only matters in one situation:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base2 = new Date::Manip::Base $base1,\@opts;
|
|
Packit |
95306a |
$base2 = $base1->new(\@opts);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
An optional string (C<$string>) may be passed in only when creating
|
|
Packit |
95306a |
a L<Date::Manip::Date>, L<Date::Manip::Delta>, or L<Date::Manip::Recur> object.
|
|
Packit |
95306a |
If it is passed in when creating a L<Date::Manip::TZ> or L<Date::Manip::Base>
|
|
Packit |
95306a |
object, a warning will be issued, but execution will continue.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
If the string is included, it will be parsed to give an initial value
|
|
Packit |
95306a |
to the object. This will only be done AFTER any options are handled,
|
|
Packit |
95306a |
so the following are equivalent:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date $string,@parse_opts,\@opts;
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = new Date::Manip::Date;
|
|
Packit |
95306a |
$date->config(@opts);
|
|
Packit |
95306a |
$date->parse($string,@parse_opts);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Once a L<Date::Manip::Date> object (or any object in any other
|
|
Packit |
95306a |
Date::Manip class) is created, it should always be used to create
|
|
Packit |
95306a |
additional objects in order to preserve cached data for optimal
|
|
Packit |
95306a |
performance and memory usage.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
The one caveat is if you are working with multiple configurations
|
|
Packit |
95306a |
as described in the L<Date::Manip::Objects> document. In that case,
|
|
Packit |
95306a |
you may need to create completely new objects to allow multiple
|
|
Packit |
95306a |
L<Date::Manip::Base> objects to be used.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<new_config>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$obj2 = $obj1->new_config($string,\@opts);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This creates a new instance with a new L<Date::Manip::Base> object (and possibly
|
|
Packit |
95306a |
a new L<Date::Manip::TZ> object).
|
|
Packit |
95306a |
|
|
Packit |
95306a |
For example,
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date2 = $date1->new_config();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
creates a new L<Date::Manip::Date> object with a new L<Date::Manip::TZ> (and
|
|
Packit |
95306a |
L<Date::Manip::Base>) object. Initially, it is the same configuration as
|
|
Packit |
95306a |
the original object.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
If the object is a L<Date::Manip::Base> object, the following are equivalent:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base2 = $base1->new_config();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base2 = $base1->new();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Both C<$string> and C<\@opts> are optional. They are used in the same way they
|
|
Packit |
95306a |
are used in the new method.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<new_date>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<new_delta>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<new_recur>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
These are shortcuts for specifying the class. The following sets of
|
|
Packit |
95306a |
calls are all equivalent:
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$date = $obj->new_date();
|
|
Packit |
95306a |
$date = new Date::Manip::Date($obj);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$delta = $obj->new_delta();
|
|
Packit |
95306a |
$delta = new Date::Manip::Date($obj);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
These methods all allow optional C<($string,\@opts)> arguments.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=back
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 OTHER METHODS
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=over 4
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<base>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<tz>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$base = $obj->base();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This returns the L<Date::Manip::Base> object associated with the
|
|
Packit |
95306a |
given object.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
If C<$obj> is a L<Date::Manip::Base> object, nothing is returned (i.e. it doesn't
|
|
Packit |
95306a |
create a new copy of the object).
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$tz = $obj->tz();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This returns the L<Date::Manip::TZ> object associated with the
|
|
Packit |
95306a |
given object. If C<$obj> is a L<Date::Manip::TZ> or L<Date::Manip::Base> object,
|
|
Packit |
95306a |
nothing is returned.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<config>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$obj->config($var1,$val1,$var2,$val2,...);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This will set the value of any configuration variables. Please refer to the
|
|
Packit |
95306a |
L<Date::Manip::Config> manual for a list of all configuration variables and their
|
|
Packit |
95306a |
description.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<get_config>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
@var = $obj->get_config();
|
|
Packit |
95306a |
$val = $obj->get_config($var1);
|
|
Packit |
95306a |
@val = $obj->get_config($var1,$var2,...);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This queries the current config values. With no argument, it will return
|
|
Packit |
95306a |
the list of config variables (all lowercase).
|
|
Packit |
95306a |
|
|
Packit |
95306a |
With one or more arguments, it returns the current values for the config
|
|
Packit |
95306a |
variables passed in (case insensitive).
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<err>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$err = $obj->err();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This will return the full error message if the previous operation failed
|
|
Packit |
95306a |
for any reason.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$obj->err(1);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
will clear the error code.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<is_date>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<is_delta>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<is_recur>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$flag = $obj->is_date();
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Returns 0 or 1, depending on the object. For example, a L<Date::Manip::Date>
|
|
Packit |
95306a |
object returns 1 with the is_date method, and 0 for the other two.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=item B<version>
|
|
Packit |
95306a |
|
|
Packit |
95306a |
$vers = $obj->version($flag);
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This returns the version of Date::Manip.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
If C<$flag> is passed in, and C<$obj> is not a L<Date::Manip::Base> object, the
|
|
Packit |
95306a |
version and timezone information will be passed back.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=back
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 KNOWN BUGS
|
|
Packit |
95306a |
|
|
Packit |
95306a |
None known.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 BUGS AND QUESTIONS
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Please refer to the L<Date::Manip::Problems> documentation for
|
|
Packit |
95306a |
information on submitting bug reports or questions to the author.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 SEE ALSO
|
|
Packit |
95306a |
|
|
Packit |
95306a |
L<Date::Manip> - main module documentation
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 LICENSE
|
|
Packit |
95306a |
|
|
Packit |
95306a |
This script is free software; you can redistribute it and/or
|
|
Packit |
95306a |
modify it under the same terms as Perl itself.
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=head1 AUTHOR
|
|
Packit |
95306a |
|
|
Packit |
95306a |
Sullivan Beck (sbeck@cpan.org)
|
|
Packit |
95306a |
|
|
Packit |
95306a |
=cut
|