Debugging and DateTime?

2006-04-25 Thread Luke Hankins
I'm running into a wall trying to figure out why and intersection of a Span
and a SpanSet isn't coming out the way I'm expecting and am being stymied
by the opacity of DateTimes in general.

In broad terms, I'm doing something like this:

$span = DateTime::Span-from_datetimes(
start  = DateTime-from_epoch(epoch=$this-start_time),
before = DateTime-from_epoch(epoch=$this-end_time)
)-set_time_zone('America/New_York');

The SpanSet is a constructed by taking 
DateTime::SpanSet-empty_set-complement and intersecting with it things
like:

DateTime::SpanSet-from_set_and_duration(
set = DateTime::Event::Recurrence-daily( hours = $min),
hours = $max-$min,
minutes = 59,
seconds = 59
)-set_time_zone('America/New_York'); 

...and:


DateTime::SpanSet-from_set_and_duration(
set = DateTime::Set-from_recurrence(
recurrence = sub {
my ($dt) = @_;
return $dt-truncate(to = 'day')
-add(days = ($min-$dt-wday()+7-1) % 
7 + 1);
},
),
days = $max-$min,
hours = 23,
minutes = 59,
seconds = 59
)-set_time_zone('America/New_York');

The spanset and span seem to be what I'm expecting, but the intersection
keeps coming out as undefined.  What tools exist to help dig into this?


Re: Debugging and DateTime?

2006-04-25 Thread Luke Hankins
* Luke Hankins wrote:
 I'm running into a wall trying to figure out why and intersection of a Span
 and a SpanSet isn't coming out the way I'm expecting and am being stymied
 by the opacity of DateTimes in general.

...note that I'm pretty sure my current issue is related to timezones,
since the span is only about 1.5 minutes long and is likely missing the
spanset due to an offset.

-Luke


Re: Debugging and DateTime?

2006-04-25 Thread Flavio S. Glock
Would you mind providing a (non)working example?

OTOH, you can specify span durations using full hours (spansets are
created using the 'before' parameter by default):

DateTime::SpanSet-from_set_and_duration(
   set = DateTime::Event::Recurrence-daily( hours = $min),
   hours = 1+$max-$min,
   )-set_time_zone('America/New_York');

- Flavio S. Glock

2006/4/25, Luke Hankins [EMAIL PROTECTED]:
 I'm running into a wall trying to figure out why and intersection of a Span
 and a SpanSet isn't coming out the way I'm expecting and am being stymied
 by the opacity of DateTimes in general.

 In broad terms, I'm doing something like this:

[cut...]

 The spanset and span seem to be what I'm expecting, but the intersection
 keeps coming out as undefined.  What tools exist to help dig into this?



Re: Debugging and DateTime?

2006-04-25 Thread Flavio S. Glock
(forwarding back to the list)

2006/4/25, Luke Hankins [EMAIL PROTECTED]:
 * Flavio S. Glock wrote:
  Would you mind providing a (non)working example?

 Hurm.  The act of distilling it down to an example seems to have gotten it
 working.  Off to dig further. :-)

 This is slightly harder because DateTime::Format::Duration won't install on
 my machine due to test issues.  Is there an easy way to get the length of
 a Duration in seconds without using that module?

The way how to calculate seconds depends a lot on the context where
the result will be used.

One of the possible ways is to not use Duration at all - instead, you
can add a difference to a datetime:

  $dt = $dt + ( $dt_max - $dt_min );

  OTOH, you can specify span durations using full hours (spansets are
  created using the 'before' parameter by default):
 
  DateTime::SpanSet-from_set_and_duration(
 set = DateTime::Event::Recurrence-daily( hours = $min),
 hours = 1+$max-$min,
 )-set_time_zone('America/New_York');

 Ooh, good point.  I wrote that before I understood the difference between
 end and before.

 Thanks!


np.

- Flavio S. Glock


DateTime::Format::Duration update

2006-04-25 Thread Rick Measham
There's been a few comments and questions regarding 
DateTime::Format::Duration.


1. I'm looking at it
2. If you ignore any failures from the normalisation tests and
   don't use local normalisation, you should be fine. (ISO
   normalisation is fine)
3. DateTime Math is confusing me more than ever (not the
   implementation, the logic)

Once I sort all that out, there'll be a working release.

Here's some logic from my brain:

DST_DT := day before end of DST
a) DST_DT + 2 days   = 2 days
   (only the 'day' should change, so we're now 49 hours later)
b) DST_DT + 48 hours = 1 day, 24 hours
   (as there's 25 hours in the next day)
c) DST_DT + 2 days - 48 hours = 1 hour
   (2 days = 49 hrs as per (a) above)

However I can't get it to work like that using DateTime's own maths so 
I'm either looking for an explaination as to what's wrong with my logic, 
or I'm going to re-implement the math-as-I-need-it in DT:F:D as I'm 
losing too much hair over this!


Cheers!
Rick Measham



Re: DateTime::Format::Duration update

2006-04-25 Thread Dave Rolsky

On Wed, 26 Apr 2006, Rick Measham wrote:


DST_DT := day before end of DST
a) DST_DT + 2 days   = 2 days
  (only the 'day' should change, so we're now 49 hours later)
b) DST_DT + 48 hours = 1 day, 24 hours
  (as there's 25 hours in the next day)
c) DST_DT + 2 days - 48 hours = 1 hour
  (2 days = 49 hrs as per (a) above)

However I can't get it to work like that using DateTime's own maths so I'm 
either looking for an explaination as to what's wrong with my logic, or I'm 
going to re-implement the math-as-I-need-it in DT:F:D as I'm losing too much 
hair over this!


Can you post examples for any operations that don't do what you expect?

Also take a look at http://datetime.perl.org/index.cgi?MathProblems


-dave

/*===
VegGuide.Orgwww.BookIRead.com
Your guide to all that's veg.   My book blog
===*/