Re: DT::Duration overloads
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. 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? 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. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: DT::Duration overloads
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 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 particular from months to days or vice versa. This would be a problem regardless of the internals, right? -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: DT::Duration overloads
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 by deriving the midpoint between sunrise and sunset. I also need to approximate solar midnight by looking at the sunset from the prior day. As a general problem, finding a fractional time between two points in time is not that unusual. I *suppose* I could convert to epoch, take the diff, and use that to create a new duration. But it seems unfortunate that I'd have to step out of the datetime API like that. The two endpoints are known quantities -- there is no abiguity in selecting a midpoint. Is this sort of thing something that should exist in spans rather than expecting regular date math to handle? Matt
Re: DT::Duration overloads
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 particular from months to days or vice versa. This would be a problem regardless of the internals, right? I do understand the ambiguities when you are dealing with various forms of durations that are not anchored to an actual point in time. As I said in my last message, however, we're talking about two absolute points in time -- no ambiguity. Rephrased, the question is again: what is the midpoint of a span? (and if we come up with a good approach to this problem, it should solve the general class of problems having to do with portioning out spans). It's not immediately apparent to me what the solution is -- I know what I want to do, and would prefer it to be fairly easy and straightforward. This seems to be an area of the interface that could use some brushing up rather than some intrinsic ambiguity of date math. (I'm willing to meditate on possible solutions myself -- I'm not merely asking you to solve it for me. However, I just thought I might be missing something obvious) Thanks again, Matt
DateTime::Calendar::Discordian
While malingering from actual work, I wrote some code to convert dates to and from the Discordian calendar. Over the past couple of nights I made it into a proper DateTime::Calendar module which I posted to PerlMonks (http://www.perlmonks.org/index.pl?node_id=362936) This morning I also packaged it up into a proper CPAN package which you can find at http://src.braincells.com/perl/ Before I upload it to CPAN, I'd like you to review it and suggest any improvements, bugfixes etc. -- Jaldhar H. Vyas [EMAIL PROTECTED]
Re: DateTime::Calendar::Discordian
On Thu, 10 Jun 2004, Jaldhar H. Vyas wrote: While malingering from actual work, I wrote some code to convert dates to and from the Discordian calendar. Over the past couple of nights I made it into a proper DateTime::Calendar module which I posted to PerlMonks (http://www.perlmonks.org/index.pl?node_id=362936) This morning I also packaged it up into a proper CPAN package which you can find at http://src.braincells.com/perl/ Before I upload it to CPAN, I'd like you to review it and suggest any improvements, bugfixes etc. Well, Rich Bowen had started working on the same module, so you should talk to him. Reviewing the code/docs, I have a couple nits: - The constructor shouldn't take rd_secs, rd_nanosecs, or locale, I don't think. The only way to set this should be via the from_object method. - I'm assuming that the holyday spelling is intentional, right? - days_till_x should be days_until_x. I'm not a big fan of abbreviations in general, unless they're ridiculously obvious, and till is the wrong abbreviation anyway ;) - You have %% documented twice. - Using uuml; in the exclamations probably isn't right. This is part of Latin-1, so use that character. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: DateTime::Calendar::Discordian
On Thu, 10 Jun 2004, Dave Rolsky wrote: Well, Rich Bowen had started working on the same module, so you should talk to him. Reviewing the code/docs, I have a couple nits: Oh yeah I just saw that in the list archives. - The constructor shouldn't take rd_secs, rd_nanosecs, or locale, I don't think. The only way to set this should be via the from_object method. Ok. I'll change that. - I'm assuming that the holyday spelling is intentional, right? Yes. That seems to be the way Discordian texts spell it. - days_till_x should be days_until_x. I'm not a big fan of abbreviations in general, unless they're ridiculously obvious, and till is the wrong abbreviation anyway ;) Ok. I'll change that. - You have %% documented twice. - Using uuml; in the exclamations probably isn't right. This is part of Latin-1, so use that character. I think both of these are artifacts from cutting and pasting from PerlMonks but I'll make sure they are fixed. Apart from being an enjoyable little waste of time, this module is just a warmup for the Hindu calendars I said I was going to do a long time ago. -- Jaldhar H. Vyas [EMAIL PROTECTED]
Re: DT::Duration overloads
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( $start )-seconds / 2 ); (you may want to account for fractional seconds too) How about a DateTime::Span-midpoint method? - Flavio S. Glock
Re: DT::Duration overloads
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 = $end-subtract_datetime_absolute( $start )-seconds / 2 ); Oh, duh! Why didn't I think of that. That's nice simple. How about a DateTime::Span-midpoint method? Let's wait and see if others ask for it. For now, let's just add those recipes to the faq. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
ANNOUNCE: DateTime.pm 0.2101
0.2101 2004-06-10 - There was a bug in the date math code that occurred if you tried to add enough days, minutes or seconds to generate a datetime 10 years in the future (or so). If the the DateTime object had a a time zone with recurring DST changes, then the date math operation would cause a fatal error Invalid local time for date in time zone Reported by Dave Faraldo. -dave /*=== House Absolute Consulting www.houseabsolute.com ===*/
Re: Re: DT::Duration overloads
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 would be a good place for FRSs (Frequently Required Solutions) use DateTime::Util::Stats qw/:all/; # Solar Noon is the mean of sunrise and sunset: my $mean = mean_datetime( @dt_list ) # The mean is: round(scalar(@_) + 1 / 2) # IIRC # therefore $median == $sunset my $median = median_datetime( @dt_list ) On the other hand, maybe these should be DateTime::Set methods: my $mean = $set-mean( $sunrise, $sunset ); my $median = $set-median( $sunrise, $sunset ); I'm not sure that DateTime::Span is a good place for these as it would only apply to getting the mean of two DateTime objects whereas in DateTime::Set it's scope increases to allow any number of DateTimes. Would/Could there be any use for other statistical functions such as Standard Deviations? I can't think of any possible need for StdDev at the moment, but maybe there getting rid of outliers will be of benefit to someone? Cheers! Rick 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: Re: DT::Duration overloads
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 namespace, but I can see a Util namespace would be a good place for FRSs (Frequently Required Solutions) Flavio's solutions are brief and efficient. Why not just have it in the FAQ, as Dave suggests? use DateTime::Util::Stats qw/:all/; # Solar Noon is the mean of sunrise and sunset: my $mean = mean_datetime( @dt_list ) # The mean is: round(scalar(@_) + 1 / 2) # IIRC # therefore $median == $sunset my $median = median_datetime( @dt_list ) On the other hand, maybe these should be DateTime::Set methods: my $mean = $set-mean( $sunrise, $sunset ); my $median = $set-median( $sunrise, $sunset ); Huh? I'm confused by your usage of 'mean' and 'median'. In the case in question, I think 'midpoint' is a much clearer term to use. My $.02. 1; - Bruce __bruce__van_allen__santa_cruz__ca__