Skip to content

Commit

Permalink
Simplify date string creation
Browse files Browse the repository at this point in the history
Fix strange issue where GMT offset could oscillate on days of DST transition.  Time::Local is no longer used and POSIX is now required.

Fixes #17
  • Loading branch information
jetmore committed Apr 25, 2020
1 parent a359fbd commit 434f494
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -906,3 +906,6 @@
scrolling, remove stray quotes, remove the news section from index
add announcement to versions, link to both plaintext and
rendered docs, etc
* 20200425 Fix strange issue where GMT offset could oscillate on days of DST
transition. Time::Local is no longer used and POSIX is now
required (#17, deb bug 955798)
2 changes: 1 addition & 1 deletion doc/base.pod
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ Replaced with the envelope-recipient(s).

=item %DATE%

Replaced with the current time in a format suitable for inclusion in the Date: header. Note this attempts to use the standard module L<Time::Local> for timezone calculations. If this module is unavailable the date string will be in GMT.
Replaced with the current time in a format suitable for inclusion in the Date: header. Note this attempts to use the standard module L<POSIX> for timezone calculations. If this module is unavailable the date string will be in GMT.

=item %MESSAGEID%

Expand Down
27 changes: 11 additions & 16 deletions swaks
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ sub load_dependencies {
pipe => { name => "Pipe Transport", req => ['IPC::Open2'] },
socket => { name => "Socket Transport", req => ['IO::Socket'] },
ipv6 => { name => "IPv6", req => ['IO::Socket::INET6'] },
date_manip => { name => "Date Manipulation", req => ['Time::Local'] },
date_manip => { name => "Date Manipulation", req => ['POSIX'] },
hostname => { name => "Local Hostname Detection", req => ['Sys::Hostname'] },
hires_timing => { name => "High Resolution Timing", req => ['Time::HiRes'] },
);
Expand Down Expand Up @@ -3743,25 +3743,20 @@ sub get_date_string {
return($G::date_string) if (length($G::date_string) > 0);

my $et = time();
my @l = localtime($et);
my $o = 0;

if (!avail("date_manip")) {
ptrans(12, avail_str("date_manip").". Date strings will be in GMT");
@l = gmtime($et);
my @l = gmtime($et);
$G::date_string = sprintf("%s, %02d %s %d %02d:%02d:%02d %+05d",
(qw(Sun Mon Tue Wed Thu Fri Sat))[$l[6]],
$l[3],
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$l[4]],
$l[5]+1900, $l[2], $l[1], $l[0],
0);
} else {
my @g = gmtime($et);
$o = (timelocal(@l) - timelocal(@g)) / 60;
# Adjust to hours and minutes and not hours and hour-hundreths
# See debian bug 646084
$o = int($o / 60)*100 + ($o%60)*($o > 0 ? 1 : -1);
}
$G::date_string = sprintf("%s, %02d %s %d %02d:%02d:%02d %+05d",
(qw(Sun Mon Tue Wed Thu Fri Sat))[$l[6]],
$l[3],
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$l[4]],
$l[5]+1900, $l[2], $l[1], $l[0],
$o);
$G::date_string = POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($et));
}
return($G::date_string);
}

# partially Cribbed from "Programming Perl" and MIME::Base64 v2.12
Expand Down

0 comments on commit 434f494

Please sign in to comment.