|o||years <=> months|
|o||weeks <=> days|
|o||hours <=> minutes|
|o||seconds <=> nanoseconds|
Note that the numbers returned by this method may not match the values given to the constructor.
In list context, in_units returns the lengths in the order of the units given. In scalar context, it returns the length in the first unit (but still computes in terms of all given units).
If you need more flexibility in presenting information about
durations, please take a look a DateTime::Format::Duration.
CW$dur->is_positive(), CW$dur->is_zero(), CW$dur->is_negative()
Indicates whether or not the duration is positive, zero, or negative.
If the duration contains both positive and negative units, then it
will return false for <B>allB> of these methods.
CW$dur->is_wrap_mode(), CW$dur->is_limit_mode(), CW$dur->is_preserve_mode()
Indicates what mode is used for end of month wrapping.
Returns one of wrap, limit, or preserve.
Returns a new object with the same calendar delta (months and days
only) and end of month mode as the current object.
Returns a new object with the same clock deltas (minutes, seconds,
and nanoseconds) and end of month mode as the current object.
CW$dur->inverse( ... )
Returns a new object with the same deltas as the current object, but
multiple by -1. The end of month mode for the new object will be the
default end of month mode, which depends on whether the new duration
is positive or negative.
You can set the end of month mode in the inverted duration explicitly by
passing end_of_month => ... to the inverse() method.
CW$dur->add_duration( CW$duration_object ), CW$dur->subtract_duration( CW$duration_object )
Adds or subtracts one duration from another.
CW$dur->add( ... ), CW$dur->subtract( ... )
Syntactic sugar for addition and subtraction. The parameters given to
these methods are used to create a new object, which is then passed to
add_duration() or subtract_duration(), as appropriate.
CW$dur->multiply( CW$number )
Multiplies each unit in the by the specified number.
DateTime::Duration->compare( CW$duration1, CW$duration2, CW$base_datetime )
This is a class method that can be used to compare or sort durations.
Comparison is done by adding each duration to the specified
DateTime.pm object and comparing the resulting datetimes. This is
necessary because without a base, many durations are not comparable.
For example, 1 month may or may not be longer than 29 days, depending
on what datetime it is added to.
If no base datetime is given, then the result of DateTime->now is used instead. Using this default will give non-repeatable results if used to compare two duration objects containing different units. It will also give non-repeatable results if the durations contain multiple types of units, such as months and days.
However, if you know that both objects only consist of one type of
unit (months or days or hours, etc.), and each duration contains
the same type of unit, then the results of the comparison will be
CW$dur->delta_months(), CW$dur->delta_days(), CW$dur->delta_minutes(), CW$dur->delta_seconds(), CW$dur->delta_nanoseconds()
These methods provide the information DateTime.pm needs for doing date
math. The numbers returned may be positive or negative. This is mostly useful
for doing date math in DateTime.
Returns a hash with the keys months, days, minutes, seconds, and
nanoseconds, containing all the delta information for the object. This is
mostly useful for doing date math in DateTime.
CW$dur->years(), CW$dur->months(), CW$dur->weeks(), CW$dur->days(), CW$dur->hours(), CW$dur->minutes(), CW$dur->seconds(), CW$dur->nanoseconds()
These methods return numbers indicating how many of the given unit the
object represents, after having done a conversion to any larger units.
For example, days are first converted to weeks, and then the remainder
is returned. These numbers are always positive.
Heres what each method returns:
$dur->years() == abs( $dur->in_units(years) )
$dur->months() == abs( ( $dur->in_units( months, years ) ) )
$dur->weeks() == abs( $dur->in_units( weeks ) )
$dur->days() == abs( ( $dur->in_units( days, weeks ) ) )
$dur->hours() == abs( $dur->in_units( hours ) )
$dur->minutes == abs( ( $dur->in_units( minutes, hours ) ) )
$dur->seconds == abs( $dur->in_units( seconds ) )
$dur->nanoseconds() == abs( ( $dur->in_units( nanoseconds, seconds ) ) )
If this seems confusing, remember that you can always use the in_units() method to specify exactly what you want.
This class overloads addition, subtraction, and mutiplication.
firstname.lastname@example.org mailing list
Support for this module is provided via the email@example.com email list. See http://lists.perl.org/ for more details.
There is a mailing list available for users of this distribution, <mailto:firstname.lastname@example.org>.
I am also usually active on IRC as drolsky on irc://irc.perl.org.
Dave Rolsky <email@example.com>
This software is Copyright (c) 2016 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
|perl v5.20.3||DATETIME::DURATION (3)||2016-03-21|