← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:57 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/DateTime/Duration.pm
StatementsExecuted 28 statements in 1.60ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11115µs19µsDateTime::Duration::::BEGIN@6DateTime::Duration::BEGIN@6
11110µs39µsDateTime::Duration::::BEGIN@12DateTime::Duration::BEGIN@12
11110µs89µsDateTime::Duration::::BEGIN@14DateTime::Duration::BEGIN@14
1119µs60µsDateTime::Duration::::BEGIN@23DateTime::Duration::BEGIN@23
1119µs25µsDateTime::Duration::::BEGIN@7DateTime::Duration::BEGIN@7
1118µs8µsDateTime::Duration::::BEGIN@10DateTime::Duration::BEGIN@10
1115µs5µsDateTime::Duration::::BEGIN@11DateTime::Duration::BEGIN@11
1113µs3µsDateTime::Duration::::BEGIN@9DateTime::Duration::BEGIN@9
0000s0sDateTime::Duration::::_add_overloadDateTime::Duration::_add_overload
0000s0sDateTime::Duration::::_compare_overloadDateTime::Duration::_compare_overload
0000s0sDateTime::Duration::::_has_negativeDateTime::Duration::_has_negative
0000s0sDateTime::Duration::::_has_positiveDateTime::Duration::_has_positive
0000s0sDateTime::Duration::::_multiply_overloadDateTime::Duration::_multiply_overload
0000s0sDateTime::Duration::::_normalize_nanosecondsDateTime::Duration::_normalize_nanoseconds
0000s0sDateTime::Duration::::_subtract_overloadDateTime::Duration::_subtract_overload
0000s0sDateTime::Duration::::addDateTime::Duration::add
0000s0sDateTime::Duration::::add_durationDateTime::Duration::add_duration
0000s0sDateTime::Duration::::calendar_durationDateTime::Duration::calendar_duration
0000s0sDateTime::Duration::::clock_durationDateTime::Duration::clock_duration
0000s0sDateTime::Duration::::cloneDateTime::Duration::clone
0000s0sDateTime::Duration::::compareDateTime::Duration::compare
0000s0sDateTime::Duration::::daysDateTime::Duration::days
0000s0sDateTime::Duration::::delta_daysDateTime::Duration::delta_days
0000s0sDateTime::Duration::::delta_minutesDateTime::Duration::delta_minutes
0000s0sDateTime::Duration::::delta_monthsDateTime::Duration::delta_months
0000s0sDateTime::Duration::::delta_nanosecondsDateTime::Duration::delta_nanoseconds
0000s0sDateTime::Duration::::delta_secondsDateTime::Duration::delta_seconds
0000s0sDateTime::Duration::::deltasDateTime::Duration::deltas
0000s0sDateTime::Duration::::end_of_month_modeDateTime::Duration::end_of_month_mode
0000s0sDateTime::Duration::::hoursDateTime::Duration::hours
0000s0sDateTime::Duration::::in_unitsDateTime::Duration::in_units
0000s0sDateTime::Duration::::inverseDateTime::Duration::inverse
0000s0sDateTime::Duration::::is_limit_modeDateTime::Duration::is_limit_mode
0000s0sDateTime::Duration::::is_negativeDateTime::Duration::is_negative
0000s0sDateTime::Duration::::is_positiveDateTime::Duration::is_positive
0000s0sDateTime::Duration::::is_preserve_modeDateTime::Duration::is_preserve_mode
0000s0sDateTime::Duration::::is_wrap_modeDateTime::Duration::is_wrap_mode
0000s0sDateTime::Duration::::is_zeroDateTime::Duration::is_zero
0000s0sDateTime::Duration::::minutesDateTime::Duration::minutes
0000s0sDateTime::Duration::::monthsDateTime::Duration::months
0000s0sDateTime::Duration::::multiplyDateTime::Duration::multiply
0000s0sDateTime::Duration::::nanosecondsDateTime::Duration::nanoseconds
0000s0sDateTime::Duration::::newDateTime::Duration::new
0000s0sDateTime::Duration::::secondsDateTime::Duration::seconds
0000s0sDateTime::Duration::::subtractDateTime::Duration::subtract
0000s0sDateTime::Duration::::subtract_durationDateTime::Duration::subtract_duration
0000s0sDateTime::Duration::::weeksDateTime::Duration::weeks
0000s0sDateTime::Duration::::yearsDateTime::Duration::years
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DateTime::Duration;
2{
321µs $DateTime::Duration::VERSION = '0.74';
4}
5
6320µs224µs
# spent 19µs (15+4) within DateTime::Duration::BEGIN@6 which was called: # once (15µs+4µs) by DateTime::BEGIN@46 at line 6
use strict;
# spent 19µs making 1 call to DateTime::Duration::BEGIN@6 # spent 4µs making 1 call to strict::import
7318µs242µs
# spent 25µs (9+16) within DateTime::Duration::BEGIN@7 which was called: # once (9µs+16µs) by DateTime::BEGIN@46 at line 7
use warnings;
# spent 25µs making 1 call to DateTime::Duration::BEGIN@7 # spent 16µs making 1 call to warnings::import
8
9315µs13µs
# spent 3µs within DateTime::Duration::BEGIN@9 which was called: # once (3µs+0s) by DateTime::BEGIN@46 at line 9
use Carp ();
# spent 3µs making 1 call to DateTime::Duration::BEGIN@9
10321µs18µs
# spent 8µs within DateTime::Duration::BEGIN@10 which was called: # once (8µs+0s) by DateTime::BEGIN@46 at line 10
use DateTime;
# spent 8µs making 1 call to DateTime::Duration::BEGIN@10
11322µs15µs
# spent 5µs within DateTime::Duration::BEGIN@11 which was called: # once (5µs+0s) by DateTime::BEGIN@46 at line 11
use DateTime::Helpers;
# spent 5µs making 1 call to DateTime::Duration::BEGIN@11
12333µs268µs
# spent 39µs (10+29) within DateTime::Duration::BEGIN@12 which was called: # once (10µs+29µs) by DateTime::BEGIN@46 at line 12
use Params::Validate qw( validate SCALAR );
# spent 39µs making 1 call to DateTime::Duration::BEGIN@12 # spent 29µs making 1 call to Exporter::import
13
14
# spent 89µs (10+79) within DateTime::Duration::BEGIN@14 which was called: # once (10µs+79µs) by DateTime::BEGIN@46 at line 21
use overload (
1517µs179µs fallback => 1,
# spent 79µs making 1 call to overload::import
16 '+' => '_add_overload',
17 '-' => '_subtract_overload',
18 '*' => '_multiply_overload',
19 '<=>' => '_compare_overload',
20 'cmp' => '_compare_overload',
21216µs189µs);
# spent 89µs making 1 call to DateTime::Duration::BEGIN@14
22
2331.44ms2110µs
# spent 60µs (9+51) within DateTime::Duration::BEGIN@23 which was called: # once (9µs+51µs) by DateTime::BEGIN@46 at line 23
use constant MAX_NANOSECONDS => 1_000_000_000; # 1E9 = almost 32 bits
# spent 60µs making 1 call to DateTime::Duration::BEGIN@23 # spent 51µs making 1 call to constant::import
24
2512µsmy @all_units = qw( months days minutes seconds nanoseconds );
26
27# XXX - need to reject non-integers but accept infinity, NaN, &
28# 1.56e+18
29sub new {
30 my $class = shift;
31 my %p = validate(
32 @_, {
33 years => { type => SCALAR, default => 0 },
34 months => { type => SCALAR, default => 0 },
35 weeks => { type => SCALAR, default => 0 },
36 days => { type => SCALAR, default => 0 },
37 hours => { type => SCALAR, default => 0 },
38 minutes => { type => SCALAR, default => 0 },
39 seconds => { type => SCALAR, default => 0 },
40 nanoseconds => { type => SCALAR, default => 0 },
41 end_of_month => {
42 type => SCALAR, default => undef,
43 regex => qr/^(?:wrap|limit|preserve)$/
44 },
45 }
46 );
47
48 my $self = bless {}, $class;
49
50 $self->{months} = ( $p{years} * 12 ) + $p{months};
51
52 $self->{days} = ( $p{weeks} * 7 ) + $p{days};
53
54 $self->{minutes} = ( $p{hours} * 60 ) + $p{minutes};
55
56 $self->{seconds} = $p{seconds};
57
58 if ( $p{nanoseconds} ) {
59 $self->{nanoseconds} = $p{nanoseconds};
60 $self->_normalize_nanoseconds;
61 }
62 else {
63
64 # shortcut - if they don't need nanoseconds
65 $self->{nanoseconds} = 0;
66 }
67
68 $self->{end_of_month} = (
69 defined $p{end_of_month} ? $p{end_of_month}
70 : $self->{months} < 0 ? 'preserve'
71 : 'wrap'
72 );
73
74 return $self;
75}
76
77# make the signs of seconds, nanos the same; 0 < abs(nanos) < MAX_NANOS
78# NB this requires nanoseconds != 0 (callers check this already)
79sub _normalize_nanoseconds {
80 my $self = shift;
81
82 return
83 if ( $self->{nanoseconds} == DateTime::INFINITY()
84 || $self->{nanoseconds} == DateTime::NEG_INFINITY()
85 || $self->{nanoseconds} eq DateTime::NAN() );
86
87 my $seconds = $self->{seconds} + $self->{nanoseconds} / MAX_NANOSECONDS;
88 $self->{seconds} = int($seconds);
89 $self->{nanoseconds} = $self->{nanoseconds} % MAX_NANOSECONDS;
90 $self->{nanoseconds} -= MAX_NANOSECONDS if $seconds < 0;
91}
92
93sub clone { bless { %{ $_[0] } }, ref $_[0] }
94
95sub years { abs( $_[0]->in_units('years') ) }
96sub months { abs( $_[0]->in_units( 'months', 'years' ) ) }
97sub weeks { abs( $_[0]->in_units('weeks') ) }
98sub days { abs( $_[0]->in_units( 'days', 'weeks' ) ) }
99sub hours { abs( $_[0]->in_units('hours') ) }
100sub minutes { abs( $_[0]->in_units( 'minutes', 'hours' ) ) }
101sub seconds { abs( $_[0]->in_units('seconds') ) }
102sub nanoseconds { abs( $_[0]->in_units( 'nanoseconds', 'seconds' ) ) }
103
104sub is_positive { $_[0]->_has_positive && !$_[0]->_has_negative }
105sub is_negative { !$_[0]->_has_positive && $_[0]->_has_negative }
106
107sub _has_positive {
108 ( grep { $_ > 0 } @{ $_[0] }{@all_units} ) ? 1 : 0;
109}
110
111sub _has_negative {
112 ( grep { $_ < 0 } @{ $_[0] }{@all_units} ) ? 1 : 0;
113}
114
115sub is_zero {
116 return 0 if grep { $_ != 0 } @{ $_[0] }{@all_units};
117 return 1;
118}
119
120sub delta_months { $_[0]->{months} }
121sub delta_days { $_[0]->{days} }
122sub delta_minutes { $_[0]->{minutes} }
123sub delta_seconds { $_[0]->{seconds} }
124sub delta_nanoseconds { $_[0]->{nanoseconds} }
125
126sub deltas {
127 map { $_ => $_[0]->{$_} } @all_units;
128}
129
130sub in_units {
131 my $self = shift;
132 my @units = @_;
133
134 my %units = map { $_ => 1 } @units;
135
136 my %ret;
137
138 my ( $months, $days, $minutes, $seconds )
139 = @{$self}{qw( months days minutes seconds )};
140
141 if ( $units{years} ) {
142 $ret{years} = int( $months / 12 );
143 $months -= $ret{years} * 12;
144 }
145
146 if ( $units{months} ) {
147 $ret{months} = $months;
148 }
149
150 if ( $units{weeks} ) {
151 $ret{weeks} = int( $days / 7 );
152 $days -= $ret{weeks} * 7;
153 }
154
155 if ( $units{days} ) {
156 $ret{days} = $days;
157 }
158
159 if ( $units{hours} ) {
160 $ret{hours} = int( $minutes / 60 );
161 $minutes -= $ret{hours} * 60;
162 }
163
164 if ( $units{minutes} ) {
165 $ret{minutes} = $minutes;
166 }
167
168 if ( $units{seconds} ) {
169 $ret{seconds} = $seconds;
170 $seconds = 0;
171 }
172
173 if ( $units{nanoseconds} ) {
174 $ret{nanoseconds} = $seconds * MAX_NANOSECONDS + $self->{nanoseconds};
175 }
176
177 wantarray ? @ret{@units} : $ret{ $units[0] };
178}
179
180sub is_wrap_mode { $_[0]->{end_of_month} eq 'wrap' ? 1 : 0 }
181sub is_limit_mode { $_[0]->{end_of_month} eq 'limit' ? 1 : 0 }
182sub is_preserve_mode { $_[0]->{end_of_month} eq 'preserve' ? 1 : 0 }
183
184sub end_of_month_mode { $_[0]->{end_of_month} }
185
186sub calendar_duration {
187 my $self = shift;
188
189 return ( ref $self )
190 ->new( map { $_ => $self->{$_} } qw( months days end_of_month ) );
191}
192
193sub clock_duration {
194 my $self = shift;
195
196 return ( ref $self )
197 ->new( map { $_ => $self->{$_} }
198 qw( minutes seconds nanoseconds end_of_month ) );
199}
200
201sub inverse {
202 my $self = shift;
203 my %p = @_;
204
205 my %new;
206 foreach my $u (@all_units) {
207 $new{$u} = $self->{$u};
208
209 # avoid -0 bug
210 $new{$u} *= -1 if $new{$u};
211 }
212
213 $new{end_of_month} = $p{end_of_month}
214 if exists $p{end_of_month};
215
216 return ( ref $self )->new(%new);
217}
218
219sub add_duration {
220 my ( $self, $dur ) = @_;
221
222 foreach my $u (@all_units) {
223 $self->{$u} += $dur->{$u};
224 }
225
226 $self->_normalize_nanoseconds if $self->{nanoseconds};
227
228 return $self;
229}
230
231sub add {
232 my $self = shift;
233
234 return $self->add_duration( ( ref $self )->new(@_) );
235}
236
237sub subtract_duration { return $_[0]->add_duration( $_[1]->inverse ) }
238
239sub subtract {
240 my $self = shift;
241
242 return $self->subtract_duration( ( ref $self )->new(@_) );
243}
244
245sub multiply {
246 my $self = shift;
247 my $multiplier = shift;
248
249 foreach my $u (@all_units) {
250 $self->{$u} *= $multiplier;
251 }
252
253 $self->_normalize_nanoseconds if $self->{nanoseconds};
254
255 return $self;
256}
257
258sub compare {
259 my ( $class, $dur1, $dur2, $dt ) = @_;
260
261 $dt ||= DateTime->now;
262
263 return DateTime->compare( $dt->clone->add_duration($dur1),
264 $dt->clone->add_duration($dur2) );
265}
266
267sub _add_overload {
268 my ( $d1, $d2, $rev ) = @_;
269
270 ( $d1, $d2 ) = ( $d2, $d1 ) if $rev;
271
272 if ( DateTime::Helpers::isa( $d2, 'DateTime' ) ) {
273 $d2->add_duration($d1);
274 return;
275 }
276
277 # will also work if $d1 is a DateTime.pm object
278 return $d1->clone->add_duration($d2);
279}
280
281sub _subtract_overload {
282 my ( $d1, $d2, $rev ) = @_;
283
284 ( $d1, $d2 ) = ( $d2, $d1 ) if $rev;
285
286 Carp::croak(
287 "Cannot subtract a DateTime object from a DateTime::Duration object")
288 if DateTime::Helpers::isa( $d2, 'DateTime' );
289
290 return $d1->clone->subtract_duration($d2);
291}
292
293sub _multiply_overload {
294 my $self = shift;
295
296 my $new = $self->clone;
297
298 return $new->multiply(@_);
299}
300
301sub _compare_overload {
302 Carp::croak( 'DateTime::Duration does not overload comparison.'
303 . ' See the documentation on the compare() method for details.'
304 );
305}
306
30714µs1;
308
309# ABSTRACT: Duration objects for date math
310
- -
313=pod
314
315=head1 NAME
316
317DateTime::Duration - Duration objects for date math
318
319=head1 VERSION
320
321version 0.74
322
323=head1 SYNOPSIS
324
325 use DateTime::Duration;
326
327 $dur = DateTime::Duration->new(
328 years => 3,
329 months => 5,
330 weeks => 1,
331 days => 1,
332 hours => 6,
333 minutes => 15,
334 seconds => 45,
335 nanoseconds => 12000
336 );
337
338 my ( $days, $hours, $seconds ) = $dur->in_units('days', 'hours', 'seconds');
339
340 # Human-readable accessors, always positive, but consider using
341 # DateTime::Format::Duration instead
342 $dur->years;
343 $dur->months;
344 $dur->weeks;
345 $dur->days;
346 $dur->hours;
347 $dur->minutes;
348 $dur->seconds;
349 $dur->nanoseconds;
350
351 $dur->is_wrap_mode
352 $dur->is_limit_mode
353 $dur->is_preserve_mode
354
355 print $dur->end_of_month_mode;
356
357 # Multiply all values by -1
358 my $opposite = $dur->inverse;
359
360 my $bigger = $dur1 + $dur2;
361 my $smaller = $dur1 - $dur2; # the result could be negative
362 my $bigger = $dur1 * 3;
363
364 my $base_dt = DateTime->new( year => 2000 );
365 my @sorted =
366 sort { DateTime::Duration->compare( $a, $b, $base_dt ) } @durations;
367
368 if ( $dur->is_positive ) { ... }
369 if ( $dur->is_zero ) { ... }
370 if ( $dur->is_negative ) { ... }
371
372=head1 DESCRIPTION
373
374This is a simple class for representing duration objects. These
375objects are used whenever you do date math with DateTime.pm.
376
377See the L<How Date Math is Done|DateTime/"How Date Math is Done">
378section of the DateTime.pm documentation for more details. The short
379course: One cannot in general convert between seconds, minutes, days,
380and months, so this class will never do so. Instead, create the
381duration with the desired units to begin with, for example by calling
382the appropriate subtraction/delta method on a C<DateTime.pm> object.
383
384=head1 METHODS
385
386Like C<DateTime> itself, C<DateTime::Duration> returns the object from
387mutator methods in order to make method chaining possible.
388
389C<DateTime::Duration> has the following methods:
390
391=over 4
392
393=item * new( ... )
394
395This method takes the parameters "years", "months", "weeks", "days",
396"hours", "minutes", "seconds", "nanoseconds", and "end_of_month". All
397of these except "end_of_month" are numbers. If any of the numbers are
398negative, the entire duration is negative.
399
400All of the numbers B<must be integers>.
401
402Internally, years as just treated as 12 months. Similarly, weeks are
403treated as 7 days, and hours are converted to minutes. Seconds and
404nanoseconds are both treated separately.
405
406The "end_of_month" parameter must be either "wrap", "limit", or
407"preserve". This parameter specifies how date math that crosses the
408end of a month is handled.
409
410In "wrap" mode, adding months or years that result in days beyond the
411end of the new month will roll over into the following month. For
412instance, adding one year to Feb 29 will result in Mar 1.
413
414If you specify "end_of_month" mode as "limit", the end of the month is
415never crossed. Thus, adding one year to Feb 29, 2000 will result in
416Feb 28, 2001. If you were to then add three more years this will
417result in Feb 28, 2004.
418
419If you specify "end_of_month" mode as "preserve", the same calculation
420is done as for "limit" except that if the original date is at the end
421of the month the new date will also be. For instance, adding one
422month to Feb 29, 2000 will result in Mar 31, 2000.
423
424For positive durations, the "end_of_month" parameter defaults to wrap.
425For negative durations, the default is "limit". This should match how
426most people "intuitively" expect datetime math to work.
427
428=item * clone
429
430Returns a new object with the same properties as the object on which
431this method was called.
432
433=item * in_units( ... )
434
435Returns the length of the duration in the units (any of those that can
436be passed to C<new>) given as arguments. All lengths are integral,
437but may be negative. Smaller units are computed from what remains
438after taking away the larger units given, so for example:
439
440 my $dur = DateTime::Duration->new( years => 1, months => 15 );
441
442 $dur->in_units( 'years' ); # 2
443 $dur->in_units( 'months' ); # 27
444 $dur->in_units( 'years', 'months' ); # (2, 3)
445 $dur->in_units( 'weeks', 'days' ); # (0, 0) !
446
447The last example demonstrates that there will not be any conversion
448between units which don't have a fixed conversion rate. The only
449conversions possible are:
450
451=over 8
452
453=item * years <=> months
454
455=item * weeks <=> days
456
457=item * hours <=> minutes
458
459=item * seconds <=> nanoseconds
460
461=back
462
463For the explanation of why this is the case, please see the L<How Datetime
464Math Works|DateTime/"How DateTime Math Works"> section of the DateTime.pm
465documentation
466
467Note that the numbers returned by this method may not match the values
468given to the constructor.
469
470In list context, in_units returns the lengths in the order of the units
471given. In scalar context, it returns the length in the first unit (but
472still computes in terms of all given units).
473
474If you need more flexibility in presenting information about
475durations, please take a look a C<DateTime::Format::Duration>.
476
477=item * is_positive, is_zero, is_negative
478
479Indicates whether or not the duration is positive, zero, or negative.
480
481If the duration contains both positive and negative units, then it
482will return false for B<all> of these methods.
483
484=item * is_wrap_mode, is_limit_mode, is_preserve_mode
485
486Indicates what mode is used for end of month wrapping.
487
488=item * end_of_month_mode
489
490Returns one of "wrap", "limit", or "preserve".
491
492=item * calendar_duration
493
494Returns a new object with the same I<calendar> delta (months and days
495only) and end of month mode as the current object.
496
497=item * clock_duration
498
499Returns a new object with the same I<clock> deltas (minutes, seconds,
500and nanoseconds) and end of month mode as the current object.
501
502=item * inverse( ... )
503
504Returns a new object with the same deltas as the current object, but
505multiple by -1. The end of month mode for the new object will be the
506default end of month mode, which depends on whether the new duration
507is positive or negative.
508
509You can set the end of month mode in the inverted duration explicitly by
510passing "end_of_month => ..." to the C<inverse()> method.
511
512=item * add_duration( $duration_object ), subtract_duration( $duration_object )
513
514Adds or subtracts one duration from another.
515
516=item * add( ... ), subtract( ... )
517
518Syntactic sugar for addition and subtraction. The parameters given to
519these methods are used to create a new object, which is then passed to
520C<add_duration()> or C<subtract_duration()>, as appropriate.
521
522=item * multiply( $number )
523
524Multiplies each unit in the by the specified number.
525
526=item * DateTime::Duration->compare( $duration1, $duration2, $base_datetime )
527
528This is a class method that can be used to compare or sort durations.
529Comparison is done by adding each duration to the specified
530C<DateTime.pm> object and comparing the resulting datetimes. This is
531necessary because without a base, many durations are not comparable.
532For example, 1 month may or may not be longer than 29 days, depending
533on what datetime it is added to.
534
535If no base datetime is given, then the result of C<< DateTime->now >>
536is used instead. Using this default will give non-repeatable results
537if used to compare two duration objects containing different units.
538It will also give non-repeatable results if the durations contain
539multiple types of units, such as months and days.
540
541However, if you know that both objects only consist of one type of
542unit (months I<or> days I<or> hours, etc.), and each duration contains
543the same type of unit, then the results of the comparison will be
544repeatable.
545
546=item * delta_months, delta_days, delta_minutes, delta_seconds, delta_nanoseconds
547
548These methods provide the information C<DateTime.pm> needs for doing date
549math. The numbers returned may be positive or negative. This is mostly useful
550for doing date math in L<DateTime>.
551
552=item * deltas
553
554Returns a hash with the keys "months", "days", "minutes", "seconds", and
555"nanoseconds", containing all the delta information for the object. This is
556mostly useful for doing date math in L<DateTime>.
557
558=item * years, months, weeks, days, hours, minutes, seconds, nanoseconds
559
560These methods return numbers indicating how many of the given unit the
561object represents, after having done a conversion to any larger units.
562For example, days are first converted to weeks, and then the remainder
563is returned. These numbers are always positive.
564
565Here's what each method returns:
566
567 $dur->years() == abs( $dur->in_units('years') )
568 $dur->months() == abs( ( $dur->in_units( 'months', 'years' ) )[0] )
569 $dur->weeks() == abs( $dur->in_units( 'weeks' ) )
570 $dur->days() == abs( ( $dur->in_units( 'days', 'weeks' ) )[0] )
571 $dur->hours() == abs( $dur->in_units( 'hours' ) )
572 $dur->minutes == abs( ( $dur->in_units( 'minutes', 'hours' ) )[0] )
573 $dur->seconds == abs( $dur->in_units( 'seconds' ) )
574 $dur->nanoseconds() == abs( ( $dur->in_units( 'nanoseconds', 'seconds' ) )[0] )
575
576If this seems confusing, remember that you can always use the
577C<in_units()> method to specify exactly what you want.
578
579Better yet, if you are trying to generate output suitable for humans,
580use the C<DateTime::Format::Duration> module.
581
582=back
583
584=head2 Overloading
585
586This class overloads addition, subtraction, and mutiplication.
587
588Comparison is B<not> overloaded. If you attempt to compare durations
589using C<< <=> >> or C<cmp>, then an exception will be thrown! Use the
590C<compare()> class method instead.
591
592=head1 SUPPORT
593
594Support for this module is provided via the datetime@perl.org email
595list. See http://lists.perl.org/ for more details.
596
597=head1 SEE ALSO
598
599datetime@perl.org mailing list
600
601http://datetime.perl.org/
602
603=head1 AUTHOR
604
605Dave Rolsky <autarch@urth.org>
606
607=head1 COPYRIGHT AND LICENSE
608
609This software is Copyright (c) 2012 by Dave Rolsky.
610
611This is free software, licensed under:
612
613 The Artistic License 2.0 (GPL Compatible)
614
615=cut
616
617
618__END__