Subject: v09i021: Public Domain (Table Driven) ``localtime'' Submitted by: Arthur David Olson Mod.sources: Volume 9, Issue 21 Archive-name: pd-localtime/Patch1 System: pd-localtime Patch #: 1 Priority: MEDIUM Description: This is patch #1 for the public domain localtime. It fixes the following problems (in decreasing order of severity): 1) The "timezone" variable, defined when USG_COMPAT is defined was being set to a value of the wrong sign (not compatible). 2) asctime() did not guarantee zero filled 2 digit fields when used with old versions of printf that cannot handle the "%.2d" format specification. 3) The STD_INSPIRED functions for converting "struct tm" values to time_t's would fail when given a "struct tm" value that was "illegal" (ie: not a possible output from localtime) and which happen to occur just near the end of one of the shorter months (the actual requirements are a little stricter than this), or from timelocal or timeoff where the offset moves the time from one month to another (where the earlier month is one of the shorter ones). 4) Missing rules for East Saskatchewan in Canada. 5) Typos in the zic(8) manual page. Fix: From your newsreading program, say "| patch -d DIR" where DIR is the directory where the pd-localtime distribution is saved. Alternatively, change to that directory, and do "patch -d . tm_wday], mon_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, --- 33,41 ----- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static char result[26]; ! (void) sprintf(result, "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n", wday_name[timeptr->tm_wday], mon_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, Index: localtime.c *** OLD/localtime.c Sun Apr 12 22:28:22 1987 --- localtime.c Sun Apr 12 22:28:39 1987 *************** *** 18,26 #endif /* !MAXPATHLEN */ #ifndef lint #ifndef NOID ! static char sccsid[] = "@(#)localtime.c 3.1"; #endif /* !NOID */ #endif /* !lint */ #ifndef TRUE --- 18,26 ----- #endif /* !MAXPATHLEN */ #ifndef lint #ifndef NOID ! static char sccsid[] = "@(#)localtime.c 3.2"; #endif /* !NOID */ #endif /* !lint */ #ifndef TRUE *************** *** 178,186 ** Set tzname elements to initial values. */ tzname[0] = tzname[1] = &s.chars[0]; #ifdef USG_COMPAT ! timezone = s.ttis[0].tt_gmtoff; daylight = 0; #endif /* USG_COMPAT */ for (i = 1; i < s.typecnt; ++i) { register struct ttinfo * ttisp; --- 178,186 ----- ** Set tzname elements to initial values. */ tzname[0] = tzname[1] = &s.chars[0]; #ifdef USG_COMPAT ! timezone = -s.ttis[0].tt_gmtoff; daylight = 0; #endif /* USG_COMPAT */ for (i = 1; i < s.typecnt; ++i) { register struct ttinfo * ttisp; *************** *** 193,201 #endif /* USG_COMPAT */ } else { tzname[0] = &s.chars[ttisp->tt_abbrind]; #ifdef USG_COMPAT ! timezone = ttisp->tt_gmtoff; #endif /* USG_COMPAT */ } } return 0; --- 193,201 ----- #endif /* USG_COMPAT */ } else { tzname[0] = &s.chars[ttisp->tt_abbrind]; #ifdef USG_COMPAT ! timezone = -ttisp->tt_gmtoff; #endif /* USG_COMPAT */ } } return 0; Index: northamerica *** OLD/northamerica Sun Apr 12 22:28:23 1987 --- northamerica Sun Apr 12 22:28:40 1987 *************** *** 1,5 ! # @(#)northamerica 3.1 # Despite the performance of existing (4.[123]BSD, System V Release 2.0) code, # US Daylight Saving Time ended on the last Sunday of *October* in 1974. # See, for example, the front page of the Saturday, October 26, 1974 --- 1,5 ----- ! # @(#)northamerica 3.2 # Despite the performance of existing (4.[123]BSD, System V Release 2.0) code, # US Daylight Saving Time ended on the last Sunday of *October* in 1974. # See, for example, the front page of the Saturday, October 26, 1974 *************** *** 86,93 Zone Canada/Newfoundland -3:30 Canada N%sT Zone Canada/Atlantic -4:00 Canada A%sT Zone Canada/Eastern -5:00 Canada E%sT Zone Canada/Central -6:00 Canada C%sT Zone Canada/Mountain -7:00 Canada M%sT Zone Canada/Pacific -8:00 Canada P%sT Zone Canada/Yukon -9:00 Canada Y%sT --- 86,94 ----- Zone Canada/Newfoundland -3:30 Canada N%sT Zone Canada/Atlantic -4:00 Canada A%sT Zone Canada/Eastern -5:00 Canada E%sT Zone Canada/Central -6:00 Canada C%sT + Zone Canada/East-Saskatchewan -6:00 - CST # No DST as of 1987 Zone Canada/Mountain -7:00 Canada M%sT Zone Canada/Pacific -8:00 Canada P%sT Zone Canada/Yukon -9:00 Canada Y%sT Index: timemk.c *** OLD/timemk.c Sun Apr 12 22:28:24 1987 --- timemk.c Sun Apr 12 22:28:42 1987 *************** *** 3,11 /*LINTLIBRARY*/ #ifndef lint #ifndef NOID ! static char sccsid[] = "@(#)timemk.c 3.1"; #endif /* !NOID */ #endif /* !lint */ #ifdef STD_INSPIRED --- 3,11 ----- /*LINTLIBRARY*/ #ifndef lint #ifndef NOID ! static char sccsid[] = "@(#)timemk.c 3.2"; #endif /* !NOID */ #endif /* !lint */ #ifdef STD_INSPIRED *************** *** 111,119 *timeptr = yourtm; /* restore "original" value */ if (yourtm.tm_mday == 31) { timeptr->tm_mday = 1; ++(timeptr->tm_mon); ! t = timemk(timeptr, funcp); if (t != WRONG) return t; *timeptr = yourtm; } else if (yourtm.tm_mon == TM_FEBRUARY && --- 111,119 ----- *timeptr = yourtm; /* restore "original" value */ if (yourtm.tm_mday == 31) { timeptr->tm_mday = 1; ++(timeptr->tm_mon); ! t = timemk(timeptr, funcp, offset); if (t != WRONG) return t; *timeptr = yourtm; } else if (yourtm.tm_mon == TM_FEBRUARY && *************** *** 119,127 } else if (yourtm.tm_mon == TM_FEBRUARY && yourtm.tm_mday > 28) { timeptr->tm_mday -= 28; ++(timeptr->tm_mon); ! t = timemk(timeptr, funcp); if (t != WRONG) return t; *timeptr = yourtm; } --- 119,127 ----- } else if (yourtm.tm_mon == TM_FEBRUARY && yourtm.tm_mday > 28) { timeptr->tm_mday -= 28; ++(timeptr->tm_mon); ! t = timemk(timeptr, funcp, offset); if (t != WRONG) return t; *timeptr = yourtm; } Index: zic.8 *** OLD/zic.8 Sun Apr 12 22:28:26 1987 --- zic.8 Sun Apr 12 22:28:44 1987 *************** *** 97,105 .B FROM field. .TP .B TYPE ! Gives the type of year in which the year applies. If .B TYPE is .B \- --- 97,105 ----- .B FROM field. .TP .B TYPE ! Gives the type of year in which the rule applies. If .B TYPE is .B \- *************** *** 154,162 .B ON field. .TP .B AT ! Gives the time of day at which the rule takes affect. Recognized forms include: .nf .in +.5i .sp --- 154,162 ----- .B ON field. .TP .B AT ! Gives the time of day at which the rule takes effect. Recognized forms include: .nf .in +.5i .sp *************** *** 290,294 .SH FILES /etc/zoneinfo standard directory used for created files .SH "SEE ALSO" newctime(3), tzfile(5), zdump(8) ! .. @(#)zic.8 3.1 --- 290,294 ----- .SH FILES /etc/zoneinfo standard directory used for created files .SH "SEE ALSO" newctime(3), tzfile(5), zdump(8) ! .. @(#)zic.8 3.2