package Time::Local;
-use 5.006;
+
require Exporter;
use Carp;
use Config;
use strict;
use integer;
-our $VERSION = '1.04';
-our @ISA = qw( Exporter );
-our @EXPORT = qw( timegm timelocal );
-our @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck );
+use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
+$VERSION = '1.07';
+@ISA = qw( Exporter );
+@EXPORT = qw( timegm timelocal );
+@EXPORT_OK = qw( timegm_nocheck timelocal_nocheck );
my @MonthDays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
my $NextCentury = $ThisYear - $ThisYear % 100;
$NextCentury += 100 if $Breakpoint < 50;
my $Century = $NextCentury - 100;
+my $SecOff = 0;
my (%Options, %Cheat);
+my $MaxInt = ((1<<(8 * $Config{intsize} - 2))-1)*2 + 1;
+my $MaxDay = int(($MaxInt-43200)/86400)-1;
+
# Determine the EPOC day for this machine
my $Epoc = 0;
if ($^O eq 'vos') {
# work around posix-977 -- VOS doesn't handle dates in
# the range 1970-1980.
$Epoc = _daygm((0, 0, 0, 1, 0, 70, 4, 0));
-} else {
+}
+elsif ($^O eq 'MacOS') {
+ no integer;
+
+ $MaxDay *=2 if $^O eq 'MacOS'; # time_t unsigned ... quick hack?
+ # MacOS time() is seconds since 1 Jan 1904, localtime
+ # so we need to calculate an offset to apply later
+ $Epoc = 693901;
+ $SecOff = timelocal(localtime(0)) - timelocal(gmtime(0));
+ $Epoc += _daygm(gmtime(0));
+}
+else {
$Epoc = _daygm(gmtime(0));
}
%Cheat=(); # clear the cache as epoc has changed
-my $MaxInt = ((1<<(8 * $Config{intsize} - 2))-1)*2 + 1;
-my $MaxDay = int(($MaxInt-43200)/86400)-1;
-
-
sub _daygm {
$_[3] + ($Cheat{pack("ss",@_[4,5])} ||= do {
my $month = ($_[4] + 10) % 12;
sub _timegm {
- $_[0] + 60 * $_[1] + 3600 * $_[2] + 86400 * &_daygm;
+ my $sec = $SecOff + $_[0] + 60 * $_[1] + 3600 * $_[2];
+
+ no integer;
+
+ $sec + 86400 * &_daygm;
}
croak "Cannot handle date ($sec, $min, $hour, $mday, $month, $year)";
}
- $sec + 60*$min + 3600*$hour + 86400*$days;
+ $sec += $SecOff + 60*$min + 3600*$hour;
+
+ no integer;
+
+ $sec + 86400*$days;
}
sub timelocal {
+ no integer;
my $ref_t = &timegm;
my $loc_t = _timegm(localtime($ref_t));
or return $loc_t;
# Adjust for DST change
- $loc_t + $dst_off;
+ $loc_t += $dst_off;
+
+ # for a negative offset from GMT, and if the original date
+ # was a non-extent gap in a forward DST jump, we should
+ # now have the wrong answer - undo the DST adjust;
+
+ return $loc_t if $zone_off <= 0;
+
+ my ($s,$m,$h) = localtime($loc_t);
+ $loc_t -= $dst_off if $s != $_[0] || $m != $_[1] || $h != $_[2];
+
+ $loc_t;
}
These routines are the inverse of built-in perl functions localtime()
and gmtime(). They accept a date as a six-element array, and return
-the corresponding time(2) value in seconds since the Epoch (Midnight,
-January 1, 1970). This value can be positive or negative.
+the corresponding time(2) value in seconds since the system epoch
+(Midnight, January 1, 1970 UTC on Unix, for example). This value can
+be positive or negative, though POSIX only requires support for
+positive values, so dates before the system's epoch may not work on
+all operating systems.
It is worth drawing particular attention to the expected ranges for
the values provided. The value for the day of the month is the actual day
The proclivity to croak() is probably a bug.
+=head1 SUPPORT
+
+Support for this module is provided via the perl5-porters@perl.org
+email list. See http://lists.perl.org/ for more details.
+
+Please submit bugs using the RT system at bugs.perl.org, the perlbug
+script, or as a last resort, to the perl5-porters@perl.org list.
+
+=head1 AUTHOR
+
+This module is based on a Perl 4 library, timelocal.pl, that was
+included with Perl 4.036, and was most likely written by Tom
+Christiansen.
+
+The current version was written by Graham Barr.
+
+It is now being maintained separately from the Perl core by Dave
+Rolsky, <autarch@urth.org>.
+
=cut