diff options
author | Bernhard M. Wiedemann <bwiedemann@suse.de> | 2018-02-23 18:20:45 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-02-23 23:47:06 +0100 |
commit | a40e06ee336d608cfe0928d91d2b44112d8fd1e2 (patch) | |
tree | 4256cb0c84d3294290f188b37496c9583a9cdc7b /perl/Git.pm | |
parent | Git 2.16.2 (diff) | |
download | git-a40e06ee336d608cfe0928d91d2b44112d8fd1e2.tar.xz git-a40e06ee336d608cfe0928d91d2b44112d8fd1e2.zip |
perl: call timegm and timelocal with 4-digit year
Amazingly, timegm(gmtime(0)) is only 0 before 2020 because perl's
timegm deviates from GNU timegm(3) in how it handles years.
man Time::Local says
Whenever possible, use an absolute four digit year instead.
with a detailed explanation about ambiguity of 2-digit years above that.
Even though this ambiguity is error-prone with >50% of users getting it
wrong, it has been like this for 20+ years, so we just use 4-digit years
everywhere to be on the safe side.
We add some extra logic to cvsimport because it allows 2-digit year
input and interpreting an 18 as 1918 can be avoided easily and safely.
Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'perl/Git.pm')
-rw-r--r-- | perl/Git.pm | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/perl/Git.pm b/perl/Git.pm index ffa09ace92..df62518c71 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -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]); } |