Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed!! Date::Calc::Add_Delta_Days(): not a valid date

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
0
0
US
Dear experts,

I have a piece of codes that has work for me for quite a long time and it suddenly stopped working.

Code:
#! /usr/bin/perl

use strict;
use warnings;
use POSIX qw(strftime);
use Date::Calc qw (Add_Delta_Days);

my $offset = -1;
my $thisDay = &getThisDayDate($offset);
print "\$thisDay = $thisDay\n"; # should be yesterday's date
exit;

sub getDate {
  my @today = localtime;
  return @today;
}

sub getThisDayDate {
  my ($offset) = @_;
  $offset = 0 if(!$offset);
  my @today = &getDate();
  my $todayStr = join ', ', @today;
  print "\$offset = $offset, \@today = $todayStr\n";
  [b][COLOR=red]@today[5,4,3] = Add_Delta_Days(@today[5,4,3], $offset); # Line 24!![/color][/b]
  my $thisday = strftime "%Y%m%d", @today;
  return $thisday;
}

% ./testDateCalc.pl
$offset = 1, @today = 38, 9, 14, 31, 9, 111, 1, 303, 0
[b]Date::Calc::PP::Add_Delta_Days(): Date::Calc::Add_Delta_Days(): not a valid date at ./testDateCalc.pl line 24 [/b]

And here is my machine time:
Code:
% date
Mon Oct 31 14:09:40 UTC 2011

Could someone tell me what the problem is and how to fix it?

Many thanks!!
 
I just did a quick and dirty fix and it works:

Code:
sub getThisDayDate {
  my ($offset) = @_;
  $offset = 0 if(!$offset);
  my @today = &getDate();
  my $date = strftime "%Y %m %d %H:%M:%S", @today;
  my @tmp = split(/\s+/, $date);
  my ($y, $m, $d) = Add_Delta_Days($tmp[0], $tmp[1], $tmp[2], $offset);
  my $thisday = $y.$m.$d;
}

But I still don't understand why the first piece of codes stopped working. I also checked the history and found out that the 1st piece of codes had worked from 2007 to two days ago (10/29/2011)!
 
It's so strange!!

I just test the piece of codes in question listed above again. The error disappeared!!

But I just don't understand why the error showed up couple days ago.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top