title: Why do I get a "Day too big" error from Perl?
body: <p>I have been helping someone debug some code where the error message was "Day too big".  I know that this springs from localtime and the Y2038 bug (most google results appear to be people dealing with cookies expiring well into the future).</p>
  
  <p>We appear to have 'fixed' the problem by using time to get the current date.  However, given that none of our original dates should have hit the 2038 issue I'm sceptical that we've actually fixed the problem ... </p>
  
  <p>Are there other instances that anyone knows of where one would hit "day too big"?</p>
  
  <p>OS is Solaris.</p>
  
  <p>Sample code - the actual code is quite large and the person I'm working with hasn't actually isolated the offending part (which is why I'm worried the 'fix' is not actually a fix).  If I can put together something concise which reproduces the issue I will post!</p>
  
  <p>UPDATE</p>
  
  <p>I isolated the bit of code, put some print statements around everything and have solved the problem ...</p>
  
  <p>The offending line of code was:</p>
  
  <pre><code>$temp = str2time(localtime());
  </code></pre>
  
  <p>This was often (but not always) setting $temp as undef.  It turns out that even when $temp was being set it wasn't being set with the expected value.</p>
  
  <p>The gotcha is that localtime() returns an array in most contexts ... and that's what's messing up the call to str2time.  </p>
  
  <p>By changing this to:</p>
  
  <pre><code>$ltime = localtime;
  $temp = str2time($ltime);
  </code></pre>
  
  <p>the problem goes away.</p>
  
  <p>Of course, better yet, just use:</p>
  
  <pre><code>$temp = time;
  </code></pre>