bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Neil Hoggarth <neil.hoggarth@gmail.com>
To: bug-gnulib@gnu.org
Subject: parse-datetime.y - Military Timezones are inverted from the correct sense
Date: Fri, 9 Aug 2019 12:31:37 +0100	[thread overview]
Message-ID: <CAHr01vNxpg4xk5KFFPOd4uPEQABxfCo3nYQQd-Sx+8vkNSLxEg@mail.gmail.com> (raw)

I have observed incorrect handling of "Military" timezones when
exercising the --date=... option of the GNU coreutils "date" utility.
I believe the underlying problem is with initialization of
"military_table[]" in the parse-datetime.y file of gnulib.

In Military Time, timezone letters "A" through "M" are supposed to
indicate zones progressively east of the prime meridian (local clocks
read some hours ahead of UTC), and "N" through "Y" progressively west
of the prime meridian (local clocks read some hours behind UTC), with
"Z" standing for the UTC+0 timezone. Reference:
https://aa.usno.navy.mil/faq/docs/world_tzones.php

Utilities using parse-datetime routines interpret correctly interpret
"Z" as UTC, but all the letters the wrong way around: zone "A" should
be one hour ahead of UTC (Paris, France when not observing DST for
example), but parse-datetime has it one hour behind:

$ TZ=UTC ./date --date='12:00A 2019-01-01'
Tue  1 Jan 13:00:00 UTC 2019
$ TZ=UTC ./date --date='12:00+0100 2019-01-01'
Tue  1 Jan 11:00:00 UTC 2019
$ TZ=UTC ./date --date='TZ="Europe/Paris" 1200 2019-01-01'
Tue  1 Jan 11:00:00 UTC 2019
$ TZ=UTC ./date --date='12:00CET 2019-01-01'
Tue  1 Jan 11:00:00 UTC 2019

Similarly, when not observing DST then US Eastern Standard Time is
5-hours behind UTC, in the "R for Romeo" timezone, but an "R" passed
to parse-datetime shifts the time 5 hours in the wrong direction:

$ TZ=UTC ./date --date='12:00R 2019-01-01'
Tue  1 Jan 07:00:00 UTC 2019
$ TZ=UTC ./date --date='12:00-0500 2019-01-01'
Tue  1 Jan 17:00:00 UTC 2019
$ TZ=UTC ./date --date='TZ="America/New_York" 12:00 2019-01-01'
Tue  1 Jan 17:00:00 UTC 2019
$ TZ=UTC ./date --date='12:00EST 2019-01-01'
Tue  1 Jan 17:00:00 UTC 2019

The following trivial change makes the routine and utilities using it
work as expected:

--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -1164,30 +1164,30 @@ static table const time_zone_table[] =
    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 }
 };

Regards,

Neil Hoggarth


             reply	other threads:[~2019-08-09 12:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-09 11:31 Neil Hoggarth [this message]
2019-08-09 14:43 ` parse-datetime.y - Military Timezones are inverted from the correct sense Assaf Gordon
2019-08-09 21:01 ` Paul Eggert
2019-08-10  2:26   ` Assaf Gordon
2019-08-10  7:46     ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHr01vNxpg4xk5KFFPOd4uPEQABxfCo3nYQQd-Sx+8vkNSLxEg@mail.gmail.com \
    --to=neil.hoggarth@gmail.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).