Re: Subtraction Broken?

2003-08-17 Thread Matthew McGillis
 > Perhaps I'm just approaching this all wrong. I'm just looking for a
 simple way to compute some ones age today.
What you want is to normalize the values of a duration relative to 
some fixed point in time.  I agree this is something that we need to 
do.  Patches are welcome. :)
So if I read this correctly the answer is at this time what I'm after 
is not possible with DateTime directly. But, what I request is 
something you all desire and hope to have working when someone has 
the time. I actually wouldn't mind taking a look to see if I could 
contribute but at this point if:

1968-06-28
2003-08-17
Years:0
Months:0
Days:2
Delta Months:0
Delta Days:12833
is viewed as correct in representing the duration between those two 
dates I feel I'm missing a little to much to grasp some of the basics 
to contribute. I really don't see what the years months days methods 
are all about and if the delta's are simply just supposed to all add 
up to the duration then I can make since of the Delta's but it seems 
like I should have some methods representing the deltas in other 
forms that would also include years. Do you have some other design 
specs for the DateTime::Duration module that might help me to 
understand the above output better.

However if on the other hand some part of the output above although 
perhaps correct not exactly what is intended or just stubs for what 
is desired then if I new what was intended/desired I probably could 
take a look and see if the effort to produce what I desire from 
DateTime is worth it. If years really should produce 35 and simply 
isn't because that method is a stub I would be happy to see what I 
can produce.


Re: Subtraction Broken?

2003-08-17 Thread Matthew McGillis
Try:

print $age->deltas, "\n";

If the output from that doesn't look right to you please send it on 
to the list.
Code (DateTime is the current version available from CPAN):

#!/usr/bin/perl

use DateTime;

$birth=DateTime->new(year=>1968,month=>6,day=>28);
print $birth->ymd."\n";
$today=DateTime->today;
print $today->ymd."\n";
$age=$today-$birth;
print "Years:".$age->years."\n";
print "Months:".$age->months."\n";
print "Days:".$age->days."\n";
print "Deltas:".$age->deltas."\n";
print "Delta Months:".$age->delta_months."\n";
print "Delta Days:".$age->delta_days."\n";
Output:

1968-06-28
2003-08-17
Years:0
Months:0
Days:2
Deltas:10
Delta Months:0
Delta Days:12833
Again I fail to see the logic or even value in the DateTime::Duration 
behaving as above. But, I'm sure I'm probably just missing something 
important. The only one that does makes since is Deltas but only 
because it is returning a hash that has 10 elements in it. The Delta 
Days is sort of interesting but its seems like a lot of work for me 
to figure out the number of years from that especially when I think 
the point of this is to take into account all the strange ness that 
goes on between missing days seconds etc that go on over time.

Perhaps I'm just approaching this all wrong. I'm just looking for a 
simple way to compute some ones age today.


Re: Subtraction Broken?

2003-08-17 Thread Joshua Hoblitt
> Again I fail to see the logic or even value in the DateTime::Duration
> behaving as above. But, I'm sure I'm probably just missing something
> important.

Durations are independent of dates and times.

> The only one that does makes since is Deltas but only
> because it is returning a hash that has 10 elements in it. The Delta

If you would have used my example it would have printed all the hash keys and values.  
Your use of the concatenation operator forced scalar context so you ended up with the 
'10'.

> Days is sort of interesting but its seems like a lot of work for me
> to figure out the number of years from that especially when I think
> the point of this is to take into account all the strange ness that
> goes on between missing days seconds etc that go on over time.

Years relative to what?  Years are _not_ all the same length.  Nor are months, days, 
hours, or even minutes.  This is what makes this such a complicated problem.  I [we] 
understand your confusion but DT::Duration is correct.

> Perhaps I'm just approaching this all wrong. I'm just looking for a
> simple way to compute some ones age today.

What you want is to normalize the values of a duration relative to some fixed point in 
time.  I agree this is something that we need to do.  Patches are welcome. :)

-J

--


Re: DateTime::Set - Number of elements in set

