Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

But you'll notice Perl has a goto. -- Larry Wall in <199710211624.JAA17833@wall.org>


devel / comp.lang.c / getFirstDayOfMonth()

SubjectAuthor
* getFirstDayOfMonth()Mike Sanders
`* Re: getFirstDayOfMonth()Kenny McCormack
 +* Re: getFirstDayOfMonth()Janis Papanagnou
 |`* Re: getFirstDayOfMonth()Keith Thompson
 | +* Re: getFirstDayOfMonth()Janis Papanagnou
 | |`* Re: getFirstDayOfMonth()Janis Papanagnou
 | | `* Re: getFirstDayOfMonth()Keith Thompson
 | |  `- Re: getFirstDayOfMonth()Janis Papanagnou
 | `- Re: getFirstDayOfMonth()Mike Sanders
 +- Re: getFirstDayOfMonth()Scott Lurndal
 +- Re: getFirstDayOfMonth()Janis Papanagnou
 +- Re: getFirstDayOfMonth()Mike Sanders
 +* Re: getFirstDayOfMonth()Mike Sanders
 |`* Re: getFirstDayOfMonth()Scott Lurndal
 | +* Re: getFirstDayOfMonth()Mike Sanders
 | |`- Re: getFirstDayOfMonth()Tim Rentsch
 | `* Re: getFirstDayOfMonth()Mike Sanders
 |  `* Re: getFirstDayOfMonth()Scott Lurndal
 |   +- Re: getFirstDayOfMonth()Janis Papanagnou
 |   +* Re: getFirstDayOfMonth()Mike Sanders
 |   |+* Re: getFirstDayOfMonth()Janis Papanagnou
 |   ||`* Re: getFirstDayOfMonth()Mike Sanders
 |   || `- Re: getFirstDayOfMonth()Janis Papanagnou
 |   |+* Re: getFirstDayOfMonth()Keith Thompson
 |   ||+* Re: getFirstDayOfMonth()Janis Papanagnou
 |   |||+* Re: getFirstDayOfMonth()David Brown
 |   ||||+* Re: getFirstDayOfMonth()Kaz Kylheku
 |   |||||`- Re: getFirstDayOfMonth()David Brown
 |   ||||+* Re: getFirstDayOfMonth()Malcolm McLean
 |   |||||`- Re: getFirstDayOfMonth()Richard Harnden
 |   ||||`- Re: getFirstDayOfMonth()Janis Papanagnou
 |   |||`* Re: getFirstDayOfMonth()Mike Sanders
 |   ||| +* Re: getFirstDayOfMonth()Scott Lurndal
 |   ||| |`* Re: getFirstDayOfMonth()Mike Sanders
 |   ||| | `* Re: getFirstDayOfMonth()Scott Lurndal
 |   ||| |  +* Re: getFirstDayOfMonth()Kaz Kylheku
 |   ||| |  |`- Re: getFirstDayOfMonth()Scott Lurndal
 |   ||| |  `* Re: getFirstDayOfMonth()Janis Papanagnou
 |   ||| |   `- Re: getFirstDayOfMonth()Scott Lurndal
 |   ||| `* Re: getFirstDayOfMonth()Janis Papanagnou
 |   |||  +- Re: getFirstDayOfMonth()Mike Sanders
 |   |||  `* Re: getFirstDayOfMonth()Mark Bourne
 |   |||   `- Re: getFirstDayOfMonth()Scott Lurndal
 |   ||`* Re: getFirstDayOfMonth()Mike Sanders
 |   || +* Re: getFirstDayOfMonth()Scott Lurndal
 |   || |+- Re: getFirstDayOfMonth()Keith Thompson
 |   || |`* Re: getFirstDayOfMonth()Mike Sanders
 |   || | +- Re: getFirstDayOfMonth()Keith Thompson
 |   || | +* Re: getFirstDayOfMonth()Mike Sanders
 |   || | |`* [OT] Re: getFirstDayOfMonth()Janis Papanagnou
 |   || | | `- Re: [OT] Re: getFirstDayOfMonth()Mike Sanders
 |   || | `* Re: getFirstDayOfMonth()Scott Lurndal
 |   || |  `- Re: getFirstDayOfMonth()Keith Thompson
 |   || `* Re: getFirstDayOfMonth()Lew Pitcher
 |   ||  +* Re: getFirstDayOfMonth()Michael S
 |   ||  |+- Re: getFirstDayOfMonth()Michael S
 |   ||  |`- Re: getFirstDayOfMonth()Tim Rentsch
 |   ||  +- Re: getFirstDayOfMonth()Mike Sanders
 |   ||  `- Re: getFirstDayOfMonth()Janis Papanagnou
 |   |+* Re: getFirstDayOfMonth()James Kuyper
 |   ||`* Re: getFirstDayOfMonth()Mike Sanders
 |   || +- Re: getFirstDayOfMonth()James Kuyper
 |   || +* Re: getFirstDayOfMonth()Keith Thompson
 |   || |`* Re: getFirstDayOfMonth()Mike Sanders
 |   || | +* Re: getFirstDayOfMonth()Kaz Kylheku
 |   || | |+- Re: getFirstDayOfMonth()Mike Sanders
 |   || | |`- Re: getFirstDayOfMonth()Scott Lurndal
 |   || | `* Re: getFirstDayOfMonth()Keith Thompson
 |   || |  `- Re: getFirstDayOfMonth()Mike Sanders
 |   || `* Re: getFirstDayOfMonth()Michael S
 |   ||  `* Re: getFirstDayOfMonth()Mike Sanders
 |   ||   `- Re: getFirstDayOfMonth()Keith Thompson
 |   |`* Re: getFirstDayOfMonth()Scott Lurndal
 |   | `* Re: getFirstDayOfMonth()Michael S
 |   |  `- Re: getFirstDayOfMonth()Scott Lurndal
 |   `- Re: getFirstDayOfMonth()Mark Bourne
 +* Re: getFirstDayOfMonth()jak
 |+* Re: getFirstDayOfMonth()Tim Rentsch
 ||`- Re: getFirstDayOfMonth()jak
 |`* Re: getFirstDayOfMonth()Peter 'Shaggy' Haywood
 | `* Re: getFirstDayOfMonth()bart
 |  `* Re: getFirstDayOfMonth()jak
 |   `* Re: getFirstDayOfMonth()jak
 |    +* Re: getFirstDayOfMonth()Spiros Bousbouras
 |    |`* Re: getFirstDayOfMonth()Keith Thompson
 |    | `- Re: getFirstDayOfMonth()Keith Thompson
 |    `* Re: getFirstDayOfMonth()Keith Thompson
 |     `- Re: getFirstDayOfMonth()Tim Rentsch
 `* Re: getFirstDayOfMonth()Kaz Kylheku
  +- Re: getFirstDayOfMonth()Peter 'Shaggy' Haywood
  `- Re: getFirstDayOfMonth()Kenny McCormack

