Re: Re: DT::Duration overloads

2004-06-11 Thread Rick Measham
I said: On the other hand, maybe these should be DateTime::Set methods: my $mean = $set-mean( $sunrise, $sunset ); my $median = $set-median( $sunrise, $sunset ); On Thu, 10 Jun 2004 18:04:36 -0700, Bruce Van Allen wrote Huh? I'm confused by your usage of 'mean' and 'median'. In the case

Re: DT::Duration overloads

2004-06-11 Thread Matt Sisk
Quoting Dave Rolsky [EMAIL PROTECTED]: With DateTime::Span: $mid_point = $span-start-add_duration( seconds = $span-duration-seconds / 2 ); With DateTime: $mid_point = $start-add_duration( seconds = $end-subtract_datetime_absolute(

Re: DT::Duration overloads

2004-06-11 Thread Dave Rolsky
On Fri, 11 Jun 2004, Matt Sisk wrote: Quoting Dave Rolsky [EMAIL PROTECTED]: With DateTime::Span: $mid_point = $span-start-add_duration( seconds = $span-duration-seconds / 2 ); With DateTime: $mid_point = $start-add_duration(

Re: DT::Duration overloads

2004-06-10 Thread Dave Rolsky
On Thu, 10 Jun 2004, Matt Sisk wrote: 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.

Re: DT::Duration overloads

2004-06-10 Thread Dave Rolsky
On Thu, 10 Jun 2004, Matt Sisk wrote: 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: Also, I'd like to point out that this really doesn't

Re: DT::Duration overloads

2004-06-10 Thread Matt Sisk
Dave Rolsky wrote: Well, if you just want the _date_, it's pretty easy. my $dur = $dt1-delta_days($dt2); # or use Math::Round if you want my $mid = $dt1-add( days = int( $dur-delta_days / 2 ) ); If you want to account for the time then it gets funkier. Hmm, indeed. I need to approximate solar noon

Re: DT::Duration overloads

2004-06-10 Thread Matt Sisk
Dave Rolsky wrote: Also, I'd like to point out that this really doesn't have as much to do with the internals as it does with the nature of date time math. You cannot expect to understand date math without understanding that it's not possible to convert between various units of date/time, in

Re: DT::Duration overloads

2004-06-10 Thread fglock
Matt Sisk wrote: what is the midpoint of a span? With DateTime::Span: $mid_point = $span-start-add_duration( seconds = $span-duration-seconds / 2 ); With DateTime: $mid_point = $start-add_duration( seconds = $end-subtract_datetime_absolute(

Re: DT::Duration overloads

2004-06-10 Thread Dave Rolsky
On Thu, 10 Jun 2004 [EMAIL PROTECTED] wrote: Matt Sisk wrote: what is the midpoint of a span? With DateTime::Span: $mid_point = $span-start-add_duration( seconds = $span-duration-seconds / 2 ); With DateTime: $mid_point = $start-add_duration( seconds

Re: Re: DT::Duration overloads

2004-06-10 Thread Rick Measham
On Thu, 10 Jun 2004 [EMAIL PROTECTED] wrote: How about a DateTime::Span-midpoint method? On 11 Jun 2004, at 6:55 AM, Dave Rolsky replied: Let's wait and see if others ask for it. For now, let's just add those recipes to the faq. I'm not sure of the best namespace, but I can see a Util namespace

Re: Re: DT::Duration overloads

2004-06-10 Thread Bruce Van Allen
On 6/11/04 Rick Measham wrote: On Thu, 10 Jun 2004 [EMAIL PROTECTED] wrote: How about a DateTime::Span-midpoint method? On 11 Jun 2004, at 6:55 AM, Dave Rolsky replied: Let's wait and see if others ask for it. For now, let's just add those recipes to the faq. I'm not sure of the best

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.

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 =

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 =

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

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 =

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