Perl in KSH - julian conversion
Hello Everyone,
I have this code misbehaving in one of my scripts, I have a var containing the sequential number of the day for the year and I am suppose to get the regular date for that day and its weekday.
If I set the day to 273 I get back 2008/09/31 which is not a proper date.
can you help me understand why?
.................
syy=2008
newstart=272
perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $mytime = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime);
$yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday number;
$weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pppp
newstart=273
perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $mytime = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime);
$yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday number;
$weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pppp
newstart=274
perl -e 'use Time::Local; $yr = $ARGV[0] - 1900; $yday = $ARGV[1]; $mytime = timelocal(1,0,0,1,1,$yr); $mytime += ( 86400 * $yday ); ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$whocares) = localtime($mytime);
$yr += 1900; printf("%d/%02d/%02d%s", $yr, $mon, $day, " " );use POSIX qw(strftime);$fmt = "%A"; # %a = abbreviated weekday %u = weekday number;
$weekday = strftime($fmt, 0, 0, 0, $day , $mon - 1, $yr - 1900, -1, -1, -1);printf("%s%s%s", "$weekday"," ",$ARG[2]);' $syy $newstart >> pppp
the contents of pppp:
2008/09/30 Tuesday 2008/09/31 Wednesday 2008/10/01 Wednesday
Thanks for your help.