Dave Rolsky > DateTime-0.72 > DateTime::Duration

Download:
DateTime-0.72.tar.gz

Dependencies

Annotate this POD (5)

CPAN RT

New  8
Open  7
Stalled  5
View/Report Bugs
Module Version: 0.72   Source   Latest Release: DateTime-1.10

NAME ^

DateTime::Duration - Duration objects for date math

VERSION ^

version 0.72

SYNOPSIS ^

  use DateTime::Duration;

  $dur = DateTime::Duration->new(
      years       => 3,
      months      => 5,
      weeks       => 1,
      days        => 1,
      hours       => 6,
      minutes     => 15,
      seconds     => 45,
      nanoseconds => 12000
  );

  my ( $days, $hours, $seconds ) = $dur->in_units('days', 'hours', 'seconds');

  # Human-readable accessors, always positive, but consider using
  # DateTime::Format::Duration instead
  $dur->years;
  $dur->months;
  $dur->weeks;
  $dur->days;
  $dur->hours;
  $dur->minutes;
  $dur->seconds;
  $dur->nanoseconds;

  $dur->is_wrap_mode
  $dur->is_limit_mode
  $dur->is_preserve_mode

  print $dur->end_of_month_mode;

  # Multiply all values by -1
  my $opposite = $dur->inverse;

  my $bigger  = $dur1 + $dur2;
  my $smaller = $dur1 - $dur2; # the result could be negative
  my $bigger  = $dur1 * 3;

  my $base_dt = DateTime->new( year => 2000 );
  my @sorted =
      sort { DateTime::Duration->compare( $a, $b, $base_dt ) } @durations;

  if ( $dur->is_positive ) { ... }
  if ( $dur->is_zero )     { ... }
  if ( $dur->is_negative ) { ... }

DESCRIPTION ^

This is a simple class for representing duration objects. These objects are used whenever you do date math with DateTime.pm.

See the How Date Math is Done section of the DateTime.pm documentation for more details. The short course: One cannot in general convert between seconds, minutes, days, and months, so this class will never do so. Instead, create the duration with the desired units to begin with, for example by calling the appropriate subtraction/delta method on a DateTime.pm object.

METHODS ^

Like DateTime itself, DateTime::Duration returns the object from mutator methods in order to make method chaining possible.

DateTime::Duration has the following methods:

Overloading

This class overloads addition, subtraction, and mutiplication.

Comparison is not overloaded. If you attempt to compare durations using <=> or cmp, then an exception will be thrown! Use the compare() class method instead.

SUPPORT ^

Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.

SEE ALSO ^

datetime@perl.org mailing list

http://datetime.perl.org/

AUTHOR ^

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2012 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: