From a40e06ee336d608cfe0928d91d2b44112d8fd1e2 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Fri, 23 Feb 2018 18:20:45 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- git-cvsimport.perl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git-cvsimport.perl') diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 2d8df83172..b31613cb8a 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -601,7 +601,9 @@ sub pdate($) { 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); } -- cgit v1.2.1