summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Time/Piece.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Time/Piece.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/Time/Piece.pm40
1 files changed, 24 insertions, 16 deletions
diff --git a/Master/tlpkg/tlperl/lib/Time/Piece.pm b/Master/tlpkg/tlperl/lib/Time/Piece.pm
index 8acba86e76c..d5624636c6f 100644
--- a/Master/tlpkg/tlperl/lib/Time/Piece.pm
+++ b/Master/tlpkg/tlperl/lib/Time/Piece.pm
@@ -6,6 +6,7 @@ use XSLoader ();
use Time::Seconds;
use Carp;
use Time::Local;
+use Scalar::Util qw/ blessed /;
use Exporter ();
@@ -18,7 +19,7 @@ our %EXPORT_TAGS = (
':override' => 'internal',
);
-our $VERSION = '1.3204';
+our $VERSION = '1.33';
XSLoader::load( 'Time::Piece', $VERSION );
@@ -63,13 +64,27 @@ sub gmtime {
$class->_mktime($time, 0);
}
+
+# Check if the supplied param is either a normal array (as returned from
+# localtime in list context) or a Time::Piece-like wrapper around one.
+#
+# We need to differentiate between an array ref that we can interrogate and
+# other blessed objects (like overloaded values).
+sub _is_time_struct {
+ return 1 if ref($_[1]) eq 'ARRAY';
+ return 1 if blessed($_[1]) && $_[1]->isa('Time::Piece');
+
+ return 0;
+}
+
+
sub new {
my $class = shift;
my ($time) = @_;
my $self;
- if (ref($time)) {
+ if ($class->_is_time_struct($time)) {
$self = $time->[c_islocal] ? $class->localtime($time) : $class->gmtime($time);
}
elsif (defined($time)) {
@@ -106,10 +121,9 @@ sub parse {
sub _mktime {
my ($class, $time, $islocal) = @_;
- $class = eval { (ref $class) && (ref $class)->isa('Time::Piece') }
- ? ref $class
- : $class;
- if (ref($time)) {
+ $class = blessed($class) || $class;
+
+ if ($class->_is_time_struct($time)) {
my @new_time = @$time;
my @tm_parts = (@new_time[c_sec .. c_mon], $new_time[c_year]+1900);
$new_time[c_epoch] = $islocal ? timelocal(@tm_parts) : timegm(@tm_parts);
@@ -639,7 +653,8 @@ sub cdate {
sub str_compare {
my ($lhs, $rhs, $reverse) = @_;
- if (UNIVERSAL::isa($rhs, 'Time::Piece')) {
+
+ if (blessed($rhs) && $rhs->isa('Time::Piece')) {
$rhs = "$rhs";
}
return $reverse ? $rhs cmp $lhs->cdate : $lhs->cdate cmp $rhs;
@@ -652,9 +667,6 @@ use overload
sub subtract {
my $time = shift;
my $rhs = shift;
- if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
- $rhs = $rhs->seconds;
- }
if (shift)
{
@@ -667,7 +679,7 @@ sub subtract {
return $rhs - "$time";
}
- if (UNIVERSAL::isa($rhs, 'Time::Piece')) {
+ if (blessed($rhs) && $rhs->isa('Time::Piece')) {
return Time::Seconds->new($time->epoch - $rhs->epoch);
}
else {
@@ -679,10 +691,6 @@ sub subtract {
sub add {
my $time = shift;
my $rhs = shift;
- if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
- $rhs = $rhs->seconds;
- }
- croak "Invalid rhs of addition: $rhs" if ref($rhs);
return $time->_mktime(($time->epoch + $rhs), $time->[c_islocal]);
}
@@ -692,7 +700,7 @@ use overload
sub get_epochs {
my ($lhs, $rhs, $reverse) = @_;
- if (!UNIVERSAL::isa($rhs, 'Time::Piece')) {
+ unless (blessed($rhs) && $rhs->isa('Time::Piece')) {
$rhs = $lhs->new($rhs);
}
if ($reverse) {