Re: Subtraction Broken?

2003-08-22 Thread Joshua Hoblitt
> > The only problem is that DT::subtract_datetime doesn't use it. It
> > probably should. (It would be even better if there was an option to
> > calculate the difference in days & secs. But the default should probably
> > be to return a difference of months, days, minutes, seconds.)
>
> I think the default should probably be the accurate method, but I do think
> offering a way to return the other values would be good.

I'm a bit nervous about building that into DT::Duration.  If a resulting vague result 
is reused for date math someone could blow their foot off an not realize it.

-J

--


Re: Subtraction Broken?

2003-08-22 Thread Joshua Hoblitt
> The infrastructure does exist: a DT::Duration can contain years
> (actually, it contains months; but the conversion months <=> years is
> unique), and a DT of say 2 years and 3 months already is relative to
> DateTime.
>
> The only problem is that DT::subtract_datetime doesn't use it. It
> probably should. (It would be even better if there was an option to
> calculate the difference in days & secs. But the default should probably
> be to return a difference of months, days, minutes, seconds.)

Yes, it can contain years but in doing so you loss precision.  The current behavior 
preserves the maximum amount of accuracy possible.  Thats why I'm advocating another 
class to convert to non-position independent values.

-J

--


Re: Subtraction Broken?

2003-08-22 Thread Eugene van der Pijll
Dave Rolsky schreef:
> On Sat, 23 Aug 2003, Eugene van der Pijll wrote:
> 
> > The only problem is that DT::subtract_datetime doesn't use it. It
> > probably should. (It would be even better if there was an option to
> > calculate the difference in days & secs. But the default should probably
> > be to return a difference of months, days, minutes, seconds.)
> 
> I think the default should probably be the accurate method, but I do think
> offering a way to return the other values would be good.

You probably mean "the more accurate method". Days are of different
lengths too, even in UTC. (But only because of leap seconds, of course.
No DST.)

But the most accurate method is not necessarily the best. If the two
dates are far apart, most people will expect "y, m, d" durations. For
example, do you not think these intervals are of the same length:
1 Jan 1991 to 1 Jan 1993, and 1 Jan 2001 to 1 Jan 2003 ? Most people
would want these intervals to count as the same length, and would be
surprised to see a difference.

However, for these two intervals: 1 Feb 2003 to 1 Mar 2003, and
1 Mar 2003 to 1 Apr 2003, people wouldn't be surprised to see a
difference. Probably...

Eugene




Re: Subtraction Broken?

2003-08-22 Thread Dave Rolsky
On Sat, 23 Aug 2003, Eugene van der Pijll wrote:

> The only problem is that DT::subtract_datetime doesn't use it. It
> probably should. (It would be even better if there was an option to
> calculate the difference in days & secs. But the default should probably
> be to return a difference of months, days, minutes, seconds.)

I think the default should probably be the accurate method, but I do think
offering a way to return the other values would be good.


-dave

/*===
House Absolute Consulting
www.houseabsolute.com
===*/


Re: Subtraction Broken?

2003-08-22 Thread Eugene van der Pijll
Joshua Hoblitt schreef:
> > >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:
> 
> You are getting the _correct_ answer.  Let me say that again.  You are
> getting the _correct_ answer.  The information is exactly what you
> asked for.  It just not in the units that you want.

No, he's getting _a_ correct answer. The information is _not_ what he
has asked for.

2003-08-23 minus 1970-08-23 is both equal to 23 years, and to 12053
days, even though 23 years is very much different from 12053 years.

> The units that
> you are asking for are of variable length and depend on the context in
> which they are used.

Days also have a variable length. Only DT::Duration's that contain only
a 'seconds' component represent time intervals of constant length.

The reason why DT::subtract_datetime returns a DT::Duration with days
and seconds, is the way DT's are implemented internally: rd_days and
rd_seconds. It's easier and faster to just subtract these values.

> It is not a stub.  It should not produce 35.  You really don't seem to
> believe me but the behavior is _correct_.  What you are asking for is
> a DT::Duration relative to DateTime and the infrastructure simply
> doesn't exist yet.

The infrastructure does exist: a DT::Duration can contain years
(actually, it contains months; but the conversion months <=> years is
unique), and a DT of say 2 years and 3 months already is relative to
DateTime.

The only problem is that DT::subtract_datetime doesn't use it. It
probably should. (It would be even better if there was an option to
calculate the difference in days & secs. But the default should probably
be to return a difference of months, days, minutes, seconds.)

Eugene


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: 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

--


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.