Skip to content

Commit

Permalink
Merge branch 'bw/perl-timegm-timelocal-fix'
Browse files Browse the repository at this point in the history
Y2k20 fix ;-) for our perl scripts.

* bw/perl-timegm-timelocal-fix:
  perl: call timegm and timelocal with 4-digit year
  • Loading branch information
gitster committed Mar 6, 2018
2 parents 6c3e6f6 + a40e06e commit 179e1f5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contrib/examples/git-svnimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ($)
my($d) = @_;
$d =~ m#(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)#
or die "Unparseable date: $d\n";
my $y=$1; $y-=1900 if $y>1900;
my $y=$1; $y+=1900 if $y<1000;
return timegm($6||0,$5,$4,$3,$2-1,$y);
}

Expand Down
4 changes: 3 additions & 1 deletion git-cvsimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ ($)
my ($d) = @_;
m#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
or die "Unparseable date: $d\n";
my $y=$1; $y-=1900 if $y>1900;
my $y=$1;
$y+=100 if $y<70;
$y+=1900 if $y<1000;
return timegm($6||0,$5,$4,$3,$2-1,$y);
}

Expand Down
4 changes: 3 additions & 1 deletion perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ If TIME is not supplied, the current local time is used.
sub get_tz_offset {
# some systems don't handle or mishandle %z, so be creative.
my $t = shift || time;
my $gm = timegm(localtime($t));
my @t = localtime($t);
$t[5] += 1900;
my $gm = timegm(@t);
my $sign = qw( + + - )[ $gm <=> $t ];
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
}
Expand Down
2 changes: 1 addition & 1 deletion perl/Git/SVN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ sub parse_svn_date {
$ENV{TZ} = 'UTC';

my $epoch_in_UTC =
Time::Local::timelocal($S, $M, $H, $d, $m - 1, $Y - 1900);
Time::Local::timelocal($S, $M, $H, $d, $m - 1, $Y);

# Determine our local timezone (including DST) at the
# time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
Expand Down

0 comments on commit 179e1f5

Please sign in to comment.