Exactly. The main problem is the &quot;day of the month&quot; ($mday) element of localtime begins with &quot;1 not &quot;0&quot; and does not need to be incremented.<br><pre class="verbatim"><span class="c">#  0    1    2     3     4    5     6     7     8</span><br>
<span class="s">(</span><span class="i">$sec</span><span class="cm">,</span><span class="i">$min</span><span class="cm">,</span><span class="i">$hour</span><span class="cm">,</span><span class="i">$mday</span><span class="cm">,</span><span class="i">$mon</span><span class="cm">,</span><span class="i">$year</span><span class="cm">,</span><span class="i">$wday</span><span class="cm">,</span><span class="i">$yday</span><span class="cm">,</span><span class="i">$isdst</span><span class="s">)</span> = <a class="l_k" href="http://perldoc.perl.org/functions/localtime.html">localtime</a><span class="s">(</span><a class="l_k" href="http://perldoc.perl.org/functions/time.html">time</a><span class="s">)</span><span class="sc">;</span></pre>
It does seem pretty arbitrary, since even the &quot;day of the year&quot; ($yday) element begins with &quot;0&quot; and goes through &quot;364&quot;. Not sure the history behind it - there may be a good story there.<br><br>
The second problem with that test was that it was just plain confusing. Not sure if the intent was to test yesterday&#39;s date or today&#39;s. But, you cannot get today by incrementing yesterday (at least not in that manner). So, I fixed the test by doing as you suggested, plus I began testing today&#39;s date instead.<br>
<br>Ed Eddington<br><br><br><br><div class="gmail_quote">On Fri, May 1, 2009 at 8:24 PM,  <span dir="ltr">&lt;<a href="mailto:grand-rapids-pm-list@pm.org">grand-rapids-pm-list@pm.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Looks like it never really worked right. It may have passed the test but the<br>
date would have been today&#39;s date except on the first day of the month when<br>
it would have been one day more than the possible number of days in the last<br>
month 12/32/2008 if run on 1/1/2009.  The localtime function is a little<br>
confusing because some things are zero based (like the month) and some<br>
things not (the day of the month) does anyone know of any other functions<br>
that do things like this?  Does anyone know or have a guess why they did<br>
this?  Looks like things that are always numbers do not need conversion and<br>
things that would be converted to names like days and months start at zero.<br>
<br>
So did it work yesterday or just not fail?<br>
<br>
To fix it I would take out &#39;+ 1&#39; after &#39;$time[3]&#39; in the 12th line.<br>
<br>
<br>
<br>
Is Perl Mongers meeting in May?<br>
<div><div></div><div class="h5"><br>
<br>
<br>
-----Original Message-----<br>
From: grand-rapids-pm-list-bounces+dave=<a href="http://hopasaurus.com" target="_blank">hopasaurus.com</a>@<a href="http://pm.org" target="_blank">pm.org</a><br>
[mailto:<a href="mailto:grand-rapids-pm-list-bounces%2Bdave">grand-rapids-pm-list-bounces+dave</a>=<a href="http://hopasaurus.com" target="_blank">hopasaurus.com</a>@<a href="http://pm.org" target="_blank">pm.org</a>] On Behalf<br>

Of <a href="mailto:grand-rapids-pm-list@pm.org">grand-rapids-pm-list@pm.org</a><br>
Sent: Friday, May 01, 2009 2:57 PM<br>
To: <a href="mailto:grand-rapids-pm-list@pm.org">grand-rapids-pm-list@pm.org</a><br>
Subject: [grand-rapids-pm-list] Perl Date Validator Test Chokes!<br>
<br>
Today I noticed a test failing in a piece of old code that tests a date<br>
validator. After some quick debugging, I found the problem. Can you find<br>
what is wrong with the second test below? (Btw, you can&#39;t actually run the<br>
code below, as I&#39;m only including the tests from the pod.) Hint: It worked<br>
yesterday! How would you fix it? I&#39;ll share my solution a bit later.<br>
<br>
    use Test::Exception;<br>
<br>
    # TEST 1 valid date, in the future<br>
    $q-&gt;param(&quot;${field}&quot;, &#39;01/01/3005&#39;);<br>
    lives_ok {<br>
        %ret = $date_v-&gt;validate;<br>
    } &#39;Valid date validated&#39;;<br>
    isnt($ret{&#39;valid&#39;}, 1, &#39;&gt; 6 months ago date validated correctly&#39;);<br>
    like($ret{&#39;error&#39;}, qr/\w+/, &#39;Correct error message returned.&#39;);<br>
<br>
    # TEST 2 valid date<br>
    my @time = localtime(time - 86400); # yesterday<br>
    my $date = sprintf(&#39;%02d/%02d/%04d&#39;, $time[4] + 1, $time[3] + 1,<br>
$time[5] + 1900);<br>
    diag(&quot;Date: $date&quot;);<br>
    $q-&gt;param(&quot;${field}&quot;, $date);<br>
    lives_ok {<br>
        %ret = $date_v-&gt;validate;<br>
    } &#39;Valid date validated&#39;;<br>
    is($ret{&#39;valid&#39;}, 1, &#39;Valid date validated correctly&#39;);<br>
<br>
<br>
<br>
Ed Eddington<br>
Gr.pm<br>
<br>
** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **<br>
This email transmission contains privileged and confidential information<br>
intended only for the use of the individual(s) or entity named above.  Any<br>
unauthorized review, use, disclosure or distribution is prohibited and may<br>
be a violation of law.  If you are not the intended recipient or a person<br>
responsible for delivering this message to an intended recipient, please<br>
delete the email and immediately notify the sender via the email return<br>
address or mailto:<a href="mailto:postmaster@priorityhealth.com">postmaster@priorityhealth.com</a>.  Thank you.<br>
<br>
<br>
_______________________________________________<br>
grand-rapids-pm-list mailing list<br>
<a href="mailto:grand-rapids-pm-list@pm.org">grand-rapids-pm-list@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list" target="_blank">http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list</a><br>
<br>
_______________________________________________<br>
grand-rapids-pm-list mailing list<br>
<a href="mailto:grand-rapids-pm-list@pm.org">grand-rapids-pm-list@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list" target="_blank">http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list</a><br>
</div></div></blockquote></div><br>