From 434f494abcc3558c73efc0e57a4338adeb402253 Mon Sep 17 00:00:00 2001 From: John Jetmore Date: Sat, 25 Apr 2020 10:42:36 -0400 Subject: [PATCH] Simplify date string creation 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 --- Changes | 3 +++ doc/base.pod | 2 +- swaks | 27 +++++++++++---------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index cac2ccbb..3fc66235 100644 --- a/Changes +++ b/Changes @@ -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) diff --git a/doc/base.pod b/doc/base.pod index 5d2d7eae..83bc35c0 100644 --- a/doc/base.pod +++ b/doc/base.pod @@ -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 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 for timezone calculations. If this module is unavailable the date string will be in GMT. =item %MESSAGEID% diff --git a/swaks b/swaks index f163f4ca..052379ae 100755 --- a/swaks +++ b/swaks @@ -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'] }, ); @@ -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