Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Below is a run of various inputs and you see that the only failure seen is Nov 1st:#!/usr/bin/perl -w use warnings; use strict; use Getopt::Long; use Time::Local; use POSIX qw(strftime); # The idea is to take an input date and add 6 days to it. # It seems to work except when the start date is November 1! # # Below is an example: # my $input_date; GetOptions("start_date=s" => \$input_date); print "\nWe expect a start day and a day 6 days later than that!\n"; my @date_pieces = split('/',$input_date); my $start_day = timelocal(0, 0, 0, $date_pieces[1], $date_pieces[0]-1, + $date_pieces[2]); my $end_day = $start_day + 6*24*60*60; my $new_start_day = strftime "%m/%d/%Y", (localtime($start_day)); my $new_end_day = strftime "%m/%d/%Y", (localtime($end_day)); print "The start day is $new_start_day and the end day is $new_end_day +\n";
Note how both November dates are 5 days apart as opposed to 6. Any help would be greatly appreciated.$ LIST="09/20/2008 1/1/2009 11/3/2008 06/06/2006 11/1/2008 11/1/2008 1 +0/1/2008" $ for i in $LIST > do > booger -start_date $i > done We expect a start day and a day 6 days later than that! The start day is 09/20/2008 and the end day is 09/26/2008 We expect a start day and a day 6 days later than that! The start day is 01/01/2009 and the end day is 01/07/2009 We expect a start day and a day 6 days later than that! The start day is 11/03/2008 and the end day is 11/09/2008 We expect a start day and a day 6 days later than that! The start day is 06/06/2006 and the end day is 06/12/2006 We expect a start day and a day 6 days later than that! The start day is 11/01/2008 and the end day is 11/06/2008 We expect a start day and a day 6 days later than that! The start day is 11/01/2008 and the end day is 11/06/2008 We expect a start day and a day 6 days later than that! The start day is 10/01/2008 and the end day is 10/07/2008
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date string conundrum
by Fletch (Bishop) on Dec 01, 2008 at 20:04 UTC | |
|
Re: date string conundrum
by Corion (Patriarch) on Dec 01, 2008 at 20:08 UTC | |
|
Re: date string conundrum
by toolic (Bishop) on Dec 01, 2008 at 20:13 UTC | |
|
Re: date string conundrum
by almut (Canon) on Dec 01, 2008 at 20:39 UTC | |
|
Re: date string conundrum
by ww (Archbishop) on Dec 01, 2008 at 22:08 UTC | |
by ikegami (Patriarch) on Dec 03, 2008 at 18:46 UTC | |
|
Re: date string conundrum
by pileofrogs (Priest) on Dec 01, 2008 at 21:49 UTC |