git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] do not use locale specific strftime when preparing 2822 date
@ 2006-07-07 18:53 Jakub Narebski
  2006-07-07 19:59 ` Jakub Narebski
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 18:53 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski

---

 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-05 21:22 Strange date format in git-send-email Junio C Hamano
@ 2006-07-07 18:57 ` Jakub Narebski
  2006-07-07 19:03   ` Jakub Narebski
  2006-07-07 19:08   ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 18:57 UTC (permalink / raw)
  To: git; +Cc: Jakub Narebski, Junio C Hamano

Signed-off-by: Junio C Hamano <junkio@cox.net>
Acked-by: Jakub Narebski <jnareb@gmail.com>
---
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: <7vd5cnv1v5.fsf@assigned-by-dhcp.cox.net>
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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 18:57 ` [PATCH] do not use locale specific strftime when preparing 2822 date Jakub Narebski
@ 2006-07-07 19:03   ` Jakub Narebski
  2006-07-07 19:25     ` Junio C Hamano
  2006-07-07 19:08   ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 19:03 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 18:57 ` [PATCH] do not use locale specific strftime when preparing 2822 date Jakub Narebski
  2006-07-07 19:03   ` Jakub Narebski
@ 2006-07-07 19:08   ` Junio C Hamano
  2006-07-07 20:01     ` Jakub Narebski
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2006-07-07 19:08 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

Jakub Narebski <jnareb@gmail.com> writes:

> Signed-off-by: Junio C Hamano <junkio@cox.net>
> Acked-by: Jakub Narebski <jnareb@gmail.com>
> ---
> 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: <7vd5cnv1v5.fsf@assigned-by-dhcp.cox.net>
> applied.

Good test.  Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 19:03   ` Jakub Narebski
@ 2006-07-07 19:25     ` Junio C Hamano
  2006-07-07 19:53       ` Jakub Narebski
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2006-07-07 19:25 UTC (permalink / raw)
  To: jnareb; +Cc: git

Jakub Narebski <jnareb@gmail.com> writes:

> 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.

I think you are reading ABNF wrong. <a>*<b>element means at least
<a> times and at most <b> times occurrences of element.  Exact
number of repetition is written as <n>element (which is a
short-and for <n>*<n>element).

See the definition of "hour" and friends a few lines below what
you quoted.  It is defined as "2DIGIT / obs-hour" and that is
why we say "01:23:45" not "1:23:45"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 19:25     ` Junio C Hamano
@ 2006-07-07 19:53       ` Jakub Narebski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 19:53 UTC (permalink / raw)
  To: git

Junio C Hamano wrote:

> Jakub Narebski <jnareb@gmail.com> writes:
> 
>> 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.
> 
> I think you are reading ABNF wrong. [...]
> 
> See the definition of "hour" and friends a few lines below what
> you quoted.  It is defined as "2DIGIT / obs-hour" and that is
> why we say "01:23:45" not "1:23:45"

But it is "day = [...] 2DIGIT [...]"! 

Besides, that what other mailers do (I checked the post I replied via
git-send-email to, i.e. your post). Although I don't think that it can
cause any problems, like using locale date with non US-ASCII characters
did...

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 18:53 [PATCH] do not use locale specific strftime when preparing 2822 date Jakub Narebski
@ 2006-07-07 19:59 ` Jakub Narebski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 19:59 UTC (permalink / raw)
  To: git

Disregard this email. It was send by mistake by git-send-spam^Wemail.perl

-- 
Jakub Narebski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] do not use locale specific strftime when preparing 2822 date
  2006-07-07 19:08   ` Junio C Hamano
@ 2006-07-07 20:01     ` Jakub Narebski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-07-07 20:01 UTC (permalink / raw)
  To: git

Junio C Hamano wrote:

> Jakub Narebski <jnareb@gmail.com> writes:
> 
>> Signed-off-by: Junio C Hamano <junkio@cox.net>
>> Acked-by: Jakub Narebski <jnareb@gmail.com>
>> ---
>> 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: <7vd5cnv1v5.fsf@assigned-by-dhcp.cox.net>
>> applied.
> 
> Good test.  Thanks.

By the way, patch didn't apply cleanly (some fuzz was used).
The patch I send was from _applied_ (to master) patch.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-07-07 20:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-07 18:53 [PATCH] do not use locale specific strftime when preparing 2822 date Jakub Narebski
2006-07-07 19:59 ` Jakub Narebski
  -- strict thread matches above, loose matches on Subject: below --
2006-07-05 21:22 Strange date format in git-send-email Junio C Hamano
2006-07-07 18:57 ` [PATCH] do not use locale specific strftime when preparing 2822 date Jakub Narebski
2006-07-07 19:03   ` Jakub Narebski
2006-07-07 19:25     ` Junio C Hamano
2006-07-07 19:53       ` Jakub Narebski
2006-07-07 19:08   ` Junio C Hamano
2006-07-07 20:01     ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).