diff options
author | Steve Hay <steve.m.hay@googlemail.com> | 2018-07-03 13:49:05 +0100 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2018-07-03 17:29:43 +0100 |
commit | d82c4df61fbe367cde173c882a13f7dd774a9fe3 (patch) | |
tree | 503418f0e398e69055b3bc5711d15d58f97ec54d /cpan/Time-Local | |
parent | e82ffdf2dd0fb79939fd1f54573cc0027aec20ef (diff) | |
download | perl-d82c4df61fbe367cde173c882a13f7dd774a9fe3.tar.gz |
Upgrade Time::Local from version 1.25 to 1.28
Diffstat (limited to 'cpan/Time-Local')
-rw-r--r-- | cpan/Time-Local/lib/Time/Local.pm | 83 | ||||
-rw-r--r-- | cpan/Time-Local/t/Local.t | 608 |
2 files changed, 403 insertions, 288 deletions
diff --git a/cpan/Time-Local/lib/Time/Local.pm b/cpan/Time-Local/lib/Time/Local.pm index 65d7d58845..b5a62bb52d 100644 --- a/cpan/Time-Local/lib/Time/Local.pm +++ b/cpan/Time-Local/lib/Time/Local.pm @@ -5,12 +5,13 @@ use strict; use Carp (); use Exporter; -our $VERSION = '1.25'; +our $VERSION = '1.28'; use parent 'Exporter'; -our @EXPORT = qw( timegm timelocal ); -our @EXPORT_OK = qw( timegm_nocheck timelocal_nocheck ); +our @EXPORT = qw( timegm timelocal ); +our @EXPORT_OK + = qw( timegm_modern timelocal_modern timegm_nocheck timelocal_nocheck ); my @MonthDays = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); @@ -62,9 +63,9 @@ if ( $^O eq 'vos' ) { $Epoc = _daygm( 0, 0, 0, 1, 0, 70, 4, 0 ); } elsif ( $^O eq 'MacOS' ) { - $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 + $MaxDay *= 2; # 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) ); @@ -73,7 +74,7 @@ else { $Epoc = _daygm( gmtime(0) ); } -%Cheat = (); # clear the cache as epoc has changed +%Cheat = (); # clear the cache as epoc has changed sub _daygm { @@ -105,11 +106,16 @@ sub _timegm { sub timegm { my ( $sec, $min, $hour, $mday, $month, $year ) = @_; - if ( $year >= 1000 ) { + if ( $Options{no_year_munging} ) { $year -= 1900; } - elsif ( $year < 100 and $year >= 0 ) { - $year += ( $year > $Breakpoint ) ? $Century : $NextCentury; + else { + if ( $year >= 1000 ) { + $year -= 1900; + } + elsif ( $year < 100 and $year >= 0 ) { + $year += ( $year > $Breakpoint ) ? $Century : $NextCentury; + } } unless ( $Options{no_range_check} ) { @@ -164,6 +170,11 @@ sub timegm_nocheck { return &timegm; } +sub timegm_modern { + local $Options{no_year_munging} = 1; + return &timegm; +} + sub timelocal { my $ref_t = &timegm; my $loc_for_ref_t = _timegm( localtime($ref_t) ); @@ -184,7 +195,7 @@ sub timelocal { !$dst_off && ( ( $ref_t - SECS_PER_HOUR ) - _timegm( localtime( $loc_t - SECS_PER_HOUR ) ) < 0 ) - ) { + ) { return $loc_t - SECS_PER_HOUR; } @@ -206,6 +217,11 @@ sub timelocal_nocheck { return &timelocal; } +sub timelocal_modern { + local $Options{no_year_munging} = 1; + return &timelocal; +} + 1; # ABSTRACT: Efficiently compute time from local and GMT time @@ -222,7 +238,7 @@ Time::Local - Efficiently compute time from local and GMT time =head1 VERSION -version 1.25 +version 1.28 =head1 SYNOPSIS @@ -247,6 +263,28 @@ consistent with the values returned from C<localtime()> and C<gmtime()>. =head1 FUNCTIONS +=head2 C<timelocal_modern()> and C<timegm_modern()> + +When C<Time::Local> was first written, it was a common practice to represent +years as a two-digit value like C<99> for C<1999> or C<1> for C<2001>. This +caused all sorts of problems (google "Y2K problem" if you're very young) and +developers eventually realized that this was a terrible idea. + +The default exports of C<timelocal()> and C<timegm()> do a complicated +calculation when given a year value less than 1000. This leads to surprising +results in many cases. See L</Year Value Interpretation> for details. + +The C<time*_modern()> subs do not do this year munging and simply take the +year value as provided. + +While it would be nice to make this the default behavior, that would almost +certainly break a lot of code, so you must explicitly import these subs and +use them instead of the default C<timelocal()> and C<timegm()>. + +You are B<strongly> encouraged to use these subs in any new code which uses +this module. It will almost certainly make your code's behavior less +surprising. + =head2 C<timelocal()> and C<timegm()> This module exports two functions by default, C<timelocal()> and C<timegm()>. @@ -270,6 +308,9 @@ will be unpredictable (so don't do that). =head2 Year Value Interpretation +B<This does not apply to C<timelocal_modern> or C<timegm_modern>. Use those +exports if you want to ensure consistent behavior as your code ages.> + Strictly speaking, the year should be specified in a form consistent with C<localtime()>, i.e. the offset from 1900. In order to make the interpretation of the year easier for humans, however, who are more accustomed to seeing @@ -314,9 +355,10 @@ approximate range from Dec 1901 to Jan 2038. Both C<timelocal()> and C<timegm()> croak if given dates outside the supported range. -As of version 5.12.0, perl has stopped using the underlying time library of -the operating system it's running on and has its own implementation of those -routines with a safe range of at least +/ 2**52 (about 142 million years). +As of version 5.12.0, perl has stopped using the time implementation of the +operating system it's running on. Instead, it has its own implementation of +those routines with a safe range of at least +/- 2**52 (about 142 million +years) =head2 Ambiguous Local Times (DST) @@ -378,13 +420,17 @@ The current version was written by Graham Barr. The whole scheme for interpreting two-digit years can be considered a bug. -Bugs may be submitted through L<https://github.com/houseabsolute/Time-Local/issues>. +Bugs may be submitted at L<https://github.com/houseabsolute/Time-Local/issues>. There is a mailing list available for users of this distribution, L<mailto:datetime@perl.org>. I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>. +=head1 SOURCE + +The source code repository for Time-Local can be found at L<https://github.com/houseabsolute/Time-Local>. + =head1 AUTHOR Dave Rolsky <autarch@urth.org> @@ -411,9 +457,12 @@ Unknown <unknown@example.com> =head1 COPYRIGHT AND LICENSE -This software is copyright (c) 1997 - 2016 by Graham Barr & Dave Rolsky. +This software is copyright (c) 1997 - 2018 by Graham Barr & Dave Rolsky. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. +The full text of the license can be found in the +F<LICENSE> file included with this distribution. + =cut diff --git a/cpan/Time-Local/t/Local.t b/cpan/Time-Local/t/Local.t index 634139695f..adfb789a85 100644 --- a/cpan/Time-Local/t/Local.t +++ b/cpan/Time-Local/t/Local.t @@ -4,304 +4,370 @@ use strict; use warnings; use Config; -use Test::More 0.88; -use Time::Local; +use Test::More 0.96; +use Time::Local + qw( timegm timelocal timegm_modern timelocal_modern timegm_nocheck timelocal_nocheck ); -# Set up time values to test -my @time = ( +# Use 3 days before the start of the epoch because with Borland on +# Win32 it will work for -3600 _if_ your time zone is +01:00 (or +# greater). +my $neg_epoch_ok + = $^O eq 'VMS' ? 0 : defined( ( localtime(-259200) )[0] ) ? 1 : 0; - #year,mon,day,hour,min,sec - [ 1970, 1, 2, 0, 0, 0 ], - [ 1980, 2, 28, 12, 0, 0 ], - [ 1980, 2, 29, 12, 0, 0 ], - [ 1999, 12, 31, 23, 59, 59 ], - [ 2000, 1, 1, 0, 0, 0 ], - [ 2010, 10, 12, 14, 13, 12 ], +my $large_epoch_ok = eval { ( gmtime 2**40 )[5] == 34912 }; + +{ + my %tests = _valid_time_tests(); + for my $group ( sort keys %tests ) { + subtest( + $group, + sub { _test_group( $tests{$group} ) }, + ); + } +} - # leap day - [ 2020, 2, 29, 12, 59, 59 ], - [ 2030, 7, 4, 17, 7, 6 ], +sub _valid_time_tests { + my %tests = ( + 'simple times' => [ + [ 1970, 1, 2, 0, 0, 0 ], + [ 1980, 2, 28, 12, 0, 0 ], + [ 1980, 2, 29, 12, 0, 0 ], + [ 1999, 12, 31, 23, 59, 59 ], + [ 2000, 1, 1, 0, 0, 0 ], + [ 2010, 10, 12, 14, 13, 12 ], + ], + 'leap days' => [ + [ 2020, 2, 29, 12, 59, 59 ], + [ 2030, 7, 4, 17, 7, 6 ], + ], + 'non-integer seconds' => [ + [ 2010, 10, 12, 14, 13, 12.1 ], + [ 2010, 10, 12, 14, 13, 59.1 ], + ], + ); # The following test fails on a surprising number of systems # so it is commented out. The end of the Epoch for a 32-bit signed # implementation of time_t should be Jan 19, 2038 03:14:07 UTC. # [2038, 1, 17, 23, 59, 59], # last full day in any tz - [ 2010, 10, 12, 14, 13, 12.1 ], - [ 2010, 10, 12, 14, 13, 59.1 ], -); - -# more than 2**31 time_t - requires a 64bit safe localtime/gmtime -push @time, [ 2258, 8, 11, 1, 49, 17 ] - if $] >= 5.012000; - -my @bad_time = ( - - # month too large - [ 1995, 13, 1, 1, 1, 1 ], + # more than 2**31 time_t - requires a 64bit safe localtime/gmtime + $tests{'greater than 2**31 seconds'} = [ [ 2258, 8, 11, 1, 49, 17 ] ] + if $] >= 5.012000; - # day too large - [ 1995, 2, 30, 1, 1, 1 ], + # use vmsish 'time' makes for oddness around the Unix epoch + $tests{'simple times'}[0][2]++ + if $^O eq 'VMS'; - # hour too large - [ 1995, 2, 10, 25, 1, 1 ], + $tests{'negative epoch'} = [ + [ 1969, 12, 31, 16, 59, 59 ], + [ 1950, 4, 12, 9, 30, 31 ], + ] if $neg_epoch_ok; - # minute too large - [ 1995, 2, 10, 1, 60, 1 ], + return %tests; +} - # second too large - [ 1995, 2, 10, 1, 1, 60 ], -); +sub _test_group { + my $group = shift; + + for my $vals ( @{$group} ) { + my ( $year, $mon, $mday, $hour, $min, $sec ) = @{$vals}; + $mon--; + + # 1970 test on VOS fails + next if $^O eq 'vos' && $year == 1970; + + for my $sub (qw( timelocal timelocal_nocheck timelocal_modern )) { + subtest( + $sub, + sub { + my $time = __PACKAGE__->can($sub) + ->( $sec, $min, $hour, $mday, $mon, $year ); + + is_deeply( + [ ( localtime($time) )[ 0 .. 5 ] ], + [ int($sec), $min, $hour, $mday, $mon, $year - 1900 ], + "timelocal for @{$vals}" + ); + }, + ); + } -my @neg_time = ( + for my $sub (qw( timegm timegm_nocheck timegm_modern )) { + subtest( + $sub, + sub { + my $time = __PACKAGE__->can($sub) + ->( $sec, $min, $hour, $mday, $mon, $year ); + + is_deeply( + [ ( gmtime($time) )[ 0 .. 5 ] ], + [ int($sec), $min, $hour, $mday, $mon, $year - 1900 ], + "timegm for @{$vals}" + ); + }, + ); + } + } +} - # test negative epochs for systems that handle it - [ 1969, 12, 31, 16, 59, 59 ], - [ 1950, 4, 12, 9, 30, 31 ], +subtest( + 'bad times', + sub { + my %bad = ( + 'month too large' => [ 1995, 13, 1, 1, 1, 1 ], + 'day too large' => [ 1995, 2, 30, 1, 1, 1 ], + 'hour too large' => [ 1995, 2, 10, 25, 1, 1 ], + 'minute too large' => [ 1995, 2, 10, 1, 60, 1 ], + 'second too large' => [ 1995, 2, 10, 1, 1, 60 ], + ); + + for my $key ( sort keys %bad ) { + subtest( + $key, + sub { + my ( $year, $mon, $mday, $hour, $min, $sec ) + = @{ $bad{$key} }; + $mon--; + + local $@ = undef; + eval { timegm( $sec, $min, $hour, $mday, $mon, $year ) }; + + like( + $@, qr/.*out of range.*/, + "invalid time caused an error - @{$bad{$key}}" + ); + } + ); + } + }, ); -# Leap year tests -my @years = ( - [ 1900 => 0 ], - [ 1947 => 0 ], - [ 1996 => 1 ], - [ 2000 => 1 ], - [ 2100 => 0 ], +subtest( + 'diff between two calls', + sub { + is( + timelocal( 0, 0, 1, 1, 0, 90 ) - timelocal( 0, 0, 0, 1, 0, 90 ), + 3600, + 'one hour difference between two calls to timelocal' + ); + + is( + timelocal( 1, 2, 3, 1, 0, 100 ) + - timelocal( 1, 2, 3, 31, 11, 99 ), + 24 * 3600, + 'one day difference between two calls to timelocal' + ); + + # Diff beween Jan 1, 1980 and Mar 1, 1980 = (31 + 29 = 60 days) + is( + timegm( 0, 0, 0, 1, 2, 80 ) - timegm( 0, 0, 0, 1, 0, 80 ), + 60 * 24 * 3600, + '60 day difference between two calls to timegm' + ); + }, ); -# Use 3 days before the start of the epoch because with Borland on -# Win32 it will work for -3600 _if_ your time zone is +01:00 (or -# greater). -my $neg_epoch_ok = defined( ( localtime(-259200) )[0] ) ? 1 : 0; - -# use vmsish 'time' makes for oddness around the Unix epoch -if ( $^O eq 'VMS' ) { - $time[0][2]++; - $neg_epoch_ok = 0; # time_t is unsigned -} - -my $epoch_is_64 - = eval { $Config{ivsize} == 8 && ( gmtime 2**40 )[5] == 34912 }; - -for ( @time, @neg_time ) { - my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_; - $year -= 1900; - $mon--; - -SKIP: { - skip '1970 test on VOS fails.', 12 - if $^O eq 'vos' && $year == 70; - skip 'this platform does not support negative epochs.', 12 - if $year < 70 && !$neg_epoch_ok; - - # Test timelocal() +subtest( + 'DST transition bug - https://rt.perl.org/Ticket/Display.html?id=19393', + sub { + # At a DST transition, the clock skips forward, eg from 01:59:59 to + # 03:00:00. In this case, 02:00:00 is an invalid time, and should be + # treated like 03:00:00 rather than 01:00:00 - negative zone offsets + # used to do the latter. { - my $year_in = $year < 70 ? $year + 1900 : $year; - my $time = timelocal( $sec, $min, $hour, $mday, $mon, $year_in ); - - my ( $s, $m, $h, $D, $M, $Y ) = localtime($time); + my $hour = ( localtime( timelocal( 0, 0, 2, 7, 3, 102 ) ) )[2]; - is( $s, int($sec), "timelocal second for @$_" ); - is( $m, $min, "timelocal minute for @$_" ); - is( $h, $hour, "timelocal hour for @$_" ); - is( $D, $mday, "timelocal day for @$_" ); - is( $M, $mon, "timelocal month for @$_" ); - is( $Y, $year, "timelocal year for @$_" ); + # testers in US/Pacific should get 3, + # other testers should get 2 + ok( $hour == 2 || $hour == 3, 'hour should be 2 or 3' ); } + }, +); - # Test timegm() - { - my $year_in = $year < 70 ? $year + 1900 : $year; - my $time = timegm( $sec, $min, $hour, $mday, $mon, $year_in ); - - my ( $s, $m, $h, $D, $M, $Y ) = gmtime($time); - - is( $s, int($sec), "timegm second for @$_" ); - is( $m, $min, "timegm minute for @$_" ); - is( $h, $hour, "timegm hour for @$_" ); - is( $D, $mday, "timegm day for @$_" ); - is( $M, $mon, "timegm month for @$_" ); - is( $Y, $year, "timegm year for @$_" ); +subtest( + 'Time::Local::_is_leap_year', + sub { + my @years = ( + [ 1900 => 0 ], + [ 1947 => 0 ], + [ 1996 => 1 ], + [ 2000 => 1 ], + [ 2100 => 0 ], + ); + + for my $p (@years) { + my ( $year, $is_leap_year ) = @$p; + + my $string = $is_leap_year ? 'is' : 'is not'; + ## no critic (Subroutines::ProtectPrivateSubs) + is( + Time::Local::_is_leap_year($year), $is_leap_year, + "$year $string a leap year" + ); } } -} - -for (@bad_time) { - my ( $year, $mon, $mday, $hour, $min, $sec ) = @$_; - $year -= 1900; - $mon--; - - eval { timegm( $sec, $min, $hour, $mday, $mon, $year ) }; - - like( $@, qr/.*out of range.*/, 'invalid time caused an error' ); -} - -{ - is( - timelocal( 0, 0, 1, 1, 0, 90 ) - timelocal( 0, 0, 0, 1, 0, 90 ), 3600, - 'one hour difference between two calls to timelocal' - ); - - is( - timelocal( 1, 2, 3, 1, 0, 100 ) - timelocal( 1, 2, 3, 31, 11, 99 ), - 24 * 3600, - 'one day difference between two calls to timelocal' - ); - - # Diff beween Jan 1, 1980 and Mar 1, 1980 = (31 + 29 = 60 days) - is( - timegm( 0, 0, 0, 1, 2, 80 ) - timegm( 0, 0, 0, 1, 0, 80 ), - 60 * 24 * 3600, - '60 day difference between two calls to timegm' - ); -} - -# bugid #19393 -# At a DST transition, the clock skips forward, eg from 01:59:59 to -# 03:00:00. In this case, 02:00:00 is an invalid time, and should be -# treated like 03:00:00 rather than 01:00:00 - negative zone offsets used -# to do the latter -{ - my $hour = ( localtime( timelocal( 0, 0, 2, 7, 3, 102 ) ) )[2]; - - # testers in US/Pacific should get 3, - # other testers should get 2 - ok( $hour == 2 || $hour == 3, 'hour should be 2 or 3' ); -} - -for my $p (@years) { - my ( $year, $is_leap_year ) = @$p; - - my $string = $is_leap_year ? 'is' : 'is not'; - ## no critic (Subroutines::ProtectPrivateSubs) - is( - Time::Local::_is_leap_year($year), $is_leap_year, - "$year $string a leap year" - ); -} - -SKIP: -{ - skip 'this platform does not support negative epochs.', 6 - unless $neg_epoch_ok; - - eval { timegm( 0, 0, 0, 29, 1, 1900 ) }; - like( - $@, qr/Day '29' out of range 1\.\.28/, - 'does not accept leap day in 1900' - ); - - eval { timegm( 0, 0, 0, 29, 1, 200 ) }; - like( - $@, qr/Day '29' out of range 1\.\.28/, - 'does not accept leap day in 2100 (year passed as 200)' - ); - - eval { timegm( 0, 0, 0, 29, 1, 0 ) }; - is( $@, q{}, 'no error with leap day of 2000 (year passed as 0)' ); - - eval { timegm( 0, 0, 0, 29, 1, 1904 ) }; - is( $@, q{}, 'no error with leap day of 1904' ); - - eval { timegm( 0, 0, 0, 29, 1, 4 ) }; - is( $@, q{}, 'no error with leap day of 2004 (year passed as 4)' ); - - eval { timegm( 0, 0, 0, 29, 1, 96 ) }; - is( $@, q{}, 'no error with leap day of 1996 (year passed as 96)' ); -} - -SKIP: -{ - skip 'These tests require a system with 64-bit time_t.', 3 - unless $epoch_is_64; - - is( - timegm( 8, 14, 3, 19, 0, ( 1900 + 138 ) ), 2**31, - 'can call timegm for 2**31 epoch seconds' - ); - is( - timegm( 16, 28, 6, 7, 1, ( 1900 + 206 ) ), 2**32, - 'can call timegm for 2**32 epoch seconds (on a 64-bit system)' - ); - is( - timegm( 16, 36, 0, 20, 1, ( 34912 + 1900 ) ), 2**40, - 'can call timegm for 2**40 epoch seconds (on a 64-bit system)' - ); -} - -SKIP: -{ - skip 'These tests only run for the package maintainer.', 8 - unless $ENV{MAINTAINER}; - - require POSIX; - - local $ENV{TZ} = 'Europe/Vienna'; - POSIX::tzset(); - - # 2001-10-28 02:30:00 - could be either summer or standard time, - # prefer earlier of the two, in this case summer - my $time = timelocal( 0, 30, 2, 28, 9, 101 ); - is( - $time, 1004229000, - 'timelocal prefers earlier epoch in the presence of a DST change' - ); - - local $ENV{TZ} = 'America/Chicago'; - POSIX::tzset(); - - # Same local time in America/Chicago. There is a transition here - # as well. - $time = timelocal( 0, 30, 1, 28, 9, 101 ); - is( - $time, 1004250600, - 'timelocal prefers earlier epoch in the presence of a DST change' - ); - - $time = timelocal( 0, 30, 2, 1, 3, 101 ); - is( - $time, 986113800, - 'timelocal for non-existent time gives you the time one hour later' - ); - - local $ENV{TZ} = 'Australia/Sydney'; - POSIX::tzset(); - - # 2001-03-25 02:30:00 in Australia/Sydney. This is the transition - # _to_ summer time. The southern hemisphere transitions are - # opposite those of the northern. - $time = timelocal( 0, 30, 2, 25, 2, 101 ); - is( - $time, 985447800, - 'timelocal prefers earlier epoch in the presence of a DST change' - ); - - $time = timelocal( 0, 30, 2, 28, 9, 101 ); - is( - $time, 1004200200, - 'timelocal for non-existent time gives you the time one hour later' - ); +); - local $ENV{TZ} = 'Europe/London'; - POSIX::tzset(); - $time = timelocal( localtime(1111917720) ); - is( - $time, 1111917720, - 'timelocal for round trip bug on date of DST change for Europe/London' - ); +subtest( + 'negative epochs', + sub { + plan skip_all => 'this platform does not support negative epochs.' + unless $neg_epoch_ok; + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 1900 ) }; + like( + $@, qr/Day '29' out of range 1\.\.28/, + 'does not accept leap day in 1900' + ); + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 200 ) }; + like( + $@, qr/Day '29' out of range 1\.\.28/, + 'does not accept leap day in 2100 (year passed as 200)' + ); + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 0 ) }; + is( + $@, q{}, + 'no error with leap day of 2000 (year passed as 0)' + ); + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 1904 ) }; + is( $@, q{}, 'no error with leap day of 1904' ); + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 4 ) }; + is( + $@, q{}, + 'no error with leap day of 2004 (year passed as 4)' + ); + + local $@ = undef; + eval { timegm( 0, 0, 0, 29, 1, 96 ) }; + is( + $@, q{}, + 'no error with leap day of 1996 (year passed as 96)' + ); + }, +); - # There is no 1:00 AM on this date, as it leaps forward to - # 2:00 on the DST change - this should return 2:00 per the - # docs. - is( - ( localtime( timelocal( 0, 0, 1, 27, 2, 2005 ) ) )[2], 2, - 'hour is 2 when given 1:00 AM on Europe/London date change' - ); +subtest( + 'Large epoch values', + sub { + plan skip_all => 'These tests require support for large epoch values' + unless $large_epoch_ok; + + is( + timegm( 8, 14, 3, 19, 0, 2038 ), 2**31, + 'can call timegm for 2**31 epoch seconds' + ); + is( + timegm( 16, 28, 6, 7, 1, 2106 ), 2**32, + 'can call timegm for 2**32 epoch seconds (on a 64-bit system)' + ); + is( + timegm( 16, 36, 0, 20, 1, 36812 ), 2**40, + 'can call timegm for 2**40 epoch seconds (on a 64-bit system)' + ); + }, +); - is( - ( localtime( timelocal( 0, 0, 2, 27, 2, 2005 ) ) )[2], 2, - 'hour is 2 when given 2:00 AM on Europe/London date change' - ); -} +subtest( + '2-digit years', + sub { + my $current_year = ( localtime() )[5]; + my $pre_break = ( $current_year + 49 ) - 100; + my $break = ( $current_year + 50 ) - 100; + my $post_break = ( $current_year + 51 ) - 100; + + subtest( + 'legacy year munging', + sub { + plan skip_all => 'Requires support for an large epoch values' + unless $large_epoch_ok; + + is( + ( + ( + localtime( + timelocal( 0, 0, 0, 1, 1, $pre_break ) + ) + )[5] + ), + $pre_break + 100, + "year $pre_break is treated as next century", + ); + is( + ( + ( localtime( timelocal( 0, 0, 0, 1, 1, $break ) ) )[5] + ), + $break + 100, + "year $break is treated as next century", + ); + is( + ( + ( + localtime( + timelocal( 0, 0, 0, 1, 1, $post_break ) + ) + )[5] + ), + $post_break, + "year $post_break is treated as current century", + ); + } + ); + + subtest( + 'modern', + sub { + plan skip_all => + 'Requires negative epoch support and large epoch support' + unless $neg_epoch_ok && $large_epoch_ok; + + is( + ( + ( + localtime( + timelocal_modern( 0, 0, 0, 1, 1, $pre_break ) + ) + )[5] + ) + 1900, + $pre_break, + "year $pre_break is treated as year $pre_break", + ); + is( + ( + ( + localtime( + timelocal_modern( 0, 0, 0, 1, 1, $break ) + ) + )[5] + ) + 1900, + $break, + "year $break is treated as year $break", + ); + is( + ( + ( + localtime( + timelocal_modern( + 0, 0, 0, 1, 1, $post_break + ) + ) + )[5] + ) + 1900, + $post_break, + "year $post_break is treated as year $post_break", + ); + }, + ); + }, +); done_testing(); |