Subject: | T:U heavy and incorrect on MacOS |
Date: | Mon, 5 Mar 2012 11:36:46 +0000 |
To: | bug-Time-Unix [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
Attached patch fixes two problems with Time::Unix. Sorry, I couldn't
disentangle them, the two issues textually interact too much.
The first issue is that the MacOS logic is slightly incorrect.
It supposes that there's a fixed offset between MacOS time_t and Unix
time_t, whereas in fact it will vary over time due to MacOS using the
local timezone. If a program keeps running across an offset change in the
timezone, the offset that T:U cached at the beginning will be incorrect.
Also, incidentally, there's a race condition in the offset determination,
due to "localtime" and "gmtime" separately determining the current time.
"localtime(localtime)" amounts to just "CORE::time()". This can all
be corrected, and substantially simplified, by replacing all of that
localtime logic with just "localtime(gmtime)" in a MacOS-specific version
of the time() sub.
The second issue is that Time::Unix is surprisingly heavy to load.
This is mainly because it loads Time::Local, which is quite big and loads
several other modules. Since Time::Local is actually only required on
MacOS, the Time::Unix load can be made much lighter everywhere else by
only loading Time::Local when it's actually needed. Another issue is
the use of "use vars", which is redundant on Perl 5.6 and later, and
after such passage of time (over 11 years since you first published T:U)
there shouldn't be any problem with switching to the Perl 5.6 formulation.
-zefram
Message body is not shown because sender requested not to inline it.