Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!panda!genrad!decvax!ima!haddock!karl From: karl@haddock Newsgroups: net.lang.c Subject: Re: Calendar Functions (simpler lea Message-ID: <86900058@haddock> Date: Thu, 18-Sep-86 09:54:00 EDT Article-I.D.: haddock.86900058 Posted: Thu Sep 18 09:54:00 1986 Date-Received: Sat, 20-Sep-86 00:15:15 EDT References: <34@vianet.UUCP> Lines: 23 Nf-ID: #R:vianet.UUCP:34:haddock:86900058:000:996 Nf-From: haddock!karl Sep 18 09:54:00 1986 vianet!devine (Bob Devine) writes: >Dave Lewis writes: >> if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) > >While this works, it is overkill. Unless you believe that your >code will make it to the year 2100, a simple test for divisibility >by 4 is sufficient. It looks like you're assuming the test is for the current year. For a general-purpose algorithm (as per the original request), Dave's code is correct. If the input is a 32-bit signed integer measuring seconds since 1970 (a common implementation of time_t), then the range is contained in (1900,2100) and the simpler algorithm works -- but this is probably not a good assumption to make; an unsigned long will reach past 2100. >If you really want an algorithm for all years, >you then need to also test for years divisible by 4000... I believe the quadrimillennium correction was never officially adopted. It's not accounted for in cal(1). Karl W. Z. Heuer (ima!haddock!karl; karl@haddock.isc.com), The Walking Lint