summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Time
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-05-21 00:15:27 +0000
committerKarl Berry <karl@freefriends.org>2012-05-21 00:15:27 +0000
commita4c42bfb2337d37da89d789cb8cc226367994e32 (patch)
treec3eabdef5d565a4e515d2be0d9d4d0540bde0250 /Master/tlpkg/tlperl/lib/Time
parent8274475057f024d35332ac47c2e2f23ea156e6ed (diff)
perl 5.14.2 from siep
git-svn-id: svn://tug.org/texlive/trunk@26525 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Time')
-rw-r--r--Master/tlpkg/tlperl/lib/Time/HiRes.pm2
-rw-r--r--Master/tlpkg/tlperl/lib/Time/Local.pm49
-rw-r--r--Master/tlpkg/tlperl/lib/Time/Piece.pm39
-rw-r--r--Master/tlpkg/tlperl/lib/Time/Seconds.pm70
4 files changed, 123 insertions, 37 deletions
diff --git a/Master/tlpkg/tlperl/lib/Time/HiRes.pm b/Master/tlpkg/tlperl/lib/Time/HiRes.pm
index da4d45a96e8..8f2ec21331b 100644
--- a/Master/tlpkg/tlperl/lib/Time/HiRes.pm
+++ b/Master/tlpkg/tlperl/lib/Time/HiRes.pm
@@ -23,7 +23,7 @@ require DynaLoader;
stat
);
-$VERSION = '1.9719';
+$VERSION = '1.9721_01';
$XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
diff --git a/Master/tlpkg/tlperl/lib/Time/Local.pm b/Master/tlpkg/tlperl/lib/Time/Local.pm
index 96a688d92c4..0e9c4ac467c 100644
--- a/Master/tlpkg/tlperl/lib/Time/Local.pm
+++ b/Master/tlpkg/tlperl/lib/Time/Local.pm
@@ -6,7 +6,7 @@ use Config;
use strict;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK );
-$VERSION = '1.1901_01';
+$VERSION = '1.2000';
@ISA = qw( Exporter );
@EXPORT = qw( timegm timelocal );
@@ -28,8 +28,23 @@ use constant SECS_PER_MINUTE => 60;
use constant SECS_PER_HOUR => 3600;
use constant SECS_PER_DAY => 86400;
-# localtime()'s limit is the year 2**31
-my $MaxDay = 365 * (2**31);
+my $MaxDay;
+if ($] < 5.012000) {
+ my $MaxInt;
+ if ( $^O eq 'MacOS' ) {
+ # time_t is unsigned...
+ $MaxInt = ( 1 << ( 8 * $Config{ivsize} ) ) - 1;
+ }
+ else {
+ $MaxInt = ( ( 1 << ( 8 * $Config{ivsize} - 2 ) ) - 1 ) * 2 + 1;
+ }
+
+ $MaxDay = int( ( $MaxInt - ( SECS_PER_DAY / 2 ) ) / SECS_PER_DAY ) - 1;
+}
+else {
+ # recent localtime()'s limit is the year 2**31
+ $MaxDay = 365 * (2**31);
+}
# Determine the EPOC day for this machine
my $Epoc = 0;
@@ -266,6 +281,21 @@ absolute four digit year instead.
The scheme above allows interpretation of a wide range of dates,
particularly if 4-digit years are used.
+=head2 Limits of time_t
+
+On perl versions older than 5.12.0, the range of dates that can be
+actually be handled depends on the size of C<time_t> (usually a signed
+integer) on the given platform. Currently, this is 32 bits for most
+systems, yielding an 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).
+
=head2 Ambiguous Local Times (DST)
Because of DST changes, there are many time zones where the same local
@@ -288,6 +318,19 @@ for the "Europe/Paris" time zone, the local clock jumped from
If the C<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
+
+On perl version 5.12.0 and newer, negative epoch values are fully
+supported.
+
+On older versions of perl, negative epoch (C<time_t>) values, which
+are not officially supported by the POSIX standards, are known not to
+work on some systems. These include MacOS (pre-OSX) and Win32.
+
+On systems which do support negative epoch values, this module should
+be able to cope with dates before the start of the epoch, down the
+minimum value of time_t for the system.
+
=head1 IMPLEMENTATION
These routines are quite efficient and yet are always guaranteed to
diff --git a/Master/tlpkg/tlperl/lib/Time/Piece.pm b/Master/tlpkg/tlperl/lib/Time/Piece.pm
index a7a602fa2ca..a3f7fb660b0 100644
--- a/Master/tlpkg/tlperl/lib/Time/Piece.pm
+++ b/Master/tlpkg/tlperl/lib/Time/Piece.pm
@@ -1,5 +1,3 @@
-# $Id: Piece.pm 82 2009-06-27 13:20:23Z matt $
-
package Time::Piece;
use strict;
@@ -9,7 +7,6 @@ require DynaLoader;
use Time::Seconds;
use Carp;
use Time::Local;
-#use UNIVERSAL qw(isa); # Commented out for Perl 5.12.0 by JRV to avoid a deprecation warning
our @ISA = qw(Exporter DynaLoader);
@@ -22,7 +19,7 @@ our %EXPORT_TAGS = (
':override' => 'internal',
);
-our $VERSION = '1.15_01';
+our $VERSION = '1.20_01';
bootstrap Time::Piece $VERSION;
@@ -78,7 +75,7 @@ sub new {
$self = $class->localtime();
}
- return bless $self, $class;
+ return bless $self, ref($class) || $class;
}
sub parse {
@@ -102,7 +99,7 @@ sub _mktime {
: $class;
if (ref($time)) {
$time->[c_epoch] = undef;
- return wantarray ? @$time : bless [@$time, $islocal], $class;
+ return wantarray ? @$time : bless [@$time[0..9], $islocal], $class;
}
_tzset();
my @time = $islocal ?
@@ -297,7 +294,9 @@ sub tzoffset {
# Compute floating offset in hours.
#
- my $delta = 24 * (&$j(CORE::localtime $epoch) - &$j(CORE::gmtime $epoch));
+ # Note use of crt methods so the tz is properly set...
+ # See: http://perlmonks.org/?node_id=820347
+ my $delta = 24 * ($j->(_crt_localtime($epoch)) - $j->(_crt_gmtime($epoch)));
# Return value in seconds rounded to nearest minute.
return Time::Seconds->new( int($delta * 60 + ($delta >= 0 ? 0.5 : -0.5)) * 60 );
@@ -601,7 +600,12 @@ sub add_months {
if ($final_month > 11 || $final_month < 0) {
# these two ops required because we have no POSIX::floor and don't
# want to load POSIX.pm
- $num_years = int($final_month / 12);
+ if ($final_month < 0 && $final_month % 12 == 0) {
+ $num_years = int($final_month / 12) + 1;
+ }
+ else {
+ $num_years = int($final_month / 12);
+ }
$num_years-- if ($final_month < 0);
$final_month = $final_month % 12;
@@ -609,7 +613,7 @@ sub add_months {
my @vals = _mini_mktime($time->sec, $time->min, $time->hour,
$time->mday, $final_month, $time->year - 1900 + $num_years);
-# warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals)));
+ # warn(sprintf("got %d vals: %d-%d-%d %d:%d:%d [%d]\n", scalar(@vals), reverse(@vals), $time->[c_islocal]));
return scalar $time->_mktime(\@vals, $time->[c_islocal]);
}
@@ -780,10 +784,10 @@ Date comparisons are also possible, using the full suite of "<", ">",
=head2 Date Parsing
-Time::Piece links to your C library's strptime() function, allowing
+Time::Piece has a built-in strptime() function (from FreeBSD), allowing
you incredibly flexible date parsing routines. For example:
- my $t = Time::Piece->strptime("Sun 3rd Nov, 1943",
+ my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943",
"%A %drd %b, %Y");
print $t->strftime("%a, %d %b %Y");
@@ -797,6 +801,8 @@ Outputs:
For more information see "man strptime", which should be on all unix
systems.
+Alternatively look here: http://www.unix.com/man-page/FreeBSD/3/strftime/
+
=head2 YYYY-MM-DDThh:mm:ss
The ISO 8601 standard defines the date format to be YYYY-MM-DD, and
@@ -838,6 +844,17 @@ also call _tzset() in the main thread to register the environment change).
Furthermore, remember that this caveat also applies to fork(), which is
emulated by threads on Win32.
+=head2 Use of epoch seconds
+
+This module internally uses the epoch seconds system that is provided via
+the perl C<time()> function and supported by C<gmtime()> and C<localtime()>.
+
+If your perl does not support times larger than C<2^31> seconds then this
+module is likely to fail at processing dates beyond the year 2038. There are
+moves afoot to fix that in perl. Alternatively use 64 bit perl. Or if none
+of those are options, use the L<DateTime> module which has support for years
+well into the future and past.
+
=head1 AUTHOR
Matt Sergeant, matt@sergeant.org
diff --git a/Master/tlpkg/tlperl/lib/Time/Seconds.pm b/Master/tlpkg/tlperl/lib/Time/Seconds.pm
index 4aac9881cb1..1ecefa16abb 100644
--- a/Master/tlpkg/tlperl/lib/Time/Seconds.pm
+++ b/Master/tlpkg/tlperl/lib/Time/Seconds.pm
@@ -1,25 +1,22 @@
-# $Id: Seconds.pm 44 2002-09-08 20:51:38Z matt $
-
package Time::Seconds;
use strict;
use vars qw/@EXPORT @EXPORT_OK @ISA/;
-# use UNIVERSAL qw(isa); # Commented out for Perl 5.12.0 by JRV to avoid a deprecation warning.
@ISA = 'Exporter';
@EXPORT = qw(
- ONE_MINUTE
- ONE_HOUR
- ONE_DAY
- ONE_WEEK
- ONE_MONTH
- ONE_REAL_MONTH
- ONE_YEAR
- ONE_REAL_YEAR
- ONE_FINANCIAL_MONTH
- LEAP_YEAR
- NON_LEAP_YEAR
- );
+ ONE_MINUTE
+ ONE_HOUR
+ ONE_DAY
+ ONE_WEEK
+ ONE_MONTH
+ ONE_REAL_MONTH
+ ONE_YEAR
+ ONE_REAL_YEAR
+ ONE_FINANCIAL_MONTH
+ LEAP_YEAR
+ NON_LEAP_YEAR
+);
@EXPORT_OK = qw(cs_sec cs_mon);
@@ -41,10 +38,10 @@ use constant cs_mon => 1;
use overload
'fallback' => 'undef',
- '0+' => \&seconds,
- '""' => \&seconds,
- '<=>' => \&compare,
- '+' => \&add,
+ '0+' => \&seconds,
+ '""' => \&seconds,
+ '<=>' => \&compare,
+ '+' => \&add,
'-' => \&subtract,
'-=' => \&subtract_from,
'+=' => \&add_to,
@@ -150,6 +147,32 @@ sub years {
$s->days / 365.24225;
}
+sub pretty {
+ my $s = shift;
+ my $str = "";
+ if ($s < 0) {
+ $s = -$s;
+ $str = "minus ";
+ }
+ if ($s >= ONE_MINUTE) {
+ if ($s >= ONE_HOUR) {
+ if ($s >= ONE_DAY) {
+ my $days = sprintf("%d", $s->days); # does a "floor"
+ $str = $days . " days, ";
+ $s -= ($days * ONE_DAY);
+ }
+ my $hours = sprintf("%d", $s->hours);
+ $str .= $hours . " hours, ";
+ $s -= ($hours * ONE_HOUR);
+ }
+ my $mins = sprintf("%d", $s->minutes);
+ $str .= $mins . " minutes, ";
+ $s -= ($mins * ONE_MINUTE);
+ }
+ $str .= $s->seconds . " seconds";
+ return $str;
+}
+
1;
__END__
@@ -183,9 +206,9 @@ Time::Seconds also exports the following constants:
ONE_WEEK
ONE_HOUR
ONE_MINUTE
- ONE_MONTH
- ONE_YEAR
- ONE_FINANCIAL_MONTH
+ ONE_MONTH
+ ONE_YEAR
+ ONE_FINANCIAL_MONTH
LEAP_YEAR
NON_LEAP_YEAR
@@ -205,6 +228,9 @@ The following methods are available:
$val->months;
$val->financial_months; # 30 days
$val->years;
+ $val->pretty; # gives English representation of the delta
+
+The usual arithmetic (+,-,+=,-=) is also available on the objects.
The methods make the assumption that there are 24 hours in a day, 7 days in
a week, 365.24225 days in a year and 12 months in a year.