Pages:1234
getFirstDayOfMonth()

<urrj5l$124o9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33968&group=comp.lang.c#33968

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 03:48:05 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urrj5l$124o9$1@dont-email.me>
Injection-Date: Fri, 1 Mar 2024 03:48:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b71f2dfef35270dbb072913dc1bc81a5";
logging-data="1118985"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yc+Al40SzmMmNKYQR3ibP"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:M101n5u4b2XRDMqsAKjO7HBWU84=
 by: Mike Sanders - Fri, 1 Mar 2024 03:48 UTC

Just sharing what I've learned, hope some of you can adapt
it for your own use.

Calculates the name of the weekday (Sun, Mon, etc) for the
1st day of a given month & year...

https://busybox.neocities.org/notes/get-first-day-of-month.txt

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<urssrf$1vntr$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33974&group=comp.lang.c#33974

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 15:39:27 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <urssrf$1vntr$1@news.xmission.com>
References: <urrj5l$124o9$1@dont-email.me>
Injection-Date: Fri, 1 Mar 2024 15:39:27 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2088891"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 1 Mar 2024 15:39 UTC

In article <urrj5l$124o9$1@dont-email.me>,
Mike Sanders <porkchop@invalid.foo> wrote:
>Just sharing what I've learned, hope some of you can adapt
>it for your own use.
>
>Calculates the name of the weekday (Sun, Mon, etc) for the
>1st day of a given month & year...
>
>https://busybox.neocities.org/notes/get-first-day-of-month.txt

Here's the guts of my version of the Zeller algorithm:

int day(d,m,y)
int d, m, y;
{ if (m < 3) {
m += 12;
y--;
}
return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
}

I assume the two versions end up being equivalent.

BTW, how long do you think it will be until this thread gets hijacked into
a long, acrimonious debate about what the definition of the first day of
the month is and how various cultures define it differently, and how
insensitive we are (especially, if "we" are USA Americans) to assume that
our way is the only way? A matter of hours, I suspect.

--
You know politics has really been turned upside down when you have someone in the
government with a last name of Cheney (Liz, Senator from Wyoming) who is the voice of
reason.

Re: getFirstDayOfMonth()

<ursupl$1al8k$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33975&group=comp.lang.c#33975

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:12:35 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <ursupl$1al8k$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:12:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="573b6f3271b5f86b0906bbb1ccc77221";
logging-data="1398036"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+m6dEmR/5WSWEdYyRafsZ1"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:UEY+OTxI7R3SCH4Zd/YfpxA1u4c=
In-Reply-To: <urssrf$1vntr$1@news.xmission.com>
 by: Janis Papanagnou - Fri, 1 Mar 2024 16:12 UTC

On 01.03.2024 16:39, Kenny McCormack wrote:
> In article <urrj5l$124o9$1@dont-email.me>,
> Mike Sanders <porkchop@invalid.foo> wrote:
>> Just sharing what I've learned, hope some of you can adapt
>> it for your own use.
>>
>> Calculates the name of the weekday (Sun, Mon, etc) for the
>> 1st day of a given month & year...
>>
>> https://busybox.neocities.org/notes/get-first-day-of-month.txt
>
> Here's the guts of my version of the Zeller algorithm:
>
> int day(d,m,y)
> int d, m, y;
> {
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
> }
>
> I assume the two versions end up being equivalent.

Are they?

I'm certainly irritated about the OP's final

return (f % 7) - 1;

returning values from -1 to 5. And then using these indexes
to address a C array. (Looks wrong to me, but I'm anyway
not interested in second hand copies of generally available
algorithms; there's little value.)

Janis

Re: getFirstDayOfMonth()

<877cilsypt.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33976&group=comp.lang.c#33976

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 01 Mar 2024 08:28:46 -0800
Organization: None to speak of
Lines: 39
Message-ID: <877cilsypt.fsf@nosuchdomain.example.com>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<ursupl$1al8k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="2cc05af7b21c575849b4d760831db7cf";
logging-data="1404600"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FdB1e00BiXwbPBfdK9Hrx"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:HsXYPCUCJa1fY8qD56xVppTxMcI=
sha1:0ttWC5v6ulGA7PvATl/M+vClVlc=
 by: Keith Thompson - Fri, 1 Mar 2024 16:28 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...]
