An anomaly with the `date` command

Discovered when I ran my script to run pcal and refresh my next-month calendar, and got March. mwilson@ningabel:~$ date Tue 30 Jan 2024 04:23:27 PM EST mwilson@ningabel:~$ date -d'this month' +%m 01 mwilson@ningabel:~$ date -d'next month' +%m 03 mwilson@ningabel:~$ which date /usr/bin/date mwilson@ningabel:~$ date --version date (GNU coreutils) 9.1 Copyright (C) 2022 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. Written by David MacKenzie. mwilson@ningabel:~$ Running Debian 12.2.0-14 patched up to last Friday. I suppose that in a couple of days next month really will be March, and the bug will be gone.

For calendar oddities try typing the following into a BASH terminal : cal 9 1752 The seemingly odd result will be correct for what is now Halifax, Nova Scotia, but incorrect for what is now Quebec City, Quebec. Anyone know why? :-) Colin McGregor On Tue, Jan 30, 2024 at 4:30 PM mwilson--- via talk <talk@gtalug.org> wrote:
Discovered when I ran my script to run pcal and refresh my next-month calendar, and got March.
mwilson@ningabel:~$ date Tue 30 Jan 2024 04:23:27 PM EST mwilson@ningabel:~$ date -d'this month' +%m 01 mwilson@ningabel:~$ date -d'next month' +%m 03 mwilson@ningabel:~$ which date /usr/bin/date mwilson@ningabel:~$ date --version date (GNU coreutils) 9.1 Copyright (C) 2022 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.
Written by David MacKenzie. mwilson@ningabel:~$
Running Debian 12.2.0-14 patched up to last Friday. I suppose that in a couple of days next month really will be March, and the bug will be gone.
--- Post to this mailing list talk@gtalug.org Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk

Colin McGregor via talk wrote on 2024-01-30 14:14:
For calendar oddities try typing the following into a BASH terminal :
cal 9 1752
The seemingly odd result will be correct for what is now Halifax, Nova Scotia, but incorrect for what is now Quebec City, Quebec. Anyone know why?
https://en.wikipedia.org/wiki/Old_Style_1752
dropped 3–13 September to transition to the Gregorian calendar.[1]

On Tue, Jan 30, 2024 at 5:24 PM Ron / BCLUG via talk <talk@gtalug.org> wrote:
Colin McGregor via talk wrote on 2024-01-30 14:14:
For calendar oddities try typing the following into a BASH terminal :
cal 9 1752
The seemingly odd result will be correct for what is now Halifax, Nova Scotia, but incorrect for what is now Quebec City, Quebec. Anyone know why?
https://en.wikipedia.org/wiki/Old_Style_1752
dropped 3–13 September to transition to the Gregorian calendar.[1]
Yes, but only in the UK and territories they controlled. France and the territories they controlled transitioned to the Gregorian calendar in 1582. Colin.
--- Post to this mailing list talk@gtalug.org Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk

On 2024-01-30 16:30, mwilson--- via talk wrote:
Discovered when I ran my script to run pcal and refresh my next-month calendar, and got March.
mwilson@ningabel:~$ date Tue 30 Jan 2024 04:23:27 PM EST mwilson@ningabel:~$ date -d'this month' +%m 01 mwilson@ningabel:~$ date -d'next month' +%m 03 mwilson@ningabel:~$ which date /usr/bin/date mwilson@ningabel:~$ date --version date (GNU coreutils) 9.1 Copyright (C) 2022 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.
Written by David MacKenzie. mwilson@ningabel:~$
Running Debian 12.2.0-14 patched up to last Friday. I suppose that in a couple of days next month really will be March, and the bug will be gone.
--- Post to this mailing list talk@gtalug.org Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk
I think its a generic error code since: $ date -d'month' +%m $ date -d'month 1' +%m $ date -d'month 12' +%m $ date -d'month 123' +%m all yield 03 Looks like its m=$((`date +%m` + 1)) for you! -- Michael Galea

| From: Michael Galea via talk <talk@gtalug.org> | Looks like its m=$((`date +%m` + 1)) for you! Try that in December.

| From: mwilson--- via talk <talk@gtalug.org> | Discovered when I ran my script to run pcal and refresh my next-month | calendar, and got March. | | | mwilson@ningabel:~$ date | Tue 30 Jan 2024 04:23:27 PM EST | mwilson@ningabel:~$ date -d'this month' +%m | 01 | mwilson@ningabel:~$ date -d'next month' +%m | 03 | mwilson@ningabel:~$ which date | /usr/bin/date I never knew you could do this with date(1). The man page punts to the info pages (yuck). I think that "next month" adds the length of the current month to the time. This is a 31-day month, we're quite late in it, so this hops over all of February. $ date Tue 30 Jan 2024 06:46:05 PM EST $ date -d'this month' Tue 30 Jan 2024 06:46:10 PM EST $ date -d'next month' Fri 01 Mar 2024 06:46:17 PM EST What you want to do is go back to the first of the month (all modern months have a first) and then leap ahead a month. $ date --date="$(date +%Y-%m-01) next month" Thu 01 Feb 2024 12:00:00 AM EST $ date --date="$(date +%Y-%m-01) next month" +%m 02 The phony natural language that date accepts is a hazard.

Hugh Redelmeier wrote:
| From: mwilson--- via talk <talk@gtalug.org> [ ... ]
I think that "next month" adds the length of the current month to the time. This is a 31-day month, we're quite late in it, so this hops over all of February.
That makes sense. They told me to ask for "next month", but what they give me is "one month from today". Because if all I wanted was $((`date +%m` % 12 + 1)) then why the heck didn't I say so? (Hat tip to Mike Galea there.) So I can fix up my scripts. I suppose "last month" doesn't hit this problem (have to try on March 1), and that finding the right year for "last month" and "next month" will be good -- since December and January are the same length. [ ... ]
The phony natural language that date accepts is a hazard.
Couldn't agree more, the state I'm in. Also pcal gags on some perfectly natural-looking directives. Many thanks, everybody.

On Tue, Jan 30, 2024 at 04:30:31PM -0500, mwilson--- via talk wrote:
Discovered when I ran my script to run pcal and refresh my next-month calendar, and got March.
mwilson@ningabel:~$ date Tue 30 Jan 2024 04:23:27 PM EST mwilson@ningabel:~$ date -d'this month' +%m 01 mwilson@ningabel:~$ date -d'next month' +%m 03 mwilson@ningabel:~$ which date /usr/bin/date mwilson@ningabel:~$ date --version date (GNU coreutils) 9.1 Copyright (C) 2022 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.
Written by David MacKenzie. mwilson@ningabel:~$
Running Debian 12.2.0-14 patched up to last Friday. I suppose that in a couple of days next month really will be March, and the bug will be gone.
Apparently the way 'next month' works is by adding 31 days. A work around is to do this: date +"%m" --date="$(date +%Y-%m-15) next month" So use this year and this month and the 15th of the month then add 31 days. -- Len Sorensen
participants (6)
-
Colin McGregor
-
D. Hugh Redelmeier
-
Lennart Sorensen
-
Michael Galea
-
mwilson@Vex.Net
-
Ron / BCLUG