Re: DT::Format::Strptime %H

2006-05-18 Thread Jerrad Pierce
But it has everything to do with strptime, if DateTime has this (newer)
POSIXMEHARDER style approach. There's no reason this roll-over couldn't
be handled in the module. I see 24:00 as being an exceptional case, a
rather common and concise means to specify a *whole* day, without having
to do any math on the date itself.

All I've found is this thread "date normalization"
http://marc.theaimsgroup.com/?l=perl-datetime&m=105713352122992&w=2
-- 
H4sICNoBwDoAA3NpZwA9jbsNwDAIRHumuC4NklvXTOD0KSJEnwU8fHz4Q8M9i3sGzkS7BBrm
OkCTwsycb4S3DloZuMIYeXpLFqw5LaMhXC2ymhreVXNWMw9YGuAYdfmAbwomoPSyFJuFn2x8
Opr8bBBidcc=
--
MOTD on Pungenday, the 65th of Discord, in the YOLD 3172:
I've lost all sensation in my shirt


Re: DT::Format::Strptime %H

2006-05-18 Thread Rick Measham

Jerrad Pierce wrote:

I've run into a bit a bit of a problem using a format containing %H with raw
data. The data I have uses both 0:00 and 24:00, one being the beginning of the
day, the other the end. I know that the docs state %H accepts 0-23, but it
doesn't seem unreasonable that it ought to DWIM, and process 24:00 as the
beginning of the next day... instead of forcing the handling upon the user
(which defeats the purpose of comprehensive magic modules for complex tasks ;-)


Nothing to do with strptime .. no DateTime method allows overflowing of 
parameters. Check the archives for much discussion. If you need it, 
consider writing DateTime::Format::Overflow or similar.


Cheers!
Rick Measham



Misc. DT module interactions resulting in an infinite loop?

2006-05-18 Thread Jerrad Pierce
I've run into an odd issue with DateTime and Memoization (often necessary to
get decent performance for processing 10-20k records with repeat dates). I've
processed a lot of data this way but I recently ran into a few records that
caused an infinite loop, below is some simplified sample code that reproduces
the behavior. It goes away if I don't memoize DT::from_object, but I still
find it odd and thought somebody might be interested in looking into it further
(or documenting the potential for trouble?)

I'm using:

  $DateTime::VERSION = '0.2901';
  $DateTime::Set::VERSION = '0.25';
  $DateTime::Event::Recurrence::VERSION = '0.16';

with ActiveState under Win32.

=cut

use Memoize;
use DateTime::Format::Strptime;
use DateTime::Event::Recurrence;

#DateTime::from_object doesn't Memoize well here.
#Granted, there maybe ought to be a normalizer for the locale parameter?
memoize($_) foreach qw/DateTime::from_object DateTime::new/;

my $strp = new DateTime::Format::Strptime(pattern => '%m/%d/%Y %H:%M');

#Behavior seems to be tied to this data, several records preceeding it are OK
@F{qw(ETYP TYPE DESCRP SDateEDateM T W R F S U STime ETime ROOM)}=
   qw(CLSS ACADEMIC 6.27   2/1/2001 2/1/2001 0 0 0 R 0 0 0 900   2300  26-100);

$F{Start} =$strp->parse_datetime("$F{SDate} ".
 substr($F{STime}, 0,-2) .':'.
 substr($F{STime}, -2, 2));
$F{End}   =$strp->parse_datetime("$F{SDate} ".
 substr($F{ETime}, 0,-2) .':'.
 substr($F{ETime}, -2, 2));

$hours = DateTime::Set->from_recurrence(
start  => $F{Start},
before => $F{End},
recurrence => sub {
  $_[0]->truncate( to => 'hour' )
->add( hours => 1 )
  },
   );

$iter = $hours->iterator;

#Possibly related: while debugging I somehow, sometimes, managed to get output
#below, but the # of hours were off? I'd get back the even hours only...
printf "There ought to be %i hours\n", scalar $hours->as_list;


#Infinite loop here:
#_callback_previous: iterator can't find a previous value, got 2001-02-01
#  after 2001-02-01 at DateTime/Set.pm line 338.
while ( my $dt = $iter->next ) {
  my $hour = $dt->hour() || 24; #0..23,24 hours
  
  if( $hour >= 7 && $hour <= 24 ){
doMath($F{ROOM}, $F{Start}->dow, 1, $hour, 1);
  }
};

sub doMath{
  print "\$stash{ $_[0] }->{usage}->[ $_[1] ]->[ $_[3] ] += $_[2] * $_[4];\n";
  $stash{ $_[0] }->{usage}->[ $_[1] ]->[ $_[3] ] += $_[2] * $_[4];
}
__END__
-- 
H4sICNoBwDoAA3NpZwA9jbsNwDAIRHumuC4NklvXTOD0KSJEnwU8fHz4Q8M9i3sGzkS7BBrm
OkCTwsycb4S3DloZuMIYeXpLFqw5LaMhXC2ymhreVXNWMw9YGuAYdfmAbwomoPSyFJuFn2x8
Opr8bBBidcc=
--
MOTD on Pungenday, the 65th of Discord, in the YOLD 3172:
I've lost all sensation in my shirt


DT::Format::Strptime %H

2006-05-18 Thread Jerrad Pierce
I've run into a bit a bit of a problem using a format containing %H with raw
data. The data I have uses both 0:00 and 24:00, one being the beginning of the
day, the other the end. I know that the docs state %H accepts 0-23, but it
doesn't seem unreasonable that it ought to DWIM, and process 24:00 as the
beginning of the next day... instead of forcing the handling upon the user
(which defeats the purpose of comprehensive magic modules for complex tasks ;-)
-- 
H4sICNoBwDoAA3NpZwA9jbsNwDAIRHumuC4NklvXTOD0KSJEnwU8fHz4Q8M9i3sGzkS7BBrm
OkCTwsycb4S3DloZuMIYeXpLFqw5LaMhXC2ymhreVXNWMw9YGuAYdfmAbwomoPSyFJuFn2x8
Opr8bBBidcc=
--
MOTD on Pungenday, the 65th of Discord, in the YOLD 3172:
I've lost all sensation in my shirt