>> In article <urrj5l$124o9$1@dont-email.me>,
>> Mike Sanders <porkchop@invalid.foo> wrote:
>>> Just sharing what I've learned, hope some of you can adapt
>>> it for your own use.
>>>
>>> Calculates the name of the weekday (Sun, Mon, etc) for the
>>> 1st day of a given month & year...
>>>
>>> https://busybox.neocities.org/notes/get-first-day-of-month.txt
[...]
> I'm certainly irritated about the OP's final
>
> return (f % 7) - 1;
>
> returning values from -1 to 5. And then using these indexes
> to address a C array. (Looks wrong to me, but I'm anyway
> not interested in second hand copies of generally available
> algorithms; there's little value.)

Yes, that's a bug in the original code. The program only tests for
August 2024, but the algorithm fails for June 2024, which starts on
Saturday.

One fix is to change
return (f % 7) - 1;
to:
return (f + 6) % 7;
which works correctly at least for all months of 2024.

Negative index values can be valid. For example, foo[-1] can be valid,
but only if foo is a pointer to an array element other than the first
one, not if foo is an array object.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: getFirstDayOfMonth()

<urt009$1aso9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33977&group=comp.lang.c#33977

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:33:13 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <urt009$1aso9$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<ursupl$1al8k$1@dont-email.me> <877cilsypt.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:33:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="573b6f3271b5f86b0906bbb1ccc77221";
logging-data="1405705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/P5n8njPWvGaa9TpmJkbWJ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:fUTCi5QUSY+thFAP4Vb1RAhmlY8=
In-Reply-To: <877cilsypt.fsf@nosuchdomain.example.com>
 by: Janis Papanagnou - Fri, 1 Mar 2024 16:33 UTC

On 01.03.2024 17:28, Keith Thompson wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> [...]
>>> In article <urrj5l$124o9$1@dont-email.me>,
>>> Mike Sanders <porkchop@invalid.foo> wrote:
>>>> Just sharing what I've learned, hope some of you can adapt
>>>> it for your own use.
>>>>
>>>> Calculates the name of the weekday (Sun, Mon, etc) for the
>>>> 1st day of a given month & year...
>>>>
>>>> https://busybox.neocities.org/notes/get-first-day-of-month.txt
> [...]
>> I'm certainly irritated about the OP's final
>>
>> return (f % 7) - 1;
>>
>> returning values from -1 to 5. And then using these indexes
>> to address a C array. (Looks wrong to me, but I'm anyway
>> not interested in second hand copies of generally available
>> algorithms; there's little value.)
>
> Yes, that's a bug in the original code. The program only tests for
> August 2024, but the algorithm fails for June 2024, which starts on
> Saturday.
>
> One fix is to change
> return (f % 7) - 1;
> to:
> return (f + 6) % 7;
> which works correctly at least for all months of 2024.

Yes. Though I'd have done the correction on the previous line.

int f = d + ... - 1;
return f % 7;

To me that would be clearer.

Janis

Re: getFirstDayOfMonth()

<urt07v$1avj4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33978&group=comp.lang.c#33978

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:37:17 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <urt07v$1avj4$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<ursupl$1al8k$1@dont-email.me> <877cilsypt.fsf@nosuchdomain.example.com>
<urt009$1aso9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:37:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="573b6f3271b5f86b0906bbb1ccc77221";
logging-data="1408612"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WO/0GnUfLuDD9cbYIVFWM"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:cniM5IlQdJfU14DfdaJ4vbQRrS8=
In-Reply-To: <urt009$1aso9$1@dont-email.me>
 by: Janis Papanagnou - Fri, 1 Mar 2024 16:37 UTC

On 01.03.2024 17:33, Janis Papanagnou wrote:
>
> Yes. Though I'd have done the correction on the previous line.
>
> int f = d + ... - 1;
> return f % 7;
>
> To me that would be clearer.

Or completely removing the 'd' and the '-1' since 'd' is actually
a (non-const declared) constant and equals to 1.

(Gee! Why do I mind, anyway.)

>
> Janis
>

Re: getFirstDayOfMonth()

<KEnEN.70968$LONb.54416@fx08.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33979&group=comp.lang.c#33979

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: getFirstDayOfMonth()
Newsgroups: comp.lang.c
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
Lines: 32
Message-ID: <KEnEN.70968$LONb.54416@fx08.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 01 Mar 2024 16:47:38 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 01 Mar 2024 16:47:38 GMT
X-Received-Bytes: 1793
 by: Scott Lurndal - Fri, 1 Mar 2024 16:47 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:
>In article <urrj5l$124o9$1@dont-email.me>,
>Mike Sanders <porkchop@invalid.foo> wrote:
>>Just sharing what I've learned, hope some of you can adapt
>>it for your own use.
>>
>>Calculates the name of the weekday (Sun, Mon, etc) for the
>>1st day of a given month & year...
>>
>>https://busybox.neocities.org/notes/get-first-day-of-month.txt
>
>Here's the guts of my version of the Zeller algorithm:
>
>int day(d,m,y)
>int d, m, y;
>{
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
>}
>
>I assume the two versions end up being equivalent.
>
>BTW, how long do you think it will be until this thread gets hijacked into
>a long, acrimonious debate about what the definition of the first day of
>the month is and how various cultures define it differently, and how
>insensitive we are (especially, if "we" are USA Americans) to assume that
>our way is the only way? A matter of hours, I suspect.

Seconds, it would appear, as you have highjacked your own thread.

Re: getFirstDayOfMonth()

<urt1b8$1b7rl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33981&group=comp.lang.c#33981

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:56:07 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <urt1b8$1b7rl$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 16:56:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="573b6f3271b5f86b0906bbb1ccc77221";
logging-data="1417077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vn3N1Z8q1I7am1ivV4jFa"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:xejG3cH7n/bM0Nkbk29J64fn7Eg=
In-Reply-To: <urssrf$1vntr$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 1 Mar 2024 16:56 UTC

On 01.03.2024 16:39, Kenny McCormack wrote:
>
> Here's the guts of my version of the Zeller algorithm:
>
> int day(d,m,y)
> int d, m, y;
> {
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
> }

I'm wondering what would be the better approach, using some date
functions or calculating it by a formula. (Serious question.)

I'm asking since I had previously used time-functions in another
context (determining Fri 13th dates) for such a purpose. And the
rewrite to the "first day" task is simple, and the code pattern
very flexible. Here's the Gawk counterpart just for illustration:

BEGIN { y = ARGV[1] ; m = ARGV[2]
print strftime ("%a", mktime (y " " m " 1 0 0 0"))
}

....and I'm sure you can also use this approach in C.

So what's more advantageous? - Is the domain of one or the other
approach restricted? Is one or the other more accurate? Or may
the runtime be an issue?

Janis

Re: getFirstDayOfMonth()

<urt2ku$1beu1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33983&group=comp.lang.c#33983

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:18:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urt2ku$1beu1$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
Injection-Date: Fri, 1 Mar 2024 17:18:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b71f2dfef35270dbb072913dc1bc81a5";
logging-data="1424321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+x4647vd5J0RCmLVEIbGZR"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:tBsag8NAtC6YbBIDk1qn2kM+9rc=
 by: Mike Sanders - Fri, 1 Mar 2024 17:18 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:

> Here's the guts of my version of the Zeller algorithm:
>
> int day(d,m,y)
> int d, m, y;
> {
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
> }
>
> I assume the two versions end up being equivalent.

Hey-hey Kenny!

Many thanks for sharing this, now I have something to compare it too
more thoroughly.
> BTW, how long do you think it will be until this thread gets hijacked into
> a long, acrimonious debate about what the definition of the first day of
> the month is and how various cultures define it differently, and how
> insensitive we are (especially, if "we" are USA Americans) to assume that
> our way is the only way? A matter of hours, I suspect.

Well...

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<urt2po$1beu1$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33984&group=comp.lang.c#33984

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 17:20:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urt2po$1beu1$2@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <ursupl$1al8k$1@dont-email.me> <877cilsypt.fsf@nosuchdomain.example.com>
Injection-Date: Fri, 1 Mar 2024 17:20:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b71f2dfef35270dbb072913dc1bc81a5";
logging-data="1424321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l9fmV8ISv/DMGYnM1JxYr"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:IQtLl8GQ1smrnegNaT8ASW3MR9Y=
 by: Mike Sanders - Fri, 1 Mar 2024 17:20 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:

> Yes, that's a bug in the original code. The program only tests for
> August 2024, but the algorithm fails for June 2024, which starts on
> Saturday.
>
> One fix is to change
> return (f % 7) - 1;
> to:
> return (f + 6) % 7;
> which works correctly at least for all months of 2024.
>
> Negative index values can be valid. For example, foo[-1] can be valid,
> but only if foo is a pointer to an array element other than the first
> one, not if foo is an array object.

Thanks Keith, will use this moving forward. Glad to have some extra
eyeballs on it.

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<8734t9sswj.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33986&group=comp.lang.c#33986

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 01 Mar 2024 10:34:20 -0800
Organization: None to speak of
Lines: 24
Message-ID: <8734t9sswj.fsf@nosuchdomain.example.com>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<ursupl$1al8k$1@dont-email.me>
<877cilsypt.fsf@nosuchdomain.example.com>
<urt009$1aso9$1@dont-email.me> <urt07v$1avj4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="2cc05af7b21c575849b4d760831db7cf";
logging-data="1458646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JajePjWjpeJmHH++8Q5gI"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:rPP+xt4ztYEiPYPI4wtTY6RCGps=
sha1:pWQst1acE5Luy8/z5b4en7XqRBQ=
 by: Keith Thompson - Fri, 1 Mar 2024 18:34 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> On 01.03.2024 17:33, Janis Papanagnou wrote:
>> Yes. Though I'd have done the correction on the previous line.
>>
>> int f = d + ... - 1;
>> return f % 7;
>>
>> To me that would be clearer.
>
> Or completely removing the 'd' and the '-1' since 'd' is actually
> a (non-const declared) constant and equals to 1.
>
> (Gee! Why do I mind, anyway.)

I think the point of defining 'd' is to allow for computing the day of
the week for days of the month other than the first. The code as
presented suggests a lot of opportunities for generalization (such as
handling months other than August 2024). The local variable 'd' could
be replaced by a parameter 'int mday'.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: getFirstDayOfMonth()

<urteto$1e55r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33988&group=comp.lang.c#33988

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 20:47:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urteto$1e55r$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
Injection-Date: Fri, 1 Mar 2024 20:47:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b71f2dfef35270dbb072913dc1bc81a5";
logging-data="1512635"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J7X0y53V2lZRyyAQgH0n+"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:xgzU/7ULOg11WnbeTwDBSx19FcQ=
 by: Mike Sanders - Fri, 1 Mar 2024 20:47 UTC

Kenny McCormack <gazelle@shell.xmission.com> wrote:

> Here's the guts of my version of the Zeller algorithm:
>
> int day(d,m,y)
> int d, m, y;
> {
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
> }

I've put this right to work too Kenny...

Prints calander for the given year with every 2 months adjacent

https://busybox.neocities.org/notes/adjacent-calendars.txt

Example...

Jan Feb
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
1 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28
30 31

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<urtfrt$1eg6j$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33990&group=comp.lang.c#33990

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 22:03:57 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <urtfrt$1eg6j$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<ursupl$1al8k$1@dont-email.me> <877cilsypt.fsf@nosuchdomain.example.com>
<urt009$1aso9$1@dont-email.me> <urt07v$1avj4$1@dont-email.me>
<8734t9sswj.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 21:03:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d63b5913b208007a66e59d1f1c95c79a";
logging-data="1523923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZPECZfZuGv3UtY3laKHBR"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:IzcPpHJ6Sa/kWJT1VyMa6B3GCnI=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <8734t9sswj.fsf@nosuchdomain.example.com>
 by: Janis Papanagnou - Fri, 1 Mar 2024 21:03 UTC

On 01.03.2024 19:34, Keith Thompson wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>> On 01.03.2024 17:33, Janis Papanagnou wrote:
>>> Yes. Though I'd have done the correction on the previous line.
>>>
>>> int f = d + ... - 1;
>>> return f % 7;
>>>
>>> To me that would be clearer.
>>
>> Or completely removing the 'd' and the '-1' since 'd' is actually
>> a (non-const declared) constant and equals to 1.
>>
>> (Gee! Why do I mind, anyway.)
>
> I think the point of defining 'd' is to allow for computing the day of
> the week for days of the month other than the first. The code as
> presented suggests a lot of opportunities for generalization (such as
> handling months other than August 2024). The local variable 'd' could
> be replaced by a parameter 'int mday'.

Surely I am aware of that. But the OP's code isn't addressing any
generalization (cf. "int getFirstDayOfMonth(int year, int month)").
If you'd strive for a generalization you'd define a function like
the one Kenny posted (cf. "int day(d,m,y)"). If you want a special
function (for whatever reason) as the OP did you can as well just
optimize it by reducing redundant parts. (Anyway, it's not worth
the dispute.)

Janis

Re: getFirstDayOfMonth()

<7VrEN.517245$xHn7.96511@fx14.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33992&group=comp.lang.c#33992

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: getFirstDayOfMonth()
Newsgroups: comp.lang.c
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <urteto$1e55r$1@dont-email.me>
Lines: 52
Message-ID: <7VrEN.517245$xHn7.96511@fx14.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 01 Mar 2024 21:38:11 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 01 Mar 2024 21:38:11 GMT
X-Received-Bytes: 2514
 by: Scott Lurndal - Fri, 1 Mar 2024 21:38 UTC

porkchop@invalid.foo (Mike Sanders) writes:
>Kenny McCormack <gazelle@shell.xmission.com> wrote:
>
>> Here's the guts of my version of the Zeller algorithm:
>>
>> int day(d,m,y)
>> int d, m, y;
>> {
>> if (m < 3) {
>> m += 12;
>> y--;
>> }
>> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;
>> }
>
>I've put this right to work too Kenny...
>
>Prints calander for the given year with every 2 months adjacent
>
>https://busybox.neocities.org/notes/adjacent-calendars.txt
>
>Example...
>
> Jan Feb
> Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
> 1 1 2 3 4 5
> 2 3 4 5 6 7 8 6 7 8 9 10 11 12
> 9 10 11 12 13 14 15 13 14 15 16 17 18 19
> 16 17 18 19 20 21 22 20 21 22 23 24 25 26
> 23 24 25 26 27 28 29 27 28
> 30 31

That must not have been for 2024, or you have a bug.

A calendar utility comes with most linux systems. It also supports
ISO 8601 which starts the week on Monday instead of Sunday.

https://en.wikipedia.org/wiki/ISO_8601

https://github.com/util-linux/util-linux/blob/master/misc-utils/cal.c

$ cal 2024
2024

January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 1 2
7 8 9 10 11 12 13 4 5 6 7 8 9 10 3 4 5 6 7 8 9
14 15 16 17 18 19 20 11 12 13 14 15 16 17 10 11 12 13 14 15 16
21 22 23 24 25 26 27 18 19 20 21 22 23 24 17 18 19 20 21 22 23
28 29 30 31 25 26 27 28 29 24 25 26 27 28 29 30
31

Re: getFirstDayOfMonth()

<urtij7$1etmt$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33993&group=comp.lang.c#33993

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Fri, 1 Mar 2024 21:50:31 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urtij7$1etmt$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
Injection-Date: Fri, 1 Mar 2024 21:50:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b71f2dfef35270dbb072913dc1bc81a5";
logging-data="1537757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CUFOK/xidSd8tidAWpbQf"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:biCKAaZD0u9paGzjSLOu2JrOgIs=
 by: Mike Sanders - Fri, 1 Mar 2024 21:50 UTC

Scott Lurndal <scott@slp53.sl.home> wrote:

> That must not have been for 2024, or you have a bug.

Well Scott, in the code of the link posted its displaying 2022:

int year = 2022;
> A calendar utility comes with most linux systems. It also supports
> ISO 8601 which starts the week on Monday instead of Sunday.

Yes sir, I know that. But I want to build my own instead so I can
learn more about it. Even if that means reiventing the wheel, at
least I'll learn it as I wish. Hoping not to sound contrite,
cant we all just help each other learn? Darn man.

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<urtq7q$1ggh0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33995&group=comp.lang.c#33995

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 00:00:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <urtq7q$1ggh0$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
Injection-Date: Sat, 2 Mar 2024 00:00:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2c149973da73c4eae3afd661444d5e51";
logging-data="1589792"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZLVed6JrvjqUBovqpnWtY"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:7oKcxgtsOfAQeAhY4uMU6EJnloo=
 by: Mike Sanders - Sat, 2 Mar 2024 00:00 UTC

Scott Lurndal <scott@slp53.sl.home> wrote:

> https://en.wikipedia.org/wiki/ISO_8601

Have partial ISO8601 compliance now (when using option: -D=2):

Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]

-A=NUM Number of days in advance to look ahead (366 max)
-P=NUM Number of days in the past to look back (366 max)
-D=NUM Format dates as: 1 mm/dd/yyyy, 2 yyyy/mm/dd
-S=NUM Separate date fields using: 1 Slash, 2 Dash, 3 Dot
-X=NUM Export results as: 1 TXT, 2 CSV, 3 SQL, 4 HTML
-T=TAG Filter results for 'TAG' (16 characters max)
-H Include holidays (see manual for list)
-W Include weekday abbreviations
-F Include attribute flags (see manual for details)
-C Display calendar for current year
-M Display embedded user manual

Error levels returned:

3 Option syntax errors
2 File open-read errors
1 Dates match today or matching tags
0 No dates match today or no tags match

But hey its Friday I should lighten up & have some fun:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

const char *getChineseZodiac(int year) {

const char* animals[] = {
"Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake",
"Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig"
};

return animals[year % 12];
}

int main() {

time_t now = time(NULL);
struct tm *localTime = localtime(&now);
int year = localTime->tm_year;
printf("%d Year of the %s\n", year + 1900, getChineseZodiac(year));

return 0;
}

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<uru0k6$1hpdi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33997&group=comp.lang.c#33997

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 02:49:59 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uru0k6$1hpdi$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Mar 2024 01:49:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="479d27da8b0e226b0afb7915f3ed9f31";
logging-data="1631666"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O2B91ljZC4rv4LpaeAsyW"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18.1
Cancel-Lock: sha1:Y9PoKTz8Uo8r5xhmnnAObx5KsdM=
In-Reply-To: <urssrf$1vntr$1@news.xmission.com>
 by: jak - Sat, 2 Mar 2024 01:49 UTC

Kenny McCormack ha scritto:
> In article <urrj5l$124o9$1@dont-email.me>,
> Mike Sanders <porkchop@invalid.foo> wrote:
>> Just sharing what I've learned, hope some of you can adapt
>> it for your own use.
>>
>> Calculates the name of the weekday (Sun, Mon, etc) for the
>> 1st day of a given month & year...
>>
>> https://busybox.neocities.org/notes/get-first-day-of-month.txt
>
> Here's the guts of my version of the Zeller algorithm:
>
> int day(d,m,y)
> int d, m, y;
> {
> if (m < 3) {
> m += 12;
> y--;
> }
> return (d + (13*m-27)/5 + y + y/4 - y/100 + y/400) % 7;

Hi,
I am referring in particular to this part of the equation:
y + y/4 - y/100 + y/400
Shouldn't it be calculated in a floating point and then truncated only
the final result? Because, for example, if the year is 2024, the
floating point calculation is 2514 (2514.82) while executed between
integer is 2515.

> }
>
> I assume the two versions end up being equivalent.
>
> BTW, how long do you think it will be until this thread gets hijacked into
> a long, acrimonious debate about what the definition of the first day of
> the month is and how various cultures define it differently, and how
> insensitive we are (especially, if "we" are USA Americans) to assume that
> our way is the only way? A matter of hours, I suspect.
>

Re: getFirstDayOfMonth()

<20240301180259.118@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=33999&group=comp.lang.c#33999

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 03:44:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <20240301180259.118@kylheku.com>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
Injection-Date: Sat, 2 Mar 2024 03:44:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="58ac84f67eaebf8c0aa7fad509bb93bf";
logging-data="1791045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GuqsMt3q+whWlcHhCVnct5ZoLheciqW8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:+lYFCVcjjQpIDBi4WEAN4+bO+PY=
 by: Kaz Kylheku - Sat, 2 Mar 2024 03:44 UTC

On 2024-03-01, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> int day(d,m,y)
> int d, m, y;
> {
[...]
> BTW, how long do you think it will be until this thread gets hijacked into
> a long, acrimonious debate about what the definition of the first day of
> the month is and how various cultures define it differently, and how

Pissing on new code using old-style C in 5... 4... 3....

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: getFirstDayOfMonth()

<pZGEN.500996$7sbb.11881@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34002&group=comp.lang.c#34002

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: getFirstDayOfMonth()
Newsgroups: comp.lang.c
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad> <urtq7q$1ggh0$1@dont-email.me>
Lines: 44
Message-ID: <pZGEN.500996$7sbb.11881@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 02 Mar 2024 14:46:45 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 02 Mar 2024 14:46:45 GMT
X-Received-Bytes: 1992
 by: Scott Lurndal - Sat, 2 Mar 2024 14:46 UTC

porkchop@invalid.foo (Mike Sanders) writes:
>Scott Lurndal <scott@slp53.sl.home> wrote:
>
>> https://en.wikipedia.org/wiki/ISO_8601
>
>Have partial ISO8601 compliance now (when using option: -D=2):

Nice.

>
>Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]
>
>-A=NUM Number of days in advance to look ahead (366 max)
>-P=NUM Number of days in the past to look back (366 max)
>-D=NUM Format dates as: 1 mm/dd/yyyy, 2 yyyy/mm/dd
>-S=NUM Separate date fields using: 1 Slash, 2 Dash, 3 Dot
>-X=NUM Export results as: 1 TXT, 2 CSV, 3 SQL, 4 HTML
>-T=TAG Filter results for 'TAG' (16 characters max)
>-H Include holidays (see manual for list)
>-W Include weekday abbreviations
>-F Include attribute flags (see manual for details)
>-C Display calendar for current year
>-M Display embedded user manual
>

If I may suggest:

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

'-h' or '-?' have traditionally been used to display
usage information for an utility.

>Error levels returned:
>
>3 Option syntax errors
>2 File open-read errors
>1 Dates match today or matching tags
>0 No dates match today or no tags match

For commands defined by POSIX (and generally in
unix), an exit status of zero indicates success.

Re: getFirstDayOfMonth()

<urvhbr$1umk2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34003&group=comp.lang.c#34003

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 16:41:46 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <urvhbr$1umk2$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
<urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Mar 2024 15:41:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c43324ab6799d18bb1ca3090e42c5bd0";
logging-data="2054786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z5V6+cGWNf/ilDy9yXYHZ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:LUVXd3nlypleThltljksdWfjDUI=
In-Reply-To: <pZGEN.500996$7sbb.11881@fx16.iad>
 by: Janis Papanagnou - Sat, 2 Mar 2024 15:41 UTC

On 02.03.2024 15:46, Scott Lurndal wrote:
> porkchop@invalid.foo (Mike Sanders) writes:
>>
>> Usage: DATES [-OPTIONS] FILE1 [FILE2 ...]
>>[...]
>
> If I may suggest:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
>
> '-h' or '-?' have traditionally been used to display
> usage information for an utility.

Or, since there's a mandatory file name argument, provide usage
information (also) if no argument or option is provided.

Janis

> [...]

Re: getFirstDayOfMonth()

<us00f7$21v55$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34004&group=comp.lang.c#34004

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: porkc...@invalid.foo (Mike Sanders)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 19:59:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Sender: Mike Sanders <busybox@sdf.org>
Message-ID: <us00f7$21v55$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com> <urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad> <urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
Injection-Date: Sat, 2 Mar 2024 19:59:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2c149973da73c4eae3afd661444d5e51";
logging-data="2161829"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rOW7KIa/qU3jXqO+pUmDo"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (NetBSD/9.3 (amd64))
Cancel-Lock: sha1:lhXaNmZaf73lWGSO2rNpiiG+kHw=
 by: Mike Sanders - Sat, 2 Mar 2024 19:59 UTC

Scott Lurndal <scott@slp53.sl.home> wrote:

> If I may suggest:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
>
> '-h' or '-?' have traditionally been used to display
> usage information for an utility.

Yep, it will definitely be '-?' (still working to finalize things).

Many thanks for the link too btw.
>>Error levels returned:
>>
>>3 Option syntax errors
>>2 File open-read errors
>>1 Dates match today or matching tags
>>0 No dates match today or no tags match
>
> For commands defined by POSIX (and generally in
> unix), an exit status of zero indicates success.

Oh yeah. Have been wrestling with the potential
consequences of this for a good while. I think I'm
going leave it as is because, (only speaking for
myself here) the POSIX 0 good, 1 bad is terrible.
This is perhaps the only area I've ever seen where
other OSs, like Windows, have a superior methodology
on the issue. 0/1 provides next to no nuance. But
I'm no expert, just my experience.

Thanks again for the links Scott, I'll read them this
weekend.

--
:wq
Mike Sanders

Re: getFirstDayOfMonth()

<us04rd$22som$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34005&group=comp.lang.c#34005

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 2 Mar 2024 22:14:20 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <us04rd$22som$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
<urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
<us00f7$21v55$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Mar 2024 21:14:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c43324ab6799d18bb1ca3090e42c5bd0";
logging-data="2192150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Y8mcokjovxyaI2ymdb6Vq"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:YFumAmG6qnGz6DwtKQUIG5W9QVA=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <us00f7$21v55$1@dont-email.me>
 by: Janis Papanagnou - Sat, 2 Mar 2024 21:14 UTC

On 02.03.2024 20:59, Mike Sanders wrote:
>
> Oh yeah. Have been wrestling with the potential
> consequences of this for a good while. I think I'm
> going leave it as is because, (only speaking for
> myself here) the POSIX 0 good, 1 bad is terrible.

Again you have a misconception; errors on Unix systems are
regularly indicated by any value unequal to 0, not only by 1.
That way you can differentiate any possible errors or types
of errors.

> This is perhaps the only area I've ever seen where
> other OSs, like Windows, have a superior methodology
> on the issue.

(I would be astonished. But since you haven't provided any
hint on its specific "methodology" the statement is void.)

> 0/1 provides next to no nuance.

That's why on Unixes you can and typically return more than
just two values.

> But I'm no expert, just my experience.

You haven't provided any evidence or facts of experience.

Janis

Re: getFirstDayOfMonth()

<87ttloqnnk.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34007&group=comp.lang.c#34007

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sat, 02 Mar 2024 14:22:55 -0800
Organization: None to speak of
Lines: 62
Message-ID: <87ttloqnnk.fsf@nosuchdomain.example.com>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
<urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
<us00f7$21v55$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="2b434c17323931286ed96edb164e09eb";
logging-data="2218647"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cJ5QTPuvn4ri4bveICNRP"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Xn2DwkUOB9krP1uhWUfGLgsDo5M=
sha1:RvhKKlVcMTTZInkrI/k+/sxh4Zk=
 by: Keith Thompson - Sat, 2 Mar 2024 22:22 UTC

porkchop@invalid.foo (Mike Sanders) writes:
> Scott Lurndal <scott@slp53.sl.home> wrote:
>> If I may suggest:
>>
>> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
>>
>> '-h' or '-?' have traditionally been used to display
>> usage information for an utility.
>
> Yep, it will definitely be '-?' (still working to finalize things).

I wouldn't use '-?'. The '?' character is a wildcard in most Unix
shells. If you happen to have a file in the current directory that
matches the pattern, it will expand to the name of that file. If you
don't, the behavior depends on the shell and settings.

$ ls -l
total 0
-rw-r--r-- 1 kst kst 0 Mar 2 14:14 -h
$ /bin/echo -?
-h
$

And most users of Unix-like systems won't expect '-?' to be an option;
'-h' is much more common.

> Many thanks for the link too btw.
>
>>>Error levels returned:
>>>
>>>3 Option syntax errors
>>>2 File open-read errors
>>>1 Dates match today or matching tags
>>>0 No dates match today or no tags match
>>
>> For commands defined by POSIX (and generally in
>> unix), an exit status of zero indicates success.
>
> Oh yeah. Have been wrestling with the potential
> consequences of this for a good while. I think I'm
> going leave it as is because, (only speaking for
> myself here) the POSIX 0 good, 1 bad is terrible.
> This is perhaps the only area I've ever seen where
> other OSs, like Windows, have a superior methodology
> on the issue. 0/1 provides next to no nuance. But
> I'm no expert, just my experience.

The C standard, not just POSIX, defines 0 as a successful status. If
your program is intended to work on Unix-like systems (or on Windows if
I'm not mistaken), using a status of 0 to indicate an error will cause
problems. Conventions exist for a reason.

Use 0 for success, 1 for unspecified errors, and other positive values
for more specific errors.

> Thanks again for the links Scott, I'll read them this
> weekend.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: getFirstDayOfMonth()

<us1ein$2dfo0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34015&group=comp.lang.c#34015

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED.pool-108-45-179-220.washdc.fios.verizon.net!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sun, 3 Mar 2024 04:06:31 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <us1ein$2dfo0$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
<urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
<us00f7$21v55$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 09:06:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="pool-108-45-179-220.washdc.fios.verizon.net:108.45.179.220";
logging-data="2539264"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla Thunderbird
In-Reply-To: <us00f7$21v55$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 3 Mar 2024 09:06 UTC

On 3/2/24 14:59, Mike Sanders wrote:
....
> going leave it as is because, (only speaking for
> myself here) the POSIX 0 good, 1 bad is terrible.

It would be, if that's what POSIX required. Instead, it uses 0 - good,
non-zero bad. Note that 0 representing successful results is mandated by
the C standard as well. EXIT_SUCCESS is another way of indicating
success, which might or might not be the same as 0. EXIT_FAILURE is the
only portable way to indicate failure as far as C itself is concerned,
but if you're willing to write POSIX-specific code, you can use a much
wider variety of values. The same is true of all of the other operating
systems I've written C code for (Windows and VMS, mostly).

> This is perhaps the only area I've ever seen where
> other OSs, like Windows, have a superior methodology
> on the issue. 0/1 provides next to no nuance.

The lack of nuance is apparently the result of your being unaware of the
fact that 1 is not the only permitted error return.

Keep in mind that the make utility and shells designed for Unix-like
systems (as well as many other programs targeting such systems) expect 0
for success, and may produce unexpected results if you violate that
convention.

Re: getFirstDayOfMonth()

<us1t8d$2gnh6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34018&group=comp.lang.c#34018

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED.2a00:23c5:7426:6d01:ee2f:ee1c:d988:64e5!not-for-mail
From: nntp.mbo...@spamgourmet.com (Mark Bourne)
Newsgroups: comp.lang.c
Subject: Re: getFirstDayOfMonth()
Date: Sun, 3 Mar 2024 13:17:00 +0000
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <us1t8d$2gnh6$1@dont-email.me>
References: <urrj5l$124o9$1@dont-email.me> <urssrf$1vntr$1@news.xmission.com>
<urteto$1e55r$1@dont-email.me> <7VrEN.517245$xHn7.96511@fx14.iad>
<urtq7q$1ggh0$1@dont-email.me> <pZGEN.500996$7sbb.11881@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 13:17:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2a00:23c5:7426:6d01:ee2f:ee1c:d988:64e5";
logging-data="2645542"; mail-complaints-to="abuse@eternal-september.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
SeaMonkey/2.53.18
In-Reply-To: <pZGEN.500996$7sbb.11881@fx16.iad>
 by: Mark Bourne - Sun, 3 Mar 2024 13:17 UTC

Scott Lurndal wrote:
> porkchop@invalid.foo (Mike Sanders) writes:
>> Error levels returned:
>>
>> 3 Option syntax errors
>> 2 File open-read errors
>> 1 Dates match today or matching tags
>> 0 No dates match today or no tags match
>
> For commands defined by POSIX (and generally in
> unix), an exit status of zero indicates success.

Also on Windows, an exit status of zero indicates success and non-zero
failure. From a command prompt, the status of the last command can be
accessed via the %ERRORLEVEL% environment variable (similar to $? on *nix).

--
Mark.

Pages:1234
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor