Why am I getting a “Day Too Big” error from Perl?

I was helping someone debug some code where the error message was "too big a day." I know this comes from local time and error Y2038 (most of the Google results seem to be people who deal with cookies that go well into the future).

It seems that we have “fixed” the problem, using the time to get the current date. However, given that none of our starting dates hit the 2038 issue, I am skeptical that we really fixed the problem ...

Are there other cases where someone knows where one could “suffer too much”?

OS is Solaris.

Code example - the actual code is quite large, and the person I work with did not actually isolate the part that violates the law (which is why I worry that the “fix” is not really a fix). If I can put together something short that will reproduce the question, I will publish!

UPDATE

I highlighted a bit of code, put some print statements about everything, and solved the problem ...

Offensive line of code:

$temp = str2time(localtime());

It is often (but not always) setting $ temp as undef. It turns out that even when $ temp was installed, it was not installed with the expected value.

It turns out that localtime () returns an array in most contexts ... and what causes the str2time call.

By changing this to:

$ltime = localtime;
$temp = str2time($ltime);

the problem disappears.

Of course, even better, just use:

$temp = time;
+3
source share
1

Time::Local " ". , .

Carp::Always.

perl -MCarp::Always script.pl arg1 arg2 ...

, .

+7

Source: https://habr.com/ru/post/1739084/


All Articles