Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!brl-adm!adm!Makey@LOGICON.arpa From: Makey@LOGICON.arpa (Jeff Makey) Newsgroups: comp.unix.wizards Subject: Daylight Savings Time: how to fix ctime.c Message-ID: <4992@brl-adm.ARPA> Date: Tue, 17-Mar-87 03:01:43 EST Article-I.D.: brl-adm.4992 Posted: Tue Mar 17 03:01:43 1987 Date-Received: Wed, 18-Mar-87 05:49:55 EST Sender: news@brl-adm.ARPA Lines: 58 Those of you with UNIX source who plan to fix your ctime routine so it knows about the 1987+ daylight savings time rules should be interested in the following information about daylight time in the United States. before 1967 no daylight time at all 1967 -> 1973 last Sunday in April -> last Sunday in October 1974 first Sunday in January -> last Sunday in October 1975 last Sunday in February -> last Sunday in October 1976 -> 1986 last Sunday in April -> last Sunday in October beginning 1987 first Sunday in April -> last Sunday in October Note that every UNIX system I have ever seen (including SVR2 and 4.2BSD) mistakenly thinks that daylight time in 1974 ends on the last Sunday in November. My evidence to the contrary is on page 741 of the 1984 edition of The World Almanac and Book of Facts and in a small article on page 3 of the 27 October 1974 edition of the Los Angeles Times (as recorded on microfilm at the San Diego city library). Check it yourself if you don't beleive me. The following data structure is useful for determining when daylight savings time is in effect in the United States. Any future changes should be simple and efficient. struct dstab { int dayyr; int daylb; int dayle; } usdaytab[] { { 1987, 96, 303 }, /* first Sun in Apr to last Sun in Oct */ { 1976, 119, 303 }, /* last Sun in Apr to last Sun in Oct */ { 1975, 58, 303 }, /* last Sun in Feb to last Sun in Oct */ { 1974, 5, 303 }, /* first Sun in Jan to last Sun in Oct */ { 1967, 119, 303 }, /* last Sun in Apr to last Sun in Oct */ { 0, 400, 0 } /* no daylight time at all */ }; The order (years are decreasing) of the entries in the table is important. In your code, use something like the following to select the appropriate table entry: struct dstab *ds; for (ds = usdaytab; ds->dayyr; ds++) if (year >= ds->dayyr) break; Those of you with 4.2BSD will notice a for loop very much like this one in localtime(). The important difference is the ">=" rather than the "==" in the if statement. You have a little less than 3 weeks to change ctime and relink programs that use it. I used what(I) on 4.2BSD to find about 70 executables that are affected. :: Jeff Makey Makey@LOGICON.ARPA P.S. Any requests for complete ctime sources will be forwarded to /dev/null.