# SPUG: Date::Manip infinite loop

Joel Grow joel at largest.org
Sun Jan 13 09:45:51 PST 2013

```Thanks for all the replies!  I hadn't considered daylight saving time,
but that does seem to be the culprit.

The version of Date::Manip that "works" for me (ie, no infinite loop)
is 5.44.  The version that triggers the infinite loop is 6.24.  I just
installed the latest Date::Manip (6.38) and it still triggers the
infinite loop.

What's your recommendation to solve this? I simply want to iterate
through N sequential days of a calendar (eg, 90 consecutive days,
starting March 17).

I see 2 quickie ways to solve it, below. But my sleepy mind is probably
not thinking through this that well this morning. :-)

Joel

#---  V1  ----
use strict;
use Date::Manip;

my \$current_date = '2012/01/01 08:00';

while (Date_Cmp(\$current_date, '2012/12/31 08:00')) {
print "Current date is: \$current_date\n";

\$current_date =
UnixDate(DateCalc(\$current_date, "+1 days"), "%Y/%m/%d
%H:%M");
}

print "Bye!\n";

#---  V2  ----
use strict;
use Date::Manip;

my \$current_date = '2012/01/01';

while (Date_Cmp(\$current_date, '2012/12/31')) {
print "Current date is: \$current_date\n";

my \$next_date =
UnixDate(DateCalc(\$current_date, "+1 days"), "%Y/%m/%d");

if (\$next_date eq \$current_date) {
\$next_date =
UnixDate(DateCalc(\$current_date, "+2 days"), "%Y/%m/%d");
}

\$current_date = \$next_date;
}

print "Bye!\n";

#---  End  ---

On 13.01.2013 06:07, Charles DeRykus wrote:

> On Sat, Jan 12, 2013 at 8:21 PM, Ronald J Kimball
> <rjk-spug at tamias.net> wrote:
>> On Sat, Jan 12, 2013 at 02:36:35PM -0800, Joel Grow wrote:
>>> Hello SPUG gurus,
>>>
>>> I'm stumped as to why the code below gets into an infinite loop on
>>> November 4, 2012.  I tried starting \$current_date at Jan 1, 2011,
>>> and it
>>> gets into an infinite loop on November 6, 2011. This is on a linux
>>> box
>>> running perl 5.10.1.  When I run it on another linux box running
>>> 5.8.8,
>>> it works fine. Any idea what's going on? Thanks!
>>
>> Daylight Saving Time ended on November 4 in 2012, and on November 6
>> in
>> 2011.  Somehow Date::Manip is not handling this correctly when
>> day.
>>
>
> s/ correctly /in a DWIM-ish way/.  I think the gist is that
> Date::Manip's definition of 24 hrs="1 day" may produce a
> daylight savings surprise as happens here. A similar thing
> would happen if you just bump up the year to add "1 year"
> if the current date happens  to be Feb 29. Both cases need
> a bit of  DWIM magic.
>
> Date::Manip's author discusses the issue in depth here
> and mentions his intent to add some more DWIMery
> (which may have already happened)
>
>
> http://www.perlmonks.org/?node_id=936850.

```