2003-08-17 Thread Rick Measham
On Mon, 2003-08-18 at 02:37, [EMAIL PROTECTED] wrote:
> > Flavio, is there already a method to determine
> > the number of elements in a DateTime::Set? 
> > 
> > If not, I can currently make it as_list, and then
> > get the length of the list, but it would be 
> > cleaner to have a method to do this.
> 
> What would be a name for this method?

$set->length (sound like it could be a DT::Duration between the first
and last)

$set->elements (sounds like a clone of as_list)

$set->count (possible, though could it be a count of something else?)

$set->number_of_elements (long, but self explainitory)

So what does it return? I figure it returns
   1 + $#{$set->{set}{list}}
when it can, and it returns 
   $DateTime::INF
when it can't.

It would also be good if it could accept a span like as_list does.
Then if there is an infinite set (Say a set of Friday 13ths), we can get
the number of them in a particular span. Without the span parameter it
returns the count of the whole set or it returns INF.

Cheers!
Rick




Re: Subtraction Broken?

2003-08-17 Thread Joshua Hoblitt
Hi Mattew,

> $birth=DateTime->new(year=>1968,month=>6,day=>28);
> print $birth->ymd."\n";
> $today=DateTime->today;
> print $today->ymd."\n";
> $age=$today-$birth;
> print $age->years."\n";

$age is a DateTime::Duration object.   Unfortunately math with these object can be a 
little non-intuitive.

> I get this output:
>
> 1968-06-28
> 2003-08-17
> 0

Try:

print $age->deltas, "\n";

If the output from that doesn't look right to you please send it on to the list.

> That zero sure doesn't seem correct to me.

It means zero year 'units' - that doesn't preclude other 'units' adding up to year+ 
values.

Cheers,

-J

--


Re: DateTime::Set - Number of elements in set

2003-08-17 Thread Flavio Glock
--- Rick Measham <[EMAIL PROTECTED]> wrote:
> Flavio, is there already a method to determine the
> number of elements in
> a DateTime::Set? 
> 
> If not, I can currently make it as_list, and then
> get the length of the
> list, but it would be cleaner to have a method to do
> this.
 
There is an internal method. 
Would you suggest a name for it?

  $set->cardinality
  $set->n
  $set->???

- Flavio S. Glock


__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


Re: DateTime::Set - Number of elements in set

2003-08-17 Thread fglock
> Flavio, is there already a method to determine
> the number of elements in a DateTime::Set? 
> 
> If not, I can currently make it as_list, and then
> get the length of the list, but it would be 
> cleaner to have a method to do this.

What would be a name for this method?

There is no accessor yet. The number of 
elements is stored as:
  $set->{set}{too_complex}   -- if set is infinite
  1 + $#{$set->{set}{list}}  -- number of elements

- Flavio S. Glock

PS: sorry if this mail is being re-sent, 
 I had a problem with my webmail




Subtraction Broken?

2003-08-17 Thread Matthew McGillis
I'm not sure if I'm doing something really wrong or if things are 
broke but with this code:

#!/usr/bin/perl

use DateTime;

$birth=DateTime->new(year=>1968,month=>6,day=>28);
print $birth->ymd."\n";
$today=DateTime->today;
print $today->ymd."\n";
$age=$today-$birth;
print $age->years."\n";
I get this output:

1968-06-28
2003-08-17
0
That zero sure doesn't seem correct to me.


[ANNOUNCE] DateTime::Event::Easter 1.02

2003-08-17 Thread Rick Measham
The new Event-Easter has been uploaded to CPAN and should be available
shortly. This release fixes the issue raised by Ron Hill concerning
sets. Basically sets weren't being tested so the problem never showed
its head. The sets test was just a duplicate of the lists test! All
fixed now though!

Cheers!
Rick



DateTime::Set - Number of elements in set

2003-08-17 Thread Rick Measham
Flavio, is there already a method to determine the number of elements in
a DateTime::Set? 

If not, I can currently make it as_list, and then get the length of the
list, but it would be cleaner to have a method to do this.

Cheers!
Rick