DT::Duration overloads

2004-06-09 Thread Matt Sisk
I understand that division can be expressed as multiplication, but is 
there any particular reason why division (/) is not overloaded but 
multiplication is for durations? Then you could say:

 $midpoint = ($dt2 - $dt1)/2;
rather than
 $midpoint = ($dt2 - $dt1) * 0.5;
Small thing. Just curious.
Thanks,
Matt


Re: DT::Duration overloads

2004-06-09 Thread Dave Rolsky
On Wed, 9 Jun 2004, Matt Sisk wrote:

 I understand that division can be expressed as multiplication, but is
 there any particular reason why division (/) is not overloaded but
 multiplication is for durations? Then you could say:

   $midpoint = ($dt2 - $dt1)/2;

 rather than

   $midpoint = ($dt2 - $dt1) * 0.5;

 Small thing. Just curious.

Well, division doesn't really work, whether you do it as multiplication or
not ;)

What is half a minute?  How long is half a month?


-dave

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


Re: DT::Duration overloads

2004-06-09 Thread Rick Measham
On 10 Jun 2004, at 9:25 AM, Dave Rolsky wrote:
What is half a minute?  How long is half a month?
$dtd = DateTime::Duration-new(
months  = 1,
minutes = 1,
);
$half_dtd = $dtd / 2;
print $half_dtd-months . \n;
# 0.5
print $half_dtd-seconds . \n;
# 0.5
print strfduration(
	normalise = 'ISO',
	pattern   = '%Y years, %m months, %e days, %H hours, %M minutes, %S 
seconds',
	duration  = $half_dtd
);
# 0 years, 0 months, 15 days, 0 hours, 0 minutes, 30 seconds


Senior Developer
PrintSupply - Print Procurement  Supply Management
18 Greenaway Street VIC 3105
Tel: (03) 9850 3255
Fx: (03) 9850 3277
http://www.printsupply.com.au/


Re: DT::Duration overloads

2004-06-09 Thread Dave Rolsky
On Thu, 10 Jun 2004, Rick Measham wrote:

 On 10 Jun 2004, at 9:25 AM, Dave Rolsky wrote:
  What is half a minute?  How long is half a month?

 $dtd = DateTime::Duration-new(
   months  = 1,
   minutes = 1,
 );

 $half_dtd = $dtd / 2;

 print $half_dtd-months . \n;
 # 0.5

 print $half_dtd-seconds . \n;
 # 0.5

 print strfduration(
   normalise = 'ISO',
   pattern   = '%Y years, %m months, %e days, %H hours, %M minutes, %S
 seconds',
   duration  = $half_dtd
 );
 # 0 years, 0 months, 15 days, 0 hours, 0 minutes, 30 seconds

Great, now what should DateTime.pm do in the add_duration method?


-dave

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


Re: DT::Duration overloads

2004-06-09 Thread Dave Rolsky
On Wed, 9 Jun 2004, Matt Sisk wrote:

 I understand that division can be expressed as multiplication, but is
 there any particular reason why division (/) is not overloaded but
 multiplication is for durations? Then you could say:

   $midpoint = ($dt2 - $dt1)/2;

 rather than

   $midpoint = ($dt2 - $dt1) * 0.5;

 Small thing. Just curious.

Thinking about this more, I'm considering maybe just requiring that
multiplication be passed an integer, because if you do this:

 my $dur = DateTime::Duration-new( months = 1, days = 1, minutes = 1 );
 $dur-multiple(.5);

 print DateTime-now-add_duration($dur)-datetime;

The results are kind of weird, and certainly not what anyone would expect.


-dave

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


Re: DT::Duration overloads

2004-06-09 Thread Matt Sisk
Dave Rolsky wrote:
Thinking about this more, I'm considering maybe just requiring that
multiplication be passed an integer, because if you do this:
 

What I'd like to do is simply find the midpoint, more or less, between 
two arbitrary datetimes. Off the cuff, knowing nothing about the 
internals (which I do, but I'm pretending not to) I'd think this:

 $mid = $dt1 + ($dt2 - $dt1)/2
to dwim.
However, as you say, things aren't really well defined the way durations 
are defined internally at the moment.

So the question becomes -- if the above is not the datetime idiom for 
finding a midpoint between two datetimes, then what is?

Thanks,
Matt