Skip to content

Commit 6aa17fc

Browse files
wychenEric Wong
authored andcommitted
git-svn: Fix time zone in --localtime
Use numerical form of time zone to replace alphabetic time zone abbreviation generated by "%Z". "%Z" is not portable and contain ambiguity for many areas. For example, CST could be "Central Standard Time" (GMT-0600) and "China Standard Time" (GMT+0800). Alphabetic time zone abbreviation is meant for human readability, not for specifying a time zone for machines. Failed case can be illustrated like this in linux shell: > echo $TZ Asia/Taipei > date +%Z CST > env TZ=`date +%Z` date Mon Dec 19 06:03:04 CST 2011 > date Mon Dec 19 14:03:04 CST 2011 [ew: fixed bad package reference inside Git::SVN::Log] Signed-off-by: Wei-Yin Chen (陳威尹) <chen.weiyin@gmail.com> Acked-by: Eric Wong <normalperson@yhbt.net>
1 parent 83cf21f commit 6aa17fc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

git-svn.perl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ package Git::SVN;
20282028
use File::Path qw/mkpath/;
20292029
use File::Copy qw/copy/;
20302030
use IPC::Open3;
2031+
use Time::Local;
20312032
use Memoize; # core since 5.8.0, Jul 2002
20322033
use Memoize::Storable;
20332034

@@ -3286,6 +3287,14 @@ sub get_untracked {
32863287
\@out;
32873288
}
32883289

3290+
sub get_tz {
3291+
# some systmes don't handle or mishandle %z, so be creative.
3292+
my $t = shift || time;
3293+
my $gm = timelocal(gmtime($t));
3294+
my $sign = qw( + + - )[ $t <=> $gm ];
3295+
return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
3296+
}
3297+
32893298
# parse_svn_date(DATE)
32903299
# --------------------
32913300
# Given a date (in UTC) from Subversion, return a string in the format
@@ -3318,8 +3327,7 @@ sub parse_svn_date {
33183327
delete $ENV{TZ};
33193328
}
33203329

3321-
my $our_TZ =
3322-
POSIX::strftime('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
3330+
my $our_TZ = get_tz();
33233331

33243332
# This converts $epoch_in_UTC into our local timezone.
33253333
my ($sec, $min, $hour, $mday, $mon, $year,
@@ -5993,7 +6001,6 @@ package Git::SVN::Log;
59936001
use strict;
59946002
use warnings;
59956003
use POSIX qw/strftime/;
5996-
use Time::Local;
59976004
use constant commit_log_separator => ('-' x 72) . "\n";
59986005
use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
59996006
%rusers $show_commit $incremental/;
@@ -6103,11 +6110,8 @@ sub run_pager {
61036110
}
61046111

61056112
sub format_svn_date {
6106-
# some systmes don't handle or mishandle %z, so be creative.
61076113
my $t = shift || time;
6108-
my $gm = timelocal(gmtime($t));
6109-
my $sign = qw( + + - )[ $t <=> $gm ];
6110-
my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
6114+
my $gmoff = Git::SVN::get_tz($t);
61116115
return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
61126116
}
61136117

0 commit comments

Comments
 (0)