🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9367

Re: Calendar Functions

#9367
From: Guido van Rossum
Date: Mon, 22 Sep 1986 22:16
16 lines
1196 bytes
Wouldn't Jim Cottrell love this:

	#define leapyear(y) !((y)&3)

	daysinmonth(m, y) {
		if (m == 2) return 28 + leapyear(y);
		return 30 + ((1&m) ^ (m>7));
	}

Seriously, I believe that the original code, which applied the same rule
here showed a discrepancy between its seemingly clear coding style
(explaining every simple statement with a comment) and the 'trick' in
the algorithm (invert the parity of the month for months > 7).

In my eyes the solution which uses a table is the cleanest.
Technical Details
Message-ID: <7080@boring.mcvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!guido
References: <206@cascade.STANFORD.EDU> <1229@loral.UUCP> <1805@mmintl.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!guido
From: guido@mcvax.uucp (Guido van Rossum)
Newsgroups: net.lang.c
Subject: Re: Calendar Functions
Message-ID: <7080@boring.mcvax.UUCP>
Date: Mon, 22-Sep-86 18:16:42 EDT
Article-I.D.: boring.7080
Posted: Mon Sep 22 18:16:42 1986
Date-Received: Tue, 23-Sep-86 03:57:28 EDT
References: <206@cascade.STANFORD.EDU> <1229@loral.UUCP> <1805@mmintl.UUCP>
Reply-To: guido@boring.uucp (Guido van Rossum)
Distribution: net.lang.c
Organization: "Stamp Out BASIC" Committee, CWI, Amsterdam
Lines: 15
Keywords: Calendars
Summary: real programmers' solution :-)
Apparently-To: rnews@mcvax