use integer;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
-$VERSION = '1.07_94';
+$VERSION = '1.09';
$VERSION = eval $VERSION;
@ISA = qw( Exporter );
@EXPORT = qw( timegm timelocal );
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 system epoch
-(Midnight, January 1, 1970 UTC on Unix, for example). This value can
+(Midnight, January 1, 1970 GMT 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.
Years greater than 999 are interpreted as being the actual year,
rather than the offset from 1900. Thus, 1963 would indicate the year
-Martin Luther King won the Nobel prize, not the year 2863.
+Martin Luther King won the Nobel prize, not the year 3863.
=item *
=head2 Ambiguous Local Times (DST)
Because of DST changes, there are many time zones where the same local
-time occurs for two different UTC times on the same day. For example,
+time occurs for two different GMT times on the same day. For example,
in the "Europe/Paris" time zone, the local time of 2001-10-28 02:30:00
-can represent either 2001-10-28 00:30:00 UTC, B<or> 2001-10-28
-01:30:00 UTC.
+can represent either 2001-10-28 00:30:00 GMT, B<or> 2001-10-28
+01:30:00 GMT.
When given an ambiguous local time, the timelocal() function should
-always return the epoch for the I<earlier> of the two possible UTC
+always return the epoch for the I<earlier> of the two possible GMT
times.
+=head2 Non-Existent Local Times (DST)
+
+When a DST change causes a locale clock to skip one hour forward,
+there will be an hour's worth of local times that don't exist. Again,
+for the "Europe/Paris" time zone, the local clock jumped from
+2001-03-25 01:59:59 to 2001-03-25 03:00:00.
+
+If the timelocal() function is given a non-existent local time, it
+will simply return an epoch value for the time one hour later.
+
=head2 Negative Epoch Values
Negative epoch (time_t) values are not officially supported by the
=head1 SUPPORT
-Support for this module is provided via the perl5-porters@perl.org
+Support for this module is provided via the datetime@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.
+Please submit bugs using the RT system at rt.cpan.org, or as a last
+resort, to the datetime@perl.org list.
=head1 AUTHOR
my $tests = (@time * 12) + 6;
$tests += 2 if $ENV{PERL_CORE};
-$tests += 3 if $ENV{MAINTAINER};
+$tests += 5 if $ENV{MAINTAINER};
plan tests => $tests;
if ($^O eq 'vos' && $year == 70) {
skip(1, "skipping 1970 test on VOS.\n") for 1..6;
} else {
- my $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
+ my $time = timegm($sec,$min,$hour,$mday,$mon,$year);
- my($s,$m,$h,$D,$M,$Y) = localtime($time);
+ my($s,$m,$h,$D,$M,$Y) = gmtime($time);
ok($s, $sec, 'second');
ok($m, $min, 'minute');
# round trip was broken for edge cases
if ($^O eq "aix" && $Config{osvers} =~ m/^4\.3\./) {
-skip ("No fix expected for edge case test for $_ on AIX 4.3") for qw( timegm timelocal );
+ skip ("No fix expected for edge case test for $_ on AIX 4.3") for qw( timegm timelocal );
} else {
-ok(sprintf('%x', timegm(gmtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
- '0x7fffffff round trip through gmtime then timegm');
+ ok(sprintf('%x', timegm(gmtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
+ '0x7fffffff round trip through gmtime then timegm');
-ok(sprintf('%x', timelocal(localtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
- '0x7fffffff round trip through localtime then timelocal');
+ ok(sprintf('%x', timelocal(localtime(0x7fffffff))), sprintf('%x', 0x7fffffff),
+ '0x7fffffff round trip through localtime then timelocal');
}
if ($ENV{MAINTAINER}) {
local $ENV{TZ} = 'America/Chicago';
POSIX::tzset();
- # Same local time in America/Chicago. There is transition here as
- # well.
+ # Same local time in America/Chicago. There is a transition
+ # here as well.
$time = timelocal(0, 30, 1, 28, 9, 101);
ok($time, 1004250600,
'timelocal prefers earlier epoch in the presence of a DST change');
+ $time = timelocal(0, 30, 2, 1, 3, 101);
+ ok($time, 986113800,
+ 'timelocal for non-existent time gives you the time one hour later');
+
local $ENV{TZ} = 'Australia/Sydney';
POSIX::tzset();
$time = timelocal(0, 30, 2, 25, 2, 101);
ok($time, 985447800,
'timelocal prefers earlier epoch in the presence of a DST change');
+
+ $time = timelocal(0, 30, 2, 28, 9, 101);
+ ok($time, 1004200200,
+ 'timelocal for non-existent time gives you the time one hour later');
}
}
if ($ENV{PERL_CORE}) {
package test;
require 'timelocal.pl';
+
+ # need to get ok() from main package
::ok(timegm(0,0,0,1,0,80), main::timegm(0,0,0,1,0,80),
'timegm in timelocal.pl');