Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit ee2ac5d

Browse files
committed
Time-Piece-1.33
1 parent e37db50 commit ee2ac5d

File tree

7 files changed

+79
-41
lines changed

7 files changed

+79
-41
lines changed

Porting/Maintainers.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ package Maintainers;
15001500
},
15011501

15021502
'Time::Piece' => {
1503-
'DISTRIBUTION' => 'ESAYM/Time-Piece-1.3203.tar.gz',
1503+
'DISTRIBUTION' => 'ESAYM/Time-Piece-1.33.tar.gz',
15041504
'FILES' => q[cpan/Time-Piece],
15051505
'EXCLUDED' => [
15061506
qw[ reverse_deps.txt ],

cpan/Time-Piece/Piece.pm

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use XSLoader ();
66
use Time::Seconds;
77
use Carp;
88
use Time::Local;
9+
use Scalar::Util qw/ blessed /;
910

1011
use Exporter ();
1112

@@ -18,7 +19,7 @@ our %EXPORT_TAGS = (
1819
':override' => 'internal',
1920
);
2021

21-
our $VERSION = '1.3203';
22+
our $VERSION = '1.33';
2223

2324
XSLoader::load( 'Time::Piece', $VERSION );
2425

@@ -63,13 +64,27 @@ sub gmtime {
6364
$class->_mktime($time, 0);
6465
}
6566

67+
68+
# Check if the supplied param is either a normal array (as returned from
69+
# localtime in list context) or a Time::Piece-like wrapper around one.
70+
#
71+
# We need to differentiate between an array ref that we can interrogate and
72+
# other blessed objects (like overloaded values).
73+
sub _is_time_struct {
74+
return 1 if ref($_[1]) eq 'ARRAY';
75+
return 1 if blessed($_[1]) && $_[1]->isa('Time::Piece');
76+
77+
return 0;
78+
}
79+
80+
6681
sub new {
6782
my $class = shift;
6883
my ($time) = @_;
6984

7085
my $self;
7186

72-
if (ref($time)) {
87+
if ($class->_is_time_struct($time)) {
7388
$self = $time->[c_islocal] ? $class->localtime($time) : $class->gmtime($time);
7489
}
7590
elsif (defined($time)) {
@@ -106,10 +121,9 @@ sub parse {
106121
sub _mktime {
107122
my ($class, $time, $islocal) = @_;
108123

109-
$class = eval { (ref $class) && (ref $class)->isa('Time::Piece') }
110-
? ref $class
111-
: $class;
112-
if (ref($time)) {
124+
$class = blessed($class) || $class;
125+
126+
if ($class->_is_time_struct($time)) {
113127
my @new_time = @$time;
114128
my @tm_parts = (@new_time[c_sec .. c_mon], $new_time[c_year]+1900);
115129
$new_time[c_epoch] = $islocal ? timelocal(@tm_parts) : timegm(@tm_parts);
@@ -639,7 +653,8 @@ sub cdate {
639653

640654
sub str_compare {
641655
my ($lhs, $rhs, $reverse) = @_;
642-
if (UNIVERSAL::isa($rhs, 'Time::Piece')) {
656+
657+
if (blessed($rhs) && $rhs->isa('Time::Piece')) {
643658
$rhs = "$rhs";
644659
}
645660
return $reverse ? $rhs cmp $lhs->cdate : $lhs->cdate cmp $rhs;
@@ -652,9 +667,6 @@ use overload
652667
sub subtract {
653668
my $time = shift;
654669
my $rhs = shift;
655-
if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
656-
$rhs = $rhs->seconds;
657-
}
658670

659671
if (shift)
660672
{
@@ -667,7 +679,7 @@ sub subtract {
667679
return $rhs - "$time";
668680
}
669681

670-
if (UNIVERSAL::isa($rhs, 'Time::Piece')) {
682+
if (blessed($rhs) && $rhs->isa('Time::Piece')) {
671683
return Time::Seconds->new($time->epoch - $rhs->epoch);
672684
}
673685
else {
@@ -679,10 +691,6 @@ sub subtract {
679691
sub add {
680692
my $time = shift;
681693
my $rhs = shift;
682-
if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
683-
$rhs = $rhs->seconds;
684-
}
685-
croak "Invalid rhs of addition: $rhs" if ref($rhs);
686694

687695
return $time->_mktime(($time->epoch + $rhs), $time->[c_islocal]);
688696
}
@@ -692,7 +700,7 @@ use overload
692700

693701
sub get_epochs {
694702
my ($lhs, $rhs, $reverse) = @_;
695-
if (!UNIVERSAL::isa($rhs, 'Time::Piece')) {
703+
unless (blessed($rhs) && $rhs->isa('Time::Piece')) {
696704
$rhs = $lhs->new($rhs);
697705
}
698706
if ($reverse) {

cpan/Time-Piece/Piece.xs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ _strptime(pTHX_ const char *buf, const char *fmt, struct tm *tm, int *got_GMT)
347347
{
348348
char c;
349349
const char *ptr;
350-
int i,
351-
len;
350+
int i;
351+
size_t len;
352352
int Ealternative, Oalternative;
353353

354354
/* There seems to be a slightly improved version at
@@ -811,12 +811,12 @@ label:
811811
for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp)
812812
{/*empty*/}
813813
if (cp - buf) {
814-
zonestr = (char *)malloc(cp - buf + 1);
814+
zonestr = (char *)malloc((size_t) (cp - buf + 1));
815815
if (!zonestr) {
816816
errno = ENOMEM;
817817
return 0;
818818
}
819-
strncpy(zonestr, buf, cp - buf);
819+
strncpy(zonestr, buf,(size_t) (cp - buf));
820820
zonestr[cp - buf] = '\0';
821821
my_tzset(aTHX);
822822
if (0 == strcmp(zonestr, "GMT")) {
@@ -921,9 +921,9 @@ return_11part_tm(pTHX_ SV ** SP, struct tm *mytm)
921921

922922
static void _populate_C_time_locale(pTHX_ HV* locales )
923923
{
924-
AV* alt_names = (AV *) SvRV( *hv_fetch(locales, "alt_month", strlen("alt_month"), 0) );
925-
AV* long_names = (AV *) SvRV( *hv_fetch(locales, "month", strlen("month"), 0) );
926-
AV* short_names = (AV *) SvRV( *hv_fetch(locales, "mon", strlen("mon"), 0) );
924+
AV* alt_names = (AV *) SvRV( *hv_fetch(locales, "alt_month", 9, 0) );
925+
AV* long_names = (AV *) SvRV( *hv_fetch(locales, "month", 5, 0) );
926+
AV* short_names = (AV *) SvRV( *hv_fetch(locales, "mon", 3, 0) );
927927
int i;
928928

929929
for (i = 0; i < 1 + (int) av_len( long_names ); i++) {
@@ -932,18 +932,18 @@ static void _populate_C_time_locale(pTHX_ HV* locales )
932932
Locale->mon[i] = SvPV_nolen( (SV *) *av_fetch(short_names, i, 0) );
933933
}
934934

935-
long_names = (AV *) SvRV( *hv_fetch(locales, "weekday", strlen("weekday"), 0) );
936-
short_names = (AV *) SvRV( *hv_fetch(locales, "wday", strlen("wday"), 0) );
935+
long_names = (AV *) SvRV( *hv_fetch(locales, "weekday", 7, 0) );
936+
short_names = (AV *) SvRV( *hv_fetch(locales, "wday", 4, 0) );
937937

938938
for (i = 0; i < 1 + (int) av_len( long_names ); i++) {
939939
Locale->wday[i] = SvPV_nolen( (SV *) *av_fetch(short_names, i, 0) );
940940
Locale->weekday[i] = SvPV_nolen( (SV *) *av_fetch(long_names, i, 0) );
941941
}
942942

943-
Locale->am = SvPV_nolen( (SV *) *hv_fetch(locales, "am", strlen("am"), 0) );
944-
Locale->pm = SvPV_nolen( (SV *) *hv_fetch(locales, "pm", strlen("pm"), 0) );
945-
Locale->AM = SvPV_nolen( (SV *) *hv_fetch(locales, "AM", strlen("AM"), 0) );
946-
Locale->PM = SvPV_nolen( (SV *) *hv_fetch(locales, "PM", strlen("PM"), 0) );
943+
Locale->am = SvPV_nolen( (SV *) *hv_fetch(locales, "am", 2, 0) );
944+
Locale->pm = SvPV_nolen( (SV *) *hv_fetch(locales, "pm", 2, 0) );
945+
Locale->AM = SvPV_nolen( (SV *) *hv_fetch(locales, "AM", 2, 0) );
946+
Locale->PM = SvPV_nolen( (SV *) *hv_fetch(locales, "PM", 2, 0) );
947947

948948
return;
949949
}
@@ -987,10 +987,10 @@ _strftime(fmt, epoch, islocal = 1)
987987
ST(0) = sv_2mortal(newSVpv(tmpbuf, len));
988988
else {
989989
/* Possibly buf overflowed - try again with a bigger buf */
990-
int fmtlen = strlen(fmt);
991-
int bufsize = fmtlen + TP_BUF_SIZE;
990+
size_t fmtlen = strlen(fmt);
991+
size_t bufsize = fmtlen + TP_BUF_SIZE;
992992
char* buf;
993-
int buflen;
993+
size_t buflen;
994994

995995
New(0, buf, bufsize, char);
996996
while (buf) {
@@ -1145,17 +1145,17 @@ _get_localization()
11451145
++mytm.tm_mon;
11461146
}
11471147

1148-
tmp = hv_store(locales, "wday", strlen("wday"), newRV_noinc((SV *) wdays), 0);
1149-
tmp = hv_store(locales, "weekday", strlen("weekday"), newRV_noinc((SV *) weekdays), 0);
1150-
tmp = hv_store(locales, "mon", strlen("mon"), newRV_noinc((SV *) mons), 0);
1151-
tmp = hv_store(locales, "month", strlen("month"), newRV_noinc((SV *) months), 0);
1152-
tmp = hv_store(locales, "alt_month", strlen("alt_month"), newRV((SV *) months), 0);
1148+
tmp = hv_store(locales, "wday", 4, newRV_noinc((SV *) wdays), 0);
1149+
tmp = hv_store(locales, "weekday", 7, newRV_noinc((SV *) weekdays), 0);
1150+
tmp = hv_store(locales, "mon", 3, newRV_noinc((SV *) mons), 0);
1151+
tmp = hv_store(locales, "month", 5, newRV_noinc((SV *) months), 0);
1152+
tmp = hv_store(locales, "alt_month", 9, newRV((SV *) months), 0);
11531153

11541154
len = strftime(buf, TP_BUF_SIZE, "%p", &mytm);
1155-
tmp = hv_store(locales, "AM", strlen("AM"), newSVpvn(buf,len), 0);
1155+
tmp = hv_store(locales, "AM", 2, newSVpvn(buf,len), 0);
11561156
mytm.tm_hour = 18;
11571157
len = strftime(buf, TP_BUF_SIZE, "%p", &mytm);
1158-
tmp = hv_store(locales, "PM", strlen("PM"), newSVpvn(buf,len), 0);
1158+
tmp = hv_store(locales, "PM", 2, newSVpvn(buf,len), 0);
11591159

11601160
if(tmp == NULL || !SvOK( (SV *) *tmp)){
11611161
croak("Failed to get localization.");

cpan/Time-Piece/Seconds.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package Time::Seconds;
22
use strict;
33

4-
our $VERSION = '1.3203';
4+
our $VERSION = '1.33';
55

66
use Exporter 5.57 'import';
77

cpan/Time-Piece/t/06subclass.t

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ for my $method (qw(new localtime gmtime)) {
3535
isa_ok($diff, $class, "yesterday via subtraction operator");
3636
}
3737

38+
{
39+
my $g = $class->gmtime;
40+
my $l = $class->localtime;
41+
42+
#via clone
43+
my $l_clone = $class->new($l);
44+
isa_ok($l_clone, $class, 'custom localtime via clone');
45+
cmp_ok("$l_clone", 'eq', "$l", 'Clones match');
46+
47+
#via clone with gmtime
48+
my $g_clone = $class->new($g);
49+
isa_ok($g_clone, $class, 'custom gmtime via clone');
50+
cmp_ok("$g_clone", 'eq', "$g", 'Clones match');
51+
}
52+
3853
{
3954
# let's verify that we can use gmtime from T::P without the export magic
4055
my $piece = Time::Piece::gmtime;

dist/Module-CoreList/lib/Module/CoreList.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17622,6 +17622,7 @@ our %delta = (
1762217622
'Test::Harness' => '3.42_01',
1762317623
'Time::HiRes' => '1.9758_01',
1762417624
'Time::Local' => '1.28',
17625+
'Time::Piece' => '1.33',
1762517626
'XSLoader' => '1.04c',
1762617627
},
1762717628
removed => {

pod/perlcdelta.pod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,20 @@ Added timelocal_modern and timegm_modern variants as optional exports. These
530530
versions do not munge years at all. They treat the year value that they are
531531
given exactly as-is.
532532

533+
=item L<Time::Piece> 1.33
534+
535+
Switch to XSLoader.
536+
537+
Fix AIX compile
538+
539+
Fix compile errors on MS
540+
541+
Use macro for buf sizes
542+
543+
Remove some compile warnings
544+
545+
SP off by 1 in C<_crt_localtime>
546+
533547
=item L<XSLoader> 1.04c
534548

535549
Fix wrong usage of C<SvREFCNT_inc_simple_NN> with a function, fixes a memory leak.

0 commit comments

Comments
 (0)