Skip to content

Commit 6bdca89

Browse files
jnarebJunio C Hamano
authored andcommitted
send-email: format 2822 datestring ourselves.
It is not worth trying to force C locale (and failing) just to format the 2822 datestring. This code was borrowed from /usr/bin/822-date (Ian Jackson and Klee Dienes, both in public domain), per suggestion by Eric Wong. Signed-off-by: Junio C Hamano <junkio@cox.net> Acked-by: Jakub Narebski <jnareb@gmail.com>
1 parent c9c95bb commit 6bdca89

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

git-send-email.perl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,43 @@ sub readline {
3434
package main;
3535

3636
# most mail servers generate the Date: header, but not all...
37-
$ENV{LC_ALL} = 'C';
38-
use POSIX qw/strftime/;
37+
sub format_2822_time {
38+
my ($time) = @_;
39+
my @localtm = localtime($time);
40+
my @gmttm = gmtime($time);
41+
my $localmin = $localtm[1] + $localtm[2] * 60;
42+
my $gmtmin = $gmttm[1] + $gmttm[2] * 60;
43+
if ($localtm[0] != $gmttm[0]) {
44+
die "local zone differs from GMT by a non-minute interval\n";
45+
}
46+
if ((($gmttm[6] + 1) % 7) == $localtm[6]) {
47+
$localmin += 1440;
48+
} elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) {
49+
$localmin -= 1440;
50+
} elsif ($gmttm[6] != $localtm[6]) {
51+
die "local time offset greater than or equal to 24 hours\n";
52+
}
53+
my $offset = $localmin - $gmtmin;
54+
my $offhour = $offset / 60;
55+
my $offmin = abs($offset % 60);
56+
if (abs($offhour) >= 24) {
57+
die ("local time offset greater than or equal to 24 hours\n");
58+
}
59+
60+
return sprintf("%s, %2d %s %d %02d:%02d:%02d %s%02d%02d",
61+
qw(Sun Mon Tue Wed Thu Fri Sat)[$localtm[6]],
62+
$localtm[3],
63+
qw(Jan Feb Mar Apr May Jun
64+
Jul Aug Sep Oct Nov Dec)[$localtm[4]],
65+
$localtm[5]+1900,
66+
$localtm[2],
67+
$localtm[1],
68+
$localtm[0],
69+
($offset >= 0) ? '+' : '-',
70+
abs($offhour),
71+
$offmin,
72+
);
73+
}
3974

4075
my $have_email_valid = eval { require Email::Valid; 1 };
4176
my $smtp;
@@ -387,7 +422,7 @@ sub send_message
387422
my @recipients = unique_email_list(@to);
388423
my $to = join (",\n\t", @recipients);
389424
@recipients = unique_email_list(@recipients,@cc,@bcclist);
390-
my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));
425+
my $date = format_2822_time($time++);
391426
my $gitversion = '@@GIT_VERSION@@';
392427
if ($gitversion =~ m/..GIT_VERSION../) {
393428
$gitversion = `git --version`;

0 commit comments

Comments
 (0)