[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ssystem bug



On Mon, Apr 27, 1998 at 06:41:38PM +0200, Axel Kielhorn wrote:
>According to my C Reference for localtime() the 1.14.7 version *is* correct
>and the table above should read:
>
>>	Day of week | 1.14.7 |
>>	------------+--------+
>>	Sunday      | 0      |
>>	Monday      | 1      |
>>	...         | ...    |
>>	Saturday    | 6      |
>
>As long as I can remember the week starts with Sunday and since programmers
>start counting with 0 this is correct.
>
>The strange thing is that the days in the month start with 1 for the first.
>Who was smoking what when writing this function?  (It is ANSI C, not K&R)

That is neither incorrect nor inconsistent.  The numbering scheme is
from the UNIX struct tm.  Since people would want to print the date
in human-readable format, the month and day-of-week values are chosen
so as to be used as indices into string arrays (i.e., char **) for the
names.  So month[0] = "Jan" and dow[0] = "Sun".  The day-of-month,
OTOH, isn't needed as an index but would be printed directly;
therefore the first of the month is 1.

-- 
			--Michael

-------------------------------------------------------------------------------
Michael Hill   <><  Isaiah 9:6 | "What you see and hear depends a good deal on
Michael_Hill@csgsystems.com    |  where you are standing; it also depends on
Aerospace/Software Engineer    |  what sort of person you are."
CSG Systems, Inc.              |          --C.S. Lewis, "The Magician's Nephew"
http://www.qadas.com/~msh      |
---In a marketplace (like the one of ideas), not everything has equal value!---
Did you ever notice that everybody in favor of abortion has already been born?!