[sf-perl] Perl's to_date() equivalent

Loo, Peter # PHX Peter.Loo at source.wolterskluwer.com
Fri Sep 1 14:42:00 PDT 2006


Hellow there.

Per Andy's recommendation, I went ahead and had DataTime.pm installed on
our test node.  It turned out that the date calculation is taking
approximately 11 seconds for every 5,000 records.  Is there something a
bit faster?  Here is my code:

  $counter = 0;
  while ( @cur = $sth->fetchrow() ) {
    if ($counter >= 5000) {
      printf(STDERR "$counter - %s", `date`);
      $counter = 0;
      }
    if ($prev[0] == $cur[0] && $prev[1] == $cur[1]) {
      ($pyear, $pmon, $pday) = split('-', $prev[7]);
      ($cyear, $cmon, $cday) = split('-', $cur[2]);
      $prev_cted = DateTime->new( year => $pyear, month => $pmon, day =>
$pday );
      $cur_rxdte = DateTime->new( year => $cyear, month => $cmon, day =>
$cday );
      ###########################################################
      # COMMENTS: Minus current rx_fill_dte with previous cted. #
      ###########################################################
      $dur = $prev_cted->subtract_datetime_absolute($cur_rxdte);
      $p_minus_c = $dur->in_units( 'days' );
      if ($p_minus_c >= 0 || ($p_minus_c < 0 && $p_minus_c <= $cur[5]))
{
        $prev_cted->add( days => $cur[4] );
        $cur[7] = $prev_cted->ymd;
        $cur[6] = "C";
        }
      elsif ($p_minus_c < 0 && $p_minus_c > $cur[5]) {
        $cur_rxdte->add( days => $cur[4] );
        $cur[7] = $cur_rxdte->ymd;
        $cur[6] = "R";
        }
      }
    @prev = @cur;
    $rec = join($delimiter, @cur);
    print PIPE "$rec\n";
    $counter++;
    }

  $sth->finish;
  $dbh->disconnect();
  close(PIPE); 

 
Peter

-----Original Message-----
From: sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.org
[mailto:sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.or
g] On Behalf Of David Fetter
Sent: Friday, August 25, 2006 10:04 AM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Perl's to_date() equivalent

On Fri, Aug 25, 2006 at 11:58:52AM -0500, Andy Lester wrote:
> 
> On Aug 25, 2006, at 11:56 AM, David Fetter wrote:
> 
> > Try Date::Manip from CPAN :)  It's not the fastest date munging 
> > library there, but it's very flexible.
> 
> I'd recommend DateTime as the standard at this point.

Thanks for the update. :)

My information was pretty old.

Cheers,
D
--
David Fetter <david at fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm


This E-mail message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information.  Any unauthorized
review, use, disclosure or distribution is prohibited.  If you are not
the intended recipient, please contact the sender by reply E-mail, and
destroy all copies of the original message.


More information about the SanFrancisco-pm mailing list