Re: How many days between 2 DTs?

2004-12-30 Thread Dave Rolsky
On Wed, 29 Dec 2004, Max Campos wrote:
Well, here we go again with DateTime::Duration.
Here's a simple problem - How many days are between two DateTime's ?  Here is 
my attempt, but it fails.

Suggestions?
You want the delta_days() method.
-dave
/*===
VegGuide.Org
Your guide to all that's veg.
===*/


Re: How many days between 2 DTs?

2004-12-30 Thread Max Campos
Hi Dave,
	After feedback from another poster, it looks like the answer is the 
following:

$now->delta_days($dt)->in_units('days');
It looks like durations end up broken up into 4 partitions.  
Conversions can happen only within the partitions, not between:

years/months
weeks/days
hours/minutes
seconds/ns
Also, maybe DateTime should throw some kind of error when you run 
in_units and a higher partition is being stripped off?

Ex:
my $dur = DateTime::Duration->new(months => 3, days=> 4);
$dur->in_units(days);  # Error; currently 4
$dur->in_units(years); # No error, 0.
Finally, I think some explanation should be added to  
DT:Duration::in_units that explains all of this!

- Max
Well, here we go again with DateTime::Duration.
Here's a simple problem - How many days are between two DateTime's ?  
Here is my attempt, but it fails.

Suggestions?
You want the delta_days() method.



Re: How many days between 2 DTs?

2004-12-30 Thread Dave Rolsky
On Thu, 30 Dec 2004, Max Campos wrote:
	After feedback from another poster, it looks like the answer is the 
following:

$now->delta_days($dt)->in_units('days');
It looks like durations end up broken up into 4 partitions.  Conversions can 
happen only within the partitions, not between:

years/months
weeks/days
hours/minutes
seconds/ns
Yes, _I_ know all this ;)  I wrote it.
Also, maybe DateTime should throw some kind of error when you run in_units 
and a higher partition is being stripped off?

Ex:
my $dur = DateTime::Duration->new(months => 3, days=> 4);
$dur->in_units(days);  # Error; currently 4
$dur->in_units(years); # No error, 0.
It's not an error, and warnings for this sort of stuff will just annoy 
people.

Finally, I think some explanation should be added to  DT:Duration::in_units 
that explains all of this!
I'll add it.  The conversion issues are explained in DateTime.pm at length 
and mentioned in the DESCRIPTION section of DT::Duration, but not in the 
in_units method.

-dave
/*===
VegGuide.Org
Your guide to all that's veg.
===*/