Thanks for mentioning this problem. The military timezone indicators (other than "Z") were purposely done backwards in 1999, to be compatible with Internet RFC 822 which also had them backwards and which was the standard for email at the time. RFC 5322, which is RFC 822's current version, says that because of the error these timezone indicators should all be treated as equivalent to "Z" now. So coreutils should be changed, either to follow the RFC 5322 recommendation, or to be compatible with traditional military use. The latter would make more sense since it is somewhat useful behavior and the RFC 5322 requirement is merely a SHOULD, not a MUST.

Since the RFC 822 error was fixed in 2001 when RFC 2822 came out, it is long past time to fix parse-datetime.y accordingly, so I installed the attached patch into Gnulib.
>From 61bdaa139a38d5accdcca852bc58880966611335 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 9 Aug 2019 13:47:41 -0700
Subject: [PATCH] parse-datetime: fix military timezone letters

Problem and trivial fix reported by Neil Hoggarth in:
https://lists.gnu.org/r/bug-gnulib/2019-08/msg00005.html
* lib/parse-datetime.y (military_table):
Do it the right way, not the RFC 822 way.
---
 ChangeLog               |  8 +++++++
 doc/parse-datetime.texi |  4 +++-
 lib/parse-datetime.y    | 49 ++++++++++++++++++++++-------------------
 3 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 35f870abe..7616b5efd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-08-09  Paul Eggert  <egg...@cs.ucla.edu>
+
+	parse-datetime: fix military timezone letters
+	Problem and trivial fix reported by Neil Hoggarth in:
+	https://lists.gnu.org/r/bug-gnulib/2019-08/msg00005.html
+	* lib/parse-datetime.y (military_table):
+	Do it the right way, not the RFC 822 way.
+
 2019-08-08  Eric Blake  <ebl...@redhat.com>
 
 	configmake: Avoid namespace pollution issue on mingw.
diff --git a/doc/parse-datetime.texi b/doc/parse-datetime.texi
index 193575edc..2f1147572 100644
--- a/doc/parse-datetime.texi
+++ b/doc/parse-datetime.texi
@@ -306,7 +306,9 @@ only for @samp{UTC}; for example, @samp{UTC+05:30} is equivalent to
 Time zone items other than @samp{UTC} and @samp{Z}
 are obsolescent and are not recommended, because they
 are ambiguous; for example, @samp{EST} has a different meaning in
-Australia than in the United States.  Instead, it's better to use
+Australia than in the United States, and @samp{A} has different
+meaning as a military time zone than as an obsolescent
+RFC 822 time zone.  Instead, it's better to use
 unambiguous numeric time zone corrections like @samp{-0500}, as
 described in the previous section.
 
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index 780575919..d371b9cb1 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -1160,34 +1160,37 @@ static table const time_zone_table[] =
 
 /* Military time zone table.
 
+   RFC 822 got these backwards, but RFC 5322 makes the incorrect
+   treatment optional, so do them the right way here.
+
    Note 'T' is a special case, as it is used as the separator in ISO
    8601 date and time of day representation.  */
 static table const military_table[] =
 {
-  { "A", tZONE, -HOUR ( 1) },
-  { "B", tZONE, -HOUR ( 2) },
-  { "C", tZONE, -HOUR ( 3) },
-  { "D", tZONE, -HOUR ( 4) },
-  { "E", tZONE, -HOUR ( 5) },
-  { "F", tZONE, -HOUR ( 6) },
-  { "G", tZONE, -HOUR ( 7) },
-  { "H", tZONE, -HOUR ( 8) },
-  { "I", tZONE, -HOUR ( 9) },
-  { "K", tZONE, -HOUR (10) },
-  { "L", tZONE, -HOUR (11) },
-  { "M", tZONE, -HOUR (12) },
-  { "N", tZONE,  HOUR ( 1) },
-  { "O", tZONE,  HOUR ( 2) },
-  { "P", tZONE,  HOUR ( 3) },
-  { "Q", tZONE,  HOUR ( 4) },
-  { "R", tZONE,  HOUR ( 5) },
-  { "S", tZONE,  HOUR ( 6) },
+  { "A", tZONE,  HOUR ( 1) },
+  { "B", tZONE,  HOUR ( 2) },
+  { "C", tZONE,  HOUR ( 3) },
+  { "D", tZONE,  HOUR ( 4) },
+  { "E", tZONE,  HOUR ( 5) },
+  { "F", tZONE,  HOUR ( 6) },
+  { "G", tZONE,  HOUR ( 7) },
+  { "H", tZONE,  HOUR ( 8) },
+  { "I", tZONE,  HOUR ( 9) },
+  { "K", tZONE,  HOUR (10) },
+  { "L", tZONE,  HOUR (11) },
+  { "M", tZONE,  HOUR (12) },
+  { "N", tZONE, -HOUR ( 1) },
+  { "O", tZONE, -HOUR ( 2) },
+  { "P", tZONE, -HOUR ( 3) },
+  { "Q", tZONE, -HOUR ( 4) },
+  { "R", tZONE, -HOUR ( 5) },
+  { "S", tZONE, -HOUR ( 6) },
   { "T", 'T',    0 },
-  { "U", tZONE,  HOUR ( 8) },
-  { "V", tZONE,  HOUR ( 9) },
-  { "W", tZONE,  HOUR (10) },
-  { "X", tZONE,  HOUR (11) },
-  { "Y", tZONE,  HOUR (12) },
+  { "U", tZONE, -HOUR ( 8) },
+  { "V", tZONE, -HOUR ( 9) },
+  { "W", tZONE, -HOUR (10) },
+  { "X", tZONE, -HOUR (11) },
+  { "Y", tZONE, -HOUR (12) },
   { "Z", tZONE,  HOUR ( 0) },
   { NULL, 0, 0 }
 };
-- 
2.21.0

Reply via email to