Today's mini WTF?

nicholas on 2009-01-09T11:22:16

use Time::Local();
my $time = timelocal(localtime());

Now that I've discovered this "idiom" lurking in the code base, I'm purging it.


Time::localtime here

runrig on 2009-01-09T16:48:25

I keep finding:

use Time::localtime;

sub getCurrentTime {
    return \ctime();
}
# and then, e.g.:
my $time = ${&getCurrentTime};

DST?

srezic on 2009-01-09T20:07:47

Maybe it's intended. Check:

        $perl -MTime::Local -e 'warn timelocal(localtime(1224984600))'
        1224981000 at -e line 1.

Re:DST?

nicholas on 2009-01-09T21:30:08

Good point. I had assumed that it was an expensive no-op for all input values. However, the code in question has no special comments about detecting the 3600 seconds of the year when the wallclock time repeats. It usually seems to be about writing cookies that will expire in about 900 seconds, and I think it's just the long gone authors of the code again demonstrating that they weren't very good and didn't really understand what they were doing. (Which is partly why we now have 25% less code than 6 months ago - I've found a lot of dead stuff and duplication to remove.)