bug-coreutils@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: "Pádraig Brady" <P@draigBrady.com>
To: Larry Ploetz <lploetz@gmail.com>, 68064@debbugs.gnu.org
Subject: bug#68064: Date addition error with “day Monthname” versus “Monthname day”
Date: Wed, 27 Dec 2023 19:27:04 +0000	[thread overview]
Message-ID: <731e6945-d410-3172-622d-66bb17dac353@draigBrady.com> (raw)
In-Reply-To: <2a4bb251-3f42-4f09-bca5-000af6ae880e@gmail.com>

tag 68064 notabug
close 68064
stop

On 27/12/2023 17:29, Larry Ploetz wrote:
> It seems like there might be a problem with date addition when the base
> date is specified as “day Monthname” instead of “Monthname day”, where
> the offset is being interpreted as an absolute year value. This may be
> locale-specific.
> 
>      <hostname>:bin larry$ locale
>      LANG="en_US.UTF-8"
>      LC_COLLATE="en_US.UTF-8"
>      LC_CTYPE="en_US.UTF-8"
>      LC_MESSAGES="en_US.UTF-8"
>      LC_MONETARY="en_US.UTF-8"
>      LC_NUMERIC="en_US.UTF-8"
>      LC_TIME="en_US.UTF-8"
>      LC_ALL=
>      <hostname>:bin larry$ ./date -d "$(./date -d today +%d\ %b) + 1 day"
>      Fri Dec 28 00:00:00 LMT 0001
>      <hostname>:bin larry$ ./date -d "$(./date -d today +%b\ %d) + 1 day"
>      Thu Dec 28 00:00:00 CST 2023
>      <hostname>:bin larry$ ./date --version
>      date (GNU coreutils) 9.4.97-98d463
>      Copyright (C) 2023 Free Software Foundation, Inc.
>      License GPLv3+: GNU GPL version 3 or later<https://gnu.org/licenses/gpl.html>.
>      This is free software: you are free to change and redistribute it.
>      There is NO WARRANTY, to the extent permitted by law.

This is due to ambiguity in date input formats.
Your case is:

   $ date --debug -d "27 Dec + 1 day"
   date: parsed date part: (Y-M-D) -001-12-27
   date: parsed relative part: +1 day(s)

A slightly adjusted case highlighting the ambiguity:

   $ date --debug -d "27 Dec + 1 week"
   date: parsed date part: (Y-M-D) -001-12-27
   date: parsed relative part: +7 day(s)

So really the solution here is to avoid the ambiguity
by explicitly specifying the year, or more abstractly
specifying "today" rather than a partial date.

Another gotcha highlighted by the --debug option above is:

   date: warning: using midnight as starting time: 00:00:00
   date: starting date/time: '(Y-M-D) 0001-12-27 00:00:00'
   date: warning: when adding relative days, it is recommended to specify noon

Another gotcha is that only English month abbreviations
are supported on input, so your command will fail in other locales.

For a summary of date input issues see:
https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#The-date-command-is-not-working-right_002e
https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html#index-date-input-formats

cheers,
Pádraig




      reply	other threads:[~2023-12-27 19:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-27 17:29 bug#68064: Date addition error with “day Monthname” versus “Monthname day” Larry Ploetz
2023-12-27 19:27 ` Pádraig Brady [this message]

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-coreutils

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

  git send-email \
    --in-reply-to=731e6945-d410-3172-622d-66bb17dac353@draigBrady.com \
    --to=p@draigbrady.com \
    --cc=68064@debbugs.gnu.org \
    --cc=lploetz@gmail.com \
    /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).