> Ah, I see.  This should be subtract_datetime.  The subtract method expects
> a hash of parameters which can be passed to DateTime::Duration->new.

Note that the '-', '+', and comparison operators have been overloaded
(thanks, D.R.! :) to figure out the appropriate methods for themselves:

  blackhatdave.288> cat ./doit
  #!/usr/bin/perl

  use strict;
  use warnings;

  use DateTime;
  use DateTime::Duration;
  use DateTime::Format::Duration;


  my $date1 = DateTime->now();
  my $date2 = DateTime->now();
  my $dur1  = DateTime::Duration->new(days => int(rand(500)));


  # Date minus date
  my $obj1 = $date2 - $date1;
  print "DateTime - DateTime = ", ref($obj1), "\n";

  # Date minus duration
  my $obj2 = $date2 - $dur1;
  print "DateTime - DateTime::Duration = ", ref($obj2), "\n";

  blackhatdave.289> ./doit
  DateTime - DateTime = DateTime::Duration
  DateTime - DateTime::Duration = DateTime


                                        -=< Dave >=-



Original message follows:
-------------------------
> Date:  Thu, 17 Jun 2004 11:12:30 -0500 (CDT)
> From:  Dave Rolsky <[EMAIL PROTECTED]>
> Subject:  Re: days in DateTime::Duration

> On Thu, 17 Jun 2004, Delian Krustev wrote:
> 
> > On Thursday 17 June 2004 14:15, Rick Measham wrote:
> > > use DateTime::Format::Duration;
> > >
> > > (See the docs for more information. IIRC there's a format key in there fo
 > r
> > > 'as days')
> >
> > Thanks,
> >
> > use warnings;
> > use strict;
> >
> > use DateTime;
> > use DateTime::Format::Duration;
> >
> > my $d = DateTime::Format::Duration->new(pattern => "\%d \%e \%j");
> > my $d1 = DateTime->now();
> > my $d2 = DateTime->now();
> > $d2->add(months=>2);
> > my $dur = $d2->subtract($d1);
> 
> Ah, I see.  This should be subtract_datetime.  The subtract method expects
> a hash of parameters which can be passed to DateTime::Duration->new.
> 
> 
> -dave
> 
> /*=======================
> House Absolute Consulting
> www.houseabsolute.com
> =======================*/
> 

Reply via email to