Re: Strange date format in git-send-email

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Strange date format in git-send-email

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:32

Jakub Narebski [off-list ref] writes:
There were two patches on the list: one hacky adding setlocale 
call (not applied), second implementing rfc-822 date in Perl.
Should be in current.
What do you mean by "should be in current"?

I specifically asked you about this issue a few days ago, even
with a patch to test out for people who are having problems, but
haven't heard back anything yet.  The issue is still on hold and
not in "current" as far as I am concerned.

    To: Jakub Narebski [off-list ref]
    Cc: git@vger.kernel.org, Eric Wong [off-list ref]
    From: Junio C Hamano [off-list ref]
    Subject: Re: [PATCH] send-email: Use setlocale in addition to
        $ENV{LC_ALL} to set locale
    Date: Sun, 02 Jul 2006 19:49:50 -0700
    Message-ID: [off-list ref]

    I was reviewing old log and noticed this topic has never been
    resolved.  Your proposal was to use POSIX::setlocale(), and
    Eric's counter-proposal was to mimic what 822-date script does,
    doing it by hand without mucking with locales, and the
    discussion seemed to have died there.  Does this still need to
    be addressed?

    My gut feeling is that it would probably be less problematic if
    we do not muck with locales at all (so drop POSIX::strftime as
    well).

    So maybe something like this (totally untested)?
    ...

[PATCH] do not use locale specific strftime when preparing 2822 date

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:42:33

Signed-off-by: Junio C Hamano <redacted>
Acked-by: Jakub Narebski <redacted>
---
This patch is sent from patched version of git-send-email.perl
with git tools 1.3.0. This patch is generated from current master
after Junio's patch 
  Message-ID: [off-list ref]
applied.

 git-send-email.perl |   41 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 3 deletions(-)

f00ff14faf86c376d0ffb3cef24d2e5a5437dfcf
diff --git a/git-send-email.perl b/git-send-email.perl
index b04b8f4..c9c1975 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -34,8 +34,43 @@ sub readline {
 package main;
 
 # most mail servers generate the Date: header, but not all...
-$ENV{LC_ALL} = 'C';
-use POSIX qw/strftime/;
+sub format_2822_time {
+	my ($time) = @_;
+	my @localtm = localtime($time);
+	my @gmttm = gmtime($time);
+	my $localmin = $localtm[1] + $localtm[2] * 60;
+	my $gmtmin = $gmttm[1] + $gmttm[2] * 60;
+	if ($localtm[0] != $gmttm[0]) {
+		die "local zone differs from GMT by a non-minute interval\n";
+	}
+	if ((($gmttm[6] + 1) % 7) == $localtm[6]) {
+		$localmin += 1440;
+	} elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) {
+		$localmin -= 1440;
+	} elsif ($gmttm[6] != $localtm[6]) {
+		die "local time offset greater than or equal to 24 hours\n";
+	}
+	my $offset = $localmin - $gmtmin;
+	my $offhour = $offset / 60;
+	my $offmin = abs($offset % 60);
+	if (abs($offhour) >= 24) {
+		die ("local time offset greater than or equal to 24 hours\n");
+	}
+
+	return sprintf("%s, %2d %s %d %02d:%02d:%02d %s%02d%02d",
+		       qw(Sun Mon Tue Wed Thu Fri Sat)[$localtm[6]],
+		       $localtm[3],
+		       qw(Jan Feb Mar Apr May Jun
+			  Jul Aug Sep Oct Nov Dec)[$localtm[4]],
+		       $localtm[5]+1900,
+		       $localtm[2],
+		       $localtm[1],
+		       $localtm[0],
+		       ($offset >= 0) ? '+' : '-',
+		       abs($offhour),
+		       $offmin,
+		       );
+}
 
 my $have_email_valid = eval { require Email::Valid; 1 };
 my $smtp;
@@ -387,7 +422,7 @@ sub send_message
 	my @recipients = unique_email_list(@to);
 	my $to = join (",\n\t", @recipients);
 	@recipients = unique_email_list(@recipients,@cc,@bcclist);
-	my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));
+	my $date = format_2822_time($time++);
 	my $gitversion = '@@GIT_VERSION@@';
 	if ($gitversion =~ m/..GIT_VERSION../) {
 	    $gitversion = `git --version`;
-- 
1.3.0

Re: [PATCH] do not use locale specific strftime when preparing 2822 date

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:42:33

It looks like it is _almost_ correct. It should be
  Date: Fri, 07 Jul 2006 20:57:55 +0200
instead of
  Date: Fri,  7 Jul 2006 20:57:55 +0200

It is "day = ([FWS] 1*2DIGIT) / obs-day" in RFC2822.

-- 
Jakub Narebski
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help