Re: [GTALUG] An anomaly with the `date` command

2024-01-31 Thread Lennart Sorensen via talk
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
> .
> 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
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread mwilson--- via talk
Hugh Redelmeier wrote:
> | From: mwilson--- via talk 
[ ... ]

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


---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread D. Hugh Redelmeier via talk
| From: Michael Galea via talk 

| Looks like its m=$((`date +%m` + 1)) for you!

Try that in December.
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread D. Hugh Redelmeier via talk
| From: mwilson--- via talk 

| 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.
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread Michael Galea via 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
.
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

---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread Colin McGregor via talk
On Tue, Jan 30, 2024 at 5:24 PM Ron / BCLUG via talk  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
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread Ron / BCLUG via 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]
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


Re: [GTALUG] An anomaly with the `date` command

2024-01-30 Thread Colin McGregor via talk
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  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
> .
> 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
---
Post to this mailing list talk@gtalug.org
Unsubscribe from this mailing list https://gtalug.org/mailman/listinfo/talk


[GTALUG] An anomaly with the `date` command

2024-01-30 Thread mwilson--- via talk
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
.
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