{"thread":{"id":"29207","subject":"[PATCH] git-svn: Fix time zone in --localtime","startedAt":"2011-12-19T08:11:05Z","lastAt":"2012-02-12T13:49:19Z","messageCount":3,"participants":["Wei-Yin Chen (陳威尹)","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"181457","messageId":"4EEEF199.4000404@gmail.com","threadId":"29207","inReplyTo":null,"subject":"[PATCH] git-svn: Fix time zone in --localtime","fromName":"Wei-Yin Chen (陳威尹)","fromEmail":"chen.weiyin@gmail.com","sentAt":"2011-12-19T08:11:05Z","receivedAt":"2011-12-19T08:11:05Z","isPatch":true,"sender":{"key":"chen.weiyin@gmail.com","avatar":null},"body":"Use numerical form of time zone to replace alphabetic time zone\nabbreviation generated by \"%Z\". \"%Z\" is not portable and contain\nambiguity for many areas. For example, CST could be \"Central\nStandard Time\" (GMT-0600) and \"China Standard Time\" (GMT+0800).\nAlphabetic time zone abbreviation is meant for human readability,\nnot for specifying a time zone for machines.\n\nFailed case can be illustrated like this in linux shell:\n  > echo $TZ\n  Asia/Taipei\n  > date +%Z\n  CST\n  > env TZ=`date +%Z` date\n  Mon Dec 19 06:03:04 CST 2011\n  > date\n  Mon Dec 19 14:03:04 CST 2011\n\nSigned-off-by: Wei-Yin Chen (陳威尹) <chen.weiyin@gmail.com>\n---\n git-svn.perl |   18 +++++++++++-------\n 1 files changed, 11 insertions(+), 7 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex e30df22..f0b6340 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -2029,6 +2029,7 @@ use Carp qw/croak/;\n use File::Path qw/mkpath/;\n use File::Copy qw/copy/;\n use IPC::Open3;\n+use Time::Local;\n use Memoize;  # core since 5.8.0, Jul 2002\n use Memoize::Storable;\n\n@@ -3287,6 +3288,14 @@ sub get_untracked {\n \t\\@out;\n }\n\n+sub get_tz {\n+\t# some systmes don't handle or mishandle %z, so be creative.\n+\tmy $t = shift || time;\n+\tmy $gm = timelocal(gmtime($t));\n+\tmy $sign = qw( + + - )[ $t <=> $gm ];\n+\treturn sprintf(\"%s%02d%02d\", $sign, (gmtime(abs($t - $gm)))[2,1]);\n+}\n+\n # parse_svn_date(DATE)\n # --------------------\n # Given a date (in UTC) from Subversion, return a string in the format\n@@ -3319,8 +3328,7 @@ sub parse_svn_date {\n \t\t\tdelete $ENV{TZ};\n \t\t}\n\n-\t\tmy $our_TZ =\n-\t\t    POSIX::strftime('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);\n+\t\tmy $our_TZ = get_tz();\n\n \t\t# This converts $epoch_in_UTC into our local timezone.\n \t\tmy ($sec, $min, $hour, $mday, $mon, $year,\n@@ -5994,7 +6002,6 @@ package Git::SVN::Log;\n use strict;\n use warnings;\n use POSIX qw/strftime/;\n-use Time::Local;\n use constant commit_log_separator => ('-' x 72) . \"\\n\";\n use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline\n             %rusers $show_commit $incremental/;\n@@ -6104,11 +6111,8 @@ sub run_pager {\n }\n\n sub format_svn_date {\n-\t# some systmes don't handle or mishandle %z, so be creative.\n \tmy $t = shift || time;\n-\tmy $gm = timelocal(gmtime($t));\n-\tmy $sign = qw( + + - )[ $t <=> $gm ];\n-\tmy $gmoff = sprintf(\"%s%02d%02d\", $sign, (gmtime(abs($t - $gm)))[2,1]);\n+\tmy $gmoff = get_tz($t);\n \treturn strftime(\"%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)\", localtime($t));\n }\n"},{"id":"184502","messageId":"20120212081553.GA10068@dcvr.yhbt.net","threadId":"29207","inReplyTo":"4EEEF199.4000404@gmail.com","subject":"Re: [PATCH] git-svn: Fix time zone in --localtime","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2012-02-12T08:15:53Z","receivedAt":"2012-02-12T08:15:53Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"\"\\\"Wei-Yin Chen (陳威尹)\\\"\" <chen.weiyin@gmail.com> wrote:\n> Use numerical form of time zone to replace alphabetic time zone\n> abbreviation generated by \"%Z\". \"%Z\" is not portable and contain\n> ambiguity for many areas. For example, CST could be \"Central\n> Standard Time\" (GMT-0600) and \"China Standard Time\" (GMT+0800).\n> Alphabetic time zone abbreviation is meant for human readability,\n> not for specifying a time zone for machines.\n> \n> Failed case can be illustrated like this in linux shell:\n>   > echo $TZ\n>   Asia/Taipei\n>   > date +%Z\n>   CST\n>   > env TZ=`date +%Z` date\n>   Mon Dec 19 06:03:04 CST 2011\n>   > date\n>   Mon Dec 19 14:03:04 CST 2011\n> \n> Signed-off-by: Wei-Yin Chen (陳威尹) <chen.weiyin@gmail.com>\n> ---\n\nHi, sorry for the late reply, this got lost in the shuffle.\n\nThis issue seems reasonable, but did you test this change at all?\n\n>  sub format_svn_date {\n> -\t# some systmes don't handle or mishandle %z, so be creative.\n>  \tmy $t = shift || time;\n> -\tmy $gm = timelocal(gmtime($t));\n> -\tmy $sign = qw( + + - )[ $t <=> $gm ];\n> -\tmy $gmoff = sprintf(\"%s%02d%02d\", $sign, (gmtime(abs($t - $gm)))[2,1]);\n> +\tmy $gmoff = get_tz($t);\n>  \treturn strftime(\"%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)\", localtime($t));\n>  }\n\nI needed the following additional change to get things working:\n\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -6111,7 +6111,7 @@ sub run_pager {\n \n sub format_svn_date {\n \tmy $t = shift || time;\n-\tmy $gmoff = get_tz($t);\n+\tmy $gmoff = Git::SVN::get_tz($t);\n \treturn strftime(\"%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)\", localtime($t));\n }\n\nIf there are no objections, I'll squash this and push for Junio\ntomorrow.\n"},{"id":"184511","messageId":"4F37C35F.9060307@gmail.com","threadId":"29207","inReplyTo":"20120212081553.GA10068@dcvr.yhbt.net","subject":"Re: [PATCH] git-svn: Fix time zone in --localtime","fromName":"Wei-Yin Chen (陳威尹)","fromEmail":"chen.weiyin@gmail.com","sentAt":"2012-02-12T13:49:19Z","receivedAt":"2012-02-12T13:49:19Z","isPatch":true,"sender":{"key":"chen.weiyin@gmail.com","avatar":null},"body":"On 2012-02-12 16:15, Eric Wong wrote:\n> I needed the following additional change to get things working:\n>\n> --- a/git-svn.perl\n> +++ b/git-svn.perl\n> @@ -6111,7 +6111,7 @@ sub run_pager {\n>\n>   sub format_svn_date {\n>   \tmy $t = shift || time;\n> -\tmy $gmoff = get_tz($t);\n> +\tmy $gmoff = Git::SVN::get_tz($t);\n>   \treturn strftime(\"%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)\", localtime($t));\n>   }\n\nSorry, my bad. This bug of missing package reference can be triggered by \n\"git svn log\", but unfortunately I didn't test this part manually. I'll \nlearn to use the git test suite next time.\n\n>\n> If there are no objections, I'll squash this and push for Junio\n> tomorrow.\n\nExcellent. Thank you for the testing and fixing effort!\n"}]}