2 ** This file is in the public domain, so clarified as of
3 ** 1996-06-05 by Arthur David Olson.
7 ** Leap second handling from Bradley White.
8 ** POSIX-style TZ environment variable handling from Guy Harris.
16 #include "float.h" /* for FLT_MAX and DBL_MAX */
18 #ifndef TZ_ABBR_MAX_LEN
19 #define TZ_ABBR_MAX_LEN 16
20 #endif /* !defined TZ_ABBR_MAX_LEN */
22 #ifndef TZ_ABBR_CHAR_SET
23 #define TZ_ABBR_CHAR_SET \
24 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._"
25 #endif /* !defined TZ_ABBR_CHAR_SET */
27 #ifndef TZ_ABBR_ERR_CHAR
28 #define TZ_ABBR_ERR_CHAR '_'
29 #endif /* !defined TZ_ABBR_ERR_CHAR */
32 ** SunOS 4.1.1 headers lack O_BINARY.
36 #define OPEN_MODE (O_RDONLY | O_BINARY)
37 #endif /* defined O_BINARY */
39 #define OPEN_MODE O_RDONLY
40 #endif /* !defined O_BINARY */
44 ** Someone might make incorrect use of a time zone abbreviation:
45 ** 1. They might reference tzname[0] before calling tzset (explicitly
47 ** 2. They might reference tzname[1] before calling tzset (explicitly
49 ** 3. They might reference tzname[1] after setting to a time zone
50 ** in which Daylight Saving Time is never observed.
51 ** 4. They might reference tzname[0] after setting to a time zone
52 ** in which Standard Time is never observed.
53 ** 5. They might reference tm.TM_ZONE after calling offtime.
54 ** What's best to do in the above cases is open to debate;
55 ** for now, we just set things up so that in any of the five cases
56 ** WILDABBR is used. Another possibility: initialize tzname[0] to the
57 ** string "tzname[0] used before set", and similarly for the other cases.
58 ** And another: initialize tzname[0] to "ERA", with an explanation in the
59 ** manual page of what this "time zone abbreviation" means (doing this so
60 ** that tzname[0] has the "normal" length of three characters).
63 #endif /* !defined WILDABBR */
65 static char wildabbr[] = WILDABBR;
67 static const char gmt[] = "GMT";
70 ** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
71 ** We default to US rules as of 1999-08-17.
72 ** POSIX 1003.1 section 8.1.1 says that the default DST rules are
73 ** implementation dependent; for historical reasons, US rules are a
76 #ifndef TZDEFRULESTRING
77 #define TZDEFRULESTRING ",M4.1.0,M10.5.0"
78 #endif /* !defined TZDEFDST */
80 struct ttinfo { /* time type information */
81 long tt_gmtoff; /* UTC offset in seconds */
82 int tt_isdst; /* used to set tm_isdst */
83 int tt_abbrind; /* abbreviation list index */
84 int tt_ttisstd; /* TRUE if transition is std time */
85 int tt_ttisgmt; /* TRUE if transition is UTC */
88 struct lsinfo { /* leap second information */
89 time_t ls_trans; /* transition time */
90 long ls_corr; /* correction to apply */
93 #define BIGGEST(a, b) (((a) > (b)) ? (a) : (b))
96 #define MY_TZNAME_MAX TZNAME_MAX
97 #endif /* defined TZNAME_MAX */
99 #define MY_TZNAME_MAX 255
100 #endif /* !defined TZNAME_MAX */
109 time_t ats[TZ_MAX_TIMES];
110 unsigned char types[TZ_MAX_TIMES];
111 struct ttinfo ttis[TZ_MAX_TYPES];
112 char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
113 (2 * (MY_TZNAME_MAX + 1)))];
114 struct lsinfo lsis[TZ_MAX_LEAPS];
118 int r_type; /* type of rule--see below */
119 int r_day; /* day number of rule */
120 int r_week; /* week number of rule */
121 int r_mon; /* month number of rule */
122 long r_time; /* transition time of rule */
125 #define JULIAN_DAY 0 /* Jn - Julian day */
126 #define DAY_OF_YEAR 1 /* n - day of year */
127 #define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
130 ** Prototypes for static functions.
133 static long detzcode(const char * codep);
134 static time_t detzcode64(const char * codep);
135 static int differ_by_repeat(time_t t1, time_t t0);
136 static const char * getzname(const char * strp);
137 static const char * getqzname(const char * strp, const int delim);
138 static const char * getnum(const char * strp, int * nump, int min,
140 static const char * getsecs(const char * strp, long * secsp);
141 static const char * getoffset(const char * strp, long * offsetp);
142 static const char * getrule(const char * strp, struct rule * rulep);
143 static void gmtload(struct state * sp);
144 static struct tm * gmtsub(const time_t * timep, long offset,
146 static struct tm * localsub(const time_t * timep, long offset,
148 static int increment_overflow(int * number, int delta);
149 static int leaps_thru_end_of(int y);
150 static int long_increment_overflow(long * number, int delta);
151 static int long_normalize_overflow(long * tensptr,
152 int * unitsptr, int base);
153 static int normalize_overflow(int * tensptr, int * unitsptr,
155 static void settzname(void);
156 static time_t time1(struct tm * tmp,
157 struct tm * (*funcp)(const time_t *,
160 static time_t time2(struct tm *tmp,
161 struct tm * (*funcp)(const time_t *,
163 long offset, int * okayp);
164 static time_t time2sub(struct tm *tmp,
165 struct tm * (*funcp)(const time_t *,
167 long offset, int * okayp, int do_norm_secs);
168 static struct tm * timesub(const time_t * timep, long offset,
169 const struct state * sp, struct tm * tmp);
170 static int tmcomp(const struct tm * atmp,
171 const struct tm * btmp);
172 static time_t transtime(time_t janfirst, int year,
173 const struct rule * rulep, long offset);
174 static int typesequiv(const struct state * sp, int a, int b);
175 static int tzload(const char * name, struct state * sp,
177 static int tzparse(const char * name, struct state * sp,
181 static struct state * lclptr;
182 static struct state * gmtptr;
183 #endif /* defined ALL_STATE */
186 static struct state lclmem;
187 static struct state gmtmem;
188 #define lclptr (&lclmem)
189 #define gmtptr (&gmtmem)
190 #endif /* State Farm */
192 #ifndef TZ_STRLEN_MAX
193 #define TZ_STRLEN_MAX 255
194 #endif /* !defined TZ_STRLEN_MAX */
196 static char lcl_TZname[TZ_STRLEN_MAX + 1];
197 static int lcl_is_set;
198 static int gmt_is_set;
206 ** Section 4.12.3 of X3.159-1989 requires that
207 ** Except for the strftime function, these functions [asctime,
208 ** ctime, gmtime, localtime] return values in one of two static
209 ** objects: a broken-down time structure and an array of char.
210 ** Thanks to Paul Eggert for noting this.
218 #endif /* defined USG_COMPAT */
222 #endif /* defined ALTZONE */
226 const char * const codep;
228 register long result;
231 result = (codep[0] & 0x80) ? ~0L : 0;
232 for (i = 0; i < 4; ++i)
233 result = (result << 8) | (codep[i] & 0xff);
239 const char * const codep;
241 register time_t result;
244 result = (codep[0] & 0x80) ? (~(int_fast64_t) 0) : 0;
245 for (i = 0; i < 8; ++i)
246 result = result * 256 + (codep[i] & 0xff);
253 register struct state * const sp = lclptr;
256 tzname[0] = wildabbr;
257 tzname[1] = wildabbr;
261 #endif /* defined USG_COMPAT */
264 #endif /* defined ALTZONE */
267 tzname[0] = tzname[1] = gmt;
270 #endif /* defined ALL_STATE */
272 ** And to get the latest zone names into tzname. . .
274 for (i = 0; i < sp->timecnt; ++i) {
275 register const struct ttinfo * const ttisp =
279 tzname[ttisp->tt_isdst] =
280 &sp->chars[ttisp->tt_abbrind];
284 if (!ttisp->tt_isdst)
285 timezone = -(ttisp->tt_gmtoff);
286 #endif /* defined USG_COMPAT */
289 altzone = -(ttisp->tt_gmtoff);
290 #endif /* defined ALTZONE */
293 ** Finally, scrub the abbreviations.
294 ** First, replace bogus characters.
296 for (i = 0; i < sp->charcnt; ++i)
297 if (strchr(TZ_ABBR_CHAR_SET, sp->chars[i]) == NULL)
298 sp->chars[i] = TZ_ABBR_ERR_CHAR;
300 ** Second, truncate long abbreviations.
302 for (i = 0; i < sp->typecnt; ++i) {
303 register const struct ttinfo * const ttisp = &sp->ttis[i];
304 register char * cp = &sp->chars[ttisp->tt_abbrind];
306 if (strlen(cp) > TZ_ABBR_MAX_LEN &&
307 strcmp(cp, GRANDPARENTED) != 0)
308 *(cp + TZ_ABBR_MAX_LEN) = '\0';
313 differ_by_repeat(t1, t0)
317 if (TYPE_INTEGRAL(time_t) &&
318 TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
320 return t1 - t0 == SECSPERREPEAT;
324 tzload(name, sp, doextend)
325 register const char * name;
326 register struct state * const sp;
327 register const int doextend;
329 register const char * p;
335 struct tzhead tzhead;
336 char buf[2 * sizeof(struct tzhead) +
343 up = (u_t *) calloc(1, sizeof *up);
346 #else /* !defined ALL_STATE */
348 register u_t * const up = &u;
349 #endif /* !defined ALL_STATE */
351 sp->goback = sp->goahead = FALSE;
352 if (name == NULL && (name = TZDEFAULT) == NULL)
355 register int doaccess;
357 ** Section 4.9.1 of the C standard says that
358 ** "FILENAME_MAX expands to an integral constant expression
359 ** that is the size needed for an array of char large enough
360 ** to hold the longest file name string that the implementation
361 ** guarantees can be opened."
363 char fullname[FILENAME_MAX + 1];
367 doaccess = name[0] == '/';
369 if ((p = TZDIR) == NULL)
371 if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
373 (void) strcpy(fullname, p);
374 (void) strcat(fullname, "/");
375 (void) strcat(fullname, name);
377 ** Set doaccess if '.' (as in "../") shows up in name.
379 if (strchr(name, '.') != NULL)
383 if (doaccess && access(name, R_OK) != 0)
385 if ((fid = open(name, OPEN_MODE)) == -1)
388 nread = read(fid, up->buf, sizeof up->buf);
389 if (close(fid) < 0 || nread <= 0)
391 for (stored = 4; stored <= 8; stored *= 2) {
395 ttisstdcnt = (int) detzcode(up->tzhead.tzh_ttisstdcnt);
396 ttisgmtcnt = (int) detzcode(up->tzhead.tzh_ttisgmtcnt);
397 sp->leapcnt = (int) detzcode(up->tzhead.tzh_leapcnt);
398 sp->timecnt = (int) detzcode(up->tzhead.tzh_timecnt);
399 sp->typecnt = (int) detzcode(up->tzhead.tzh_typecnt);
400 sp->charcnt = (int) detzcode(up->tzhead.tzh_charcnt);
401 p = up->tzhead.tzh_charcnt + sizeof up->tzhead.tzh_charcnt;
402 if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
403 sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
404 sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
405 sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
406 (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
407 (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
409 if (nread - (p - up->buf) <
410 sp->timecnt * stored + /* ats */
411 sp->timecnt + /* types */
412 sp->typecnt * 6 + /* ttinfos */
413 sp->charcnt + /* chars */
414 sp->leapcnt * (stored + 4) + /* lsinfos */
415 ttisstdcnt + /* ttisstds */
416 ttisgmtcnt) /* ttisgmts */
418 for (i = 0; i < sp->timecnt; ++i) {
419 sp->ats[i] = (stored == 4) ?
420 detzcode(p) : detzcode64(p);
423 for (i = 0; i < sp->timecnt; ++i) {
424 sp->types[i] = (unsigned char) *p++;
425 if (sp->types[i] >= sp->typecnt)
428 for (i = 0; i < sp->typecnt; ++i) {
429 register struct ttinfo * ttisp;
431 ttisp = &sp->ttis[i];
432 ttisp->tt_gmtoff = detzcode(p);
434 ttisp->tt_isdst = (unsigned char) *p++;
435 if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
437 ttisp->tt_abbrind = (unsigned char) *p++;
438 if (ttisp->tt_abbrind < 0 ||
439 ttisp->tt_abbrind > sp->charcnt)
442 for (i = 0; i < sp->charcnt; ++i)
444 sp->chars[i] = '\0'; /* ensure '\0' at end */
445 for (i = 0; i < sp->leapcnt; ++i) {
446 register struct lsinfo * lsisp;
448 lsisp = &sp->lsis[i];
449 lsisp->ls_trans = (stored == 4) ?
450 detzcode(p) : detzcode64(p);
452 lsisp->ls_corr = detzcode(p);
455 for (i = 0; i < sp->typecnt; ++i) {
456 register struct ttinfo * ttisp;
458 ttisp = &sp->ttis[i];
460 ttisp->tt_ttisstd = FALSE;
462 ttisp->tt_ttisstd = *p++;
463 if (ttisp->tt_ttisstd != TRUE &&
464 ttisp->tt_ttisstd != FALSE)
468 for (i = 0; i < sp->typecnt; ++i) {
469 register struct ttinfo * ttisp;
471 ttisp = &sp->ttis[i];
473 ttisp->tt_ttisgmt = FALSE;
475 ttisp->tt_ttisgmt = *p++;
476 if (ttisp->tt_ttisgmt != TRUE &&
477 ttisp->tt_ttisgmt != FALSE)
482 ** Out-of-sort ats should mean we're running on a
483 ** signed time_t system but using a data file with
484 ** unsigned values (or vice versa).
486 for (i = 0; i < sp->timecnt - 2; ++i)
487 if (sp->ats[i] > sp->ats[i + 1]) {
489 if (TYPE_SIGNED(time_t)) {
491 ** Ignore the end (easy).
496 ** Ignore the beginning (harder).
500 for (j = 0; j + i < sp->timecnt; ++j) {
501 sp->ats[j] = sp->ats[j + i];
502 sp->types[j] = sp->types[j + i];
509 ** If this is an old file, we're done.
511 if (up->tzhead.tzh_version[0] == '\0')
513 nread -= p - up->buf;
514 for (i = 0; i < nread; ++i)
517 ** If this is a narrow integer time_t system, we're done.
519 if (stored >= (int) sizeof(time_t) && TYPE_INTEGRAL(time_t))
522 if (doextend && nread > 2 &&
523 up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
524 sp->typecnt + 2 <= TZ_MAX_TYPES) {
528 up->buf[nread - 1] = '\0';
529 result = tzparse(&up->buf[1], &ts, FALSE);
530 if (result == 0 && ts.typecnt == 2 &&
531 sp->charcnt + ts.charcnt <= TZ_MAX_CHARS) {
532 for (i = 0; i < 2; ++i)
533 ts.ttis[i].tt_abbrind +=
535 for (i = 0; i < ts.charcnt; ++i)
536 sp->chars[sp->charcnt++] =
539 while (i < ts.timecnt &&
541 sp->ats[sp->timecnt - 1])
543 while (i < ts.timecnt &&
544 sp->timecnt < TZ_MAX_TIMES) {
545 sp->ats[sp->timecnt] =
547 sp->types[sp->timecnt] =
553 sp->ttis[sp->typecnt++] = ts.ttis[0];
554 sp->ttis[sp->typecnt++] = ts.ttis[1];
557 if (sp->timecnt > 1) {
558 for (i = 1; i < sp->timecnt; ++i)
559 if (typesequiv(sp, sp->types[i], sp->types[0]) &&
560 differ_by_repeat(sp->ats[i], sp->ats[0])) {
564 for (i = sp->timecnt - 2; i >= 0; --i)
565 if (typesequiv(sp, sp->types[sp->timecnt - 1],
567 differ_by_repeat(sp->ats[sp->timecnt - 1],
574 (void) free((void *) up);
575 #endif /* defined ALL_STATE */
579 (void) free((void *) up);
580 #endif /* defined ALL_STATE */
586 const struct state * const sp;
593 a < 0 || a >= sp->typecnt ||
594 b < 0 || b >= sp->typecnt)
597 register const struct ttinfo * ap = &sp->ttis[a];
598 register const struct ttinfo * bp = &sp->ttis[b];
599 result = ap->tt_gmtoff == bp->tt_gmtoff &&
600 ap->tt_isdst == bp->tt_isdst &&
601 ap->tt_ttisstd == bp->tt_ttisstd &&
602 ap->tt_ttisgmt == bp->tt_ttisgmt &&
603 strcmp(&sp->chars[ap->tt_abbrind],
604 &sp->chars[bp->tt_abbrind]) == 0;
609 static const int mon_lengths[2][MONSPERYEAR] = {
610 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
611 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
614 static const int year_lengths[2] = {
615 DAYSPERNYEAR, DAYSPERLYEAR
619 ** Given a pointer into a time zone string, scan until a character that is not
620 ** a valid character in a zone name is found. Return a pointer to that
626 register const char * strp;
630 while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
637 ** Given a pointer into an extended time zone string, scan until the ending
638 ** delimiter of the zone name is located. Return a pointer to the delimiter.
640 ** As with getzname above, the legal character set is actually quite
641 ** restricted, with other characters producing undefined results.
642 ** We don't do any checking here; checking is done later in common-case code.
646 getqzname(register const char *strp, const int delim)
650 while ((c = *strp) != '\0' && c != delim)
656 ** Given a pointer into a time zone string, extract a number from that string.
657 ** Check that the number is within a specified range; if it is not, return
659 ** Otherwise, return a pointer to the first character not part of the number.
663 getnum(strp, nump, min, max)
664 register const char * strp;
672 if (strp == NULL || !is_digit(c = *strp))
676 num = num * 10 + (c - '0');
678 return NULL; /* illegal value */
680 } while (is_digit(c));
682 return NULL; /* illegal value */
688 ** Given a pointer into a time zone string, extract a number of seconds,
689 ** in hh[:mm[:ss]] form, from the string.
690 ** If any error occurs, return NULL.
691 ** Otherwise, return a pointer to the first character not part of the number
697 register const char * strp;
703 ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
704 ** "M10.4.6/26", which does not conform to Posix,
705 ** but which specifies the equivalent of
706 ** ``02:00 on the first Sunday on or after 23 Oct''.
708 strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
711 *secsp = num * (long) SECSPERHOUR;
714 strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
717 *secsp += num * SECSPERMIN;
720 /* `SECSPERMIN' allows for leap seconds. */
721 strp = getnum(strp, &num, 0, SECSPERMIN);
731 ** Given a pointer into a time zone string, extract an offset, in
732 ** [+-]hh[:mm[:ss]] form, from the string.
733 ** If any error occurs, return NULL.
734 ** Otherwise, return a pointer to the first character not part of the time.
738 getoffset(strp, offsetp)
739 register const char * strp;
740 long * const offsetp;
742 register int neg = 0;
747 } else if (*strp == '+')
749 strp = getsecs(strp, offsetp);
751 return NULL; /* illegal time */
753 *offsetp = -*offsetp;
758 ** Given a pointer into a time zone string, extract a rule in the form
759 ** date[/time]. See POSIX section 8 for the format of "date" and "time".
760 ** If a valid rule is not found, return NULL.
761 ** Otherwise, return a pointer to the first character not part of the rule.
767 register struct rule * const rulep;
773 rulep->r_type = JULIAN_DAY;
775 strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
776 } else if (*strp == 'M') {
780 rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
782 strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
787 strp = getnum(strp, &rulep->r_week, 1, 5);
792 strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
793 } else if (is_digit(*strp)) {
797 rulep->r_type = DAY_OF_YEAR;
798 strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
799 } else return NULL; /* invalid format */
807 strp = getsecs(strp, &rulep->r_time);
808 } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
813 ** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the
814 ** year, a rule, and the offset from UTC at the time that rule takes effect,
815 ** calculate the Epoch-relative time that rule takes effect.
819 transtime(janfirst, year, rulep, offset)
820 const time_t janfirst;
822 register const struct rule * const rulep;
825 register int leapyear;
826 register time_t value;
828 int d, m1, yy0, yy1, yy2, dow;
831 leapyear = isleap(year);
832 switch (rulep->r_type) {
836 ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
838 ** In non-leap years, or if the day number is 59 or less, just
839 ** add SECSPERDAY times the day number-1 to the time of
840 ** January 1, midnight, to get the day.
842 value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
843 if (leapyear && rulep->r_day >= 60)
850 ** Just add SECSPERDAY times the day number to the time of
851 ** January 1, midnight, to get the day.
853 value = janfirst + rulep->r_day * SECSPERDAY;
856 case MONTH_NTH_DAY_OF_WEEK:
858 ** Mm.n.d - nth "dth day" of month m.
861 for (i = 0; i < rulep->r_mon - 1; ++i)
862 value += mon_lengths[leapyear][i] * SECSPERDAY;
865 ** Use Zeller's Congruence to get day-of-week of first day of
868 m1 = (rulep->r_mon + 9) % 12 + 1;
869 yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
872 dow = ((26 * m1 - 2) / 10 +
873 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
878 ** "dow" is the day-of-week of the first day of the month. Get
879 ** the day-of-month (zero-origin) of the first "dow" day of the
882 d = rulep->r_day - dow;
885 for (i = 1; i < rulep->r_week; ++i) {
886 if (d + DAYSPERWEEK >=
887 mon_lengths[leapyear][rulep->r_mon - 1])
893 ** "d" is the day-of-month (zero-origin) of the day we want.
895 value += d * SECSPERDAY;
900 ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
901 ** question. To get the Epoch-relative time of the specified local
902 ** time on that day, add the transition time and the current offset
905 return value + rulep->r_time + offset;
909 ** Given a POSIX section 8-style TZ string, fill in the rule tables as
914 tzparse(name, sp, lastditch)
916 register struct state * const sp;
919 const char * stdname;
920 const char * dstname;
925 register time_t * atp;
926 register unsigned char * typep;
928 register int load_result;
929 static struct ttinfo zttinfo;
934 stdlen = strlen(name); /* length of standard zone name */
936 if (stdlen >= sizeof sp->chars)
937 stdlen = (sizeof sp->chars) - 1;
943 name = getqzname(name, '>');
946 stdlen = name - stdname;
949 name = getzname(name);
950 stdlen = name - stdname;
954 name = getoffset(name, &stdoffset);
958 load_result = tzload(TZDEFRULES, sp, FALSE);
959 if (load_result != 0)
960 sp->leapcnt = 0; /* so, we're off a little */
964 name = getqzname(name, '>');
967 dstlen = name - dstname;
971 name = getzname(name);
972 dstlen = name - dstname; /* length of DST zone name */
974 if (*name != '\0' && *name != ',' && *name != ';') {
975 name = getoffset(name, &dstoffset);
978 } else dstoffset = stdoffset - SECSPERHOUR;
979 if (*name == '\0' && load_result != 0)
980 name = TZDEFRULESTRING;
981 if (*name == ',' || *name == ';') {
985 register time_t janfirst;
990 if ((name = getrule(name, &start)) == NULL)
994 if ((name = getrule(name, &end)) == NULL)
998 sp->typecnt = 2; /* standard time and DST */
1000 ** Two transitions per year, from EPOCH_YEAR forward.
1002 sp->ttis[0] = sp->ttis[1] = zttinfo;
1003 sp->ttis[0].tt_gmtoff = -dstoffset;
1004 sp->ttis[0].tt_isdst = 1;
1005 sp->ttis[0].tt_abbrind = stdlen + 1;
1006 sp->ttis[1].tt_gmtoff = -stdoffset;
1007 sp->ttis[1].tt_isdst = 0;
1008 sp->ttis[1].tt_abbrind = 0;
1013 for (year = EPOCH_YEAR;
1014 sp->timecnt + 2 <= TZ_MAX_TIMES;
1018 starttime = transtime(janfirst, year, &start,
1020 endtime = transtime(janfirst, year, &end,
1022 if (starttime > endtime) {
1024 *typep++ = 1; /* DST ends */
1026 *typep++ = 0; /* DST begins */
1029 *typep++ = 0; /* DST begins */
1031 *typep++ = 1; /* DST ends */
1034 newfirst = janfirst;
1035 newfirst += year_lengths[isleap(year)] *
1037 if (newfirst <= janfirst)
1039 janfirst = newfirst;
1042 register long theirstdoffset;
1043 register long theirdstoffset;
1044 register long theiroffset;
1052 ** Initial values of theirstdoffset and theirdstoffset.
1055 for (i = 0; i < sp->timecnt; ++i) {
1057 if (!sp->ttis[j].tt_isdst) {
1059 -sp->ttis[j].tt_gmtoff;
1064 for (i = 0; i < sp->timecnt; ++i) {
1066 if (sp->ttis[j].tt_isdst) {
1068 -sp->ttis[j].tt_gmtoff;
1073 ** Initially we're assumed to be in standard time.
1076 theiroffset = theirstdoffset;
1078 ** Now juggle transition times and types
1079 ** tracking offsets as you do.
1081 for (i = 0; i < sp->timecnt; ++i) {
1083 sp->types[i] = sp->ttis[j].tt_isdst;
1084 if (sp->ttis[j].tt_ttisgmt) {
1085 /* No adjustment to transition time */
1088 ** If summer time is in effect, and the
1089 ** transition time was not specified as
1090 ** standard time, add the summer time
1091 ** offset to the transition time;
1092 ** otherwise, add the standard time
1093 ** offset to the transition time.
1096 ** Transitions from DST to DDST
1097 ** will effectively disappear since
1098 ** POSIX provides for only one DST
1101 if (isdst && !sp->ttis[j].tt_ttisstd) {
1102 sp->ats[i] += dstoffset -
1105 sp->ats[i] += stdoffset -
1109 theiroffset = -sp->ttis[j].tt_gmtoff;
1110 if (sp->ttis[j].tt_isdst)
1111 theirdstoffset = theiroffset;
1112 else theirstdoffset = theiroffset;
1115 ** Finally, fill in ttis.
1117 sp->ttis[0] = sp->ttis[1] = zttinfo;
1118 sp->ttis[0].tt_gmtoff = -stdoffset;
1119 sp->ttis[0].tt_isdst = FALSE;
1120 sp->ttis[0].tt_abbrind = 0;
1121 sp->ttis[1].tt_gmtoff = -dstoffset;
1122 sp->ttis[1].tt_isdst = TRUE;
1123 sp->ttis[1].tt_abbrind = stdlen + 1;
1128 sp->typecnt = 1; /* only standard time */
1130 sp->ttis[0] = zttinfo;
1131 sp->ttis[0].tt_gmtoff = -stdoffset;
1132 sp->ttis[0].tt_isdst = 0;
1133 sp->ttis[0].tt_abbrind = 0;
1135 sp->charcnt = stdlen + 1;
1137 sp->charcnt += dstlen + 1;
1138 if ((size_t) sp->charcnt > sizeof sp->chars)
1141 (void) strncpy(cp, stdname, stdlen);
1145 (void) strncpy(cp, dstname, dstlen);
1146 *(cp + dstlen) = '\0';
1153 struct state * const sp;
1155 if (tzload(gmt, sp, TRUE) != 0)
1156 (void) tzparse(gmt, sp, TRUE);
1159 #ifndef STD_INSPIRED
1161 ** A non-static declaration of tzsetwall in a system header file
1162 ** may cause a warning about this upcoming static declaration...
1165 #endif /* !defined STD_INSPIRED */
1174 if (lclptr == NULL) {
1175 lclptr = (struct state *) calloc(1, sizeof *lclptr);
1176 if (lclptr == NULL) {
1177 settzname(); /* all we can do */
1181 #endif /* defined ALL_STATE */
1182 if (tzload((char *) NULL, lclptr, TRUE) != 0)
1190 register const char * name;
1192 name = getenv("TZ");
1198 if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
1200 lcl_is_set = strlen(name) < sizeof lcl_TZname;
1202 (void) strcpy(lcl_TZname, name);
1205 if (lclptr == NULL) {
1206 lclptr = (struct state *) calloc(1, sizeof *lclptr);
1207 if (lclptr == NULL) {
1208 settzname(); /* all we can do */
1212 #endif /* defined ALL_STATE */
1213 if (*name == '\0') {
1215 ** User wants it fast rather than right.
1217 lclptr->leapcnt = 0; /* so, we're off a little */
1218 lclptr->timecnt = 0;
1219 lclptr->typecnt = 0;
1220 lclptr->ttis[0].tt_isdst = 0;
1221 lclptr->ttis[0].tt_gmtoff = 0;
1222 lclptr->ttis[0].tt_abbrind = 0;
1223 (void) strcpy(lclptr->chars, gmt);
1224 } else if (tzload(name, lclptr, TRUE) != 0)
1225 if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
1226 (void) gmtload(lclptr);
1231 ** The easy way to behave "as if no library function calls" localtime
1232 ** is to not call it--so we drop its guts into "localsub", which can be
1233 ** freely called. (And no, the PANS doesn't require the above behavior--
1234 ** but it *is* desirable.)
1236 ** The unused offset argument is for the benefit of mktime variants.
1241 localsub(timep, offset, tmp)
1242 const time_t * const timep;
1244 struct tm * const tmp;
1246 register struct state * sp;
1247 register const struct ttinfo * ttisp;
1249 register struct tm * result;
1250 const time_t t = *timep;
1255 return gmtsub(timep, offset, tmp);
1256 #endif /* defined ALL_STATE */
1257 if ((sp->goback && t < sp->ats[0]) ||
1258 (sp->goahead && t > sp->ats[sp->timecnt - 1])) {
1260 register time_t seconds;
1261 register time_t tcycles;
1262 register int_fast64_t icycles;
1265 seconds = sp->ats[0] - t;
1266 else seconds = t - sp->ats[sp->timecnt - 1];
1268 tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR;
1271 if (tcycles - icycles >= 1 || icycles - tcycles >= 1)
1274 seconds *= YEARSPERREPEAT;
1275 seconds *= AVGSECSPERYEAR;
1278 else newt -= seconds;
1279 if (newt < sp->ats[0] ||
1280 newt > sp->ats[sp->timecnt - 1])
1281 return NULL; /* "cannot happen" */
1282 result = localsub(&newt, offset, tmp);
1283 if (result == tmp) {
1284 register time_t newy;
1286 newy = tmp->tm_year;
1288 newy -= icycles * YEARSPERREPEAT;
1289 else newy += icycles * YEARSPERREPEAT;
1290 tmp->tm_year = newy;
1291 if (tmp->tm_year != newy)
1296 if (sp->timecnt == 0 || t < sp->ats[0]) {
1298 while (sp->ttis[i].tt_isdst)
1299 if (++i >= sp->typecnt) {
1304 register int lo = 1;
1305 register int hi = sp->timecnt;
1308 register int mid = (lo + hi) >> 1;
1310 if (t < sp->ats[mid])
1314 i = (int) sp->types[lo - 1];
1316 ttisp = &sp->ttis[i];
1318 ** To get (wrong) behavior that's compatible with System V Release 2.0
1319 ** you'd replace the statement below with
1320 ** t += ttisp->tt_gmtoff;
1321 ** timesub(&t, 0L, sp, tmp);
1323 result = timesub(&t, ttisp->tt_gmtoff, sp, tmp);
1324 tmp->tm_isdst = ttisp->tt_isdst;
1325 tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
1327 tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
1328 #endif /* defined TM_ZONE */
1334 const time_t * const timep;
1337 return localsub(timep, 0L, &tm);
1341 ** Re-entrant version of localtime.
1345 localtime_r(timep, tmp)
1346 const time_t * const timep;
1349 return localsub(timep, 0L, tmp);
1353 ** gmtsub is to gmtime as localsub is to localtime.
1357 gmtsub(timep, offset, tmp)
1358 const time_t * const timep;
1360 struct tm * const tmp;
1362 register struct tm * result;
1367 gmtptr = (struct state *) calloc(1, sizeof *gmtptr);
1369 #endif /* defined ALL_STATE */
1372 result = timesub(timep, offset, gmtptr, tmp);
1375 ** Could get fancy here and deliver something such as
1376 ** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,
1377 ** but this is no time for a treasure hunt.
1380 tmp->TM_ZONE = wildabbr;
1385 else tmp->TM_ZONE = gmtptr->chars;
1386 #endif /* defined ALL_STATE */
1388 tmp->TM_ZONE = gmtptr->chars;
1389 #endif /* State Farm */
1391 #endif /* defined TM_ZONE */
1397 const time_t * const timep;
1399 return gmtsub(timep, 0L, &tm);
1403 * Re-entrant version of gmtime.
1407 gmtime_r(timep, tmp)
1408 const time_t * const timep;
1411 return gmtsub(timep, 0L, tmp);
1417 offtime(timep, offset)
1418 const time_t * const timep;
1421 return gmtsub(timep, offset, &tm);
1424 #endif /* defined STD_INSPIRED */
1427 ** Return the number of leap years through the end of the given year
1428 ** where, to make the math easy, the answer for year zero is defined as zero.
1432 leaps_thru_end_of(y)
1433 register const int y;
1435 return (y >= 0) ? (y / 4 - y / 100 + y / 400) :
1436 -(leaps_thru_end_of(-(y + 1)) + 1);
1440 timesub(timep, offset, sp, tmp)
1441 const time_t * const timep;
1443 register const struct state * const sp;
1444 register struct tm * const tmp;
1446 register const struct lsinfo * lp;
1447 register time_t tdays;
1448 register int idays; /* unsigned would be so 2003 */
1451 register const int * ip;
1459 i = (sp == NULL) ? 0 : sp->leapcnt;
1460 #endif /* defined ALL_STATE */
1463 #endif /* State Farm */
1466 if (*timep >= lp->ls_trans) {
1467 if (*timep == lp->ls_trans) {
1468 hit = ((i == 0 && lp->ls_corr > 0) ||
1469 lp->ls_corr > sp->lsis[i - 1].ls_corr);
1472 sp->lsis[i].ls_trans ==
1473 sp->lsis[i - 1].ls_trans + 1 &&
1474 sp->lsis[i].ls_corr ==
1475 sp->lsis[i - 1].ls_corr + 1) {
1485 tdays = *timep / SECSPERDAY;
1486 rem = *timep - tdays * SECSPERDAY;
1487 while (tdays < 0 || tdays >= year_lengths[isleap(y)]) {
1489 register time_t tdelta;
1490 register int idelta;
1491 register int leapdays;
1493 tdelta = tdays / DAYSPERLYEAR;
1495 if (tdelta - idelta >= 1 || idelta - tdelta >= 1)
1498 idelta = (tdays < 0) ? -1 : 1;
1500 if (increment_overflow(&newy, idelta))
1502 leapdays = leaps_thru_end_of(newy - 1) -
1503 leaps_thru_end_of(y - 1);
1504 tdays -= ((time_t) newy - y) * DAYSPERNYEAR;
1509 register long seconds;
1511 seconds = tdays * SECSPERDAY + 0.5;
1512 tdays = seconds / SECSPERDAY;
1513 rem += seconds - tdays * SECSPERDAY;
1516 ** Given the range, we can now fearlessly cast...
1519 rem += offset - corr;
1524 while (rem >= SECSPERDAY) {
1529 if (increment_overflow(&y, -1))
1531 idays += year_lengths[isleap(y)];
1533 while (idays >= year_lengths[isleap(y)]) {
1534 idays -= year_lengths[isleap(y)];
1535 if (increment_overflow(&y, 1))
1539 if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE))
1541 tmp->tm_yday = idays;
1543 ** The "extra" mods below avoid overflow problems.
1545 tmp->tm_wday = EPOCH_WDAY +
1546 ((y - EPOCH_YEAR) % DAYSPERWEEK) *
1547 (DAYSPERNYEAR % DAYSPERWEEK) +
1548 leaps_thru_end_of(y - 1) -
1549 leaps_thru_end_of(EPOCH_YEAR - 1) +
1551 tmp->tm_wday %= DAYSPERWEEK;
1552 if (tmp->tm_wday < 0)
1553 tmp->tm_wday += DAYSPERWEEK;
1554 tmp->tm_hour = (int) (rem / SECSPERHOUR);
1556 tmp->tm_min = (int) (rem / SECSPERMIN);
1558 ** A positive leap second requires a special
1559 ** representation. This uses "... ??:59:60" et seq.
1561 tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
1562 ip = mon_lengths[isleap(y)];
1563 for (tmp->tm_mon = 0; idays >= ip[tmp->tm_mon]; ++(tmp->tm_mon))
1564 idays -= ip[tmp->tm_mon];
1565 tmp->tm_mday = (int) (idays + 1);
1568 tmp->TM_GMTOFF = offset;
1569 #endif /* defined TM_GMTOFF */
1575 const time_t * const timep;
1578 ** Section 4.12.3.2 of X3.159-1989 requires that
1579 ** The ctime function converts the calendar time pointed to by timer
1580 ** to local time in the form of a string. It is equivalent to
1581 ** asctime(localtime(timer))
1583 return asctime(localtime(timep));
1588 const time_t * const timep;
1593 return asctime_r(localtime_r(timep, &mytm), buf);
1597 ** Adapted from code provided by Robert Elz, who writes:
1598 ** The "best" way to do mktime I think is based on an idea of Bob
1599 ** Kridle's (so its said...) from a long time ago.
1600 ** It does a binary search of the time_t space. Since time_t's are
1601 ** just 32 bits, its a max of 32 iterations (even at 64 bits it
1602 ** would still be very reasonable).
1607 #endif /* !defined WRONG */
1610 ** Normalize logic courtesy Paul Eggert.
1614 increment_overflow(ip, j)
1618 register int const i = *ip;
1621 ** If i >= 0 there can only be overflow if i + j > INT_MAX
1622 ** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
1623 ** If i < 0 there can only be overflow if i + j < INT_MIN
1624 ** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
1626 if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
1633 long_increment_overflow(lp, m)
1637 register long const l = *lp;
1639 if ((l >= 0) ? (m > LONG_MAX - l) : (m < LONG_MIN - l))
1646 normalize_overflow(tensptr, unitsptr, base)
1647 int * const tensptr;
1648 int * const unitsptr;
1651 register int tensdelta;
1653 tensdelta = (*unitsptr >= 0) ?
1654 (*unitsptr / base) :
1655 (-1 - (-1 - *unitsptr) / base);
1656 *unitsptr -= tensdelta * base;
1657 return increment_overflow(tensptr, tensdelta);
1661 long_normalize_overflow(tensptr, unitsptr, base)
1662 long * const tensptr;
1663 int * const unitsptr;
1666 register int tensdelta;
1668 tensdelta = (*unitsptr >= 0) ?
1669 (*unitsptr / base) :
1670 (-1 - (-1 - *unitsptr) / base);
1671 *unitsptr -= tensdelta * base;
1672 return long_increment_overflow(tensptr, tensdelta);
1677 register const struct tm * const atmp;
1678 register const struct tm * const btmp;
1680 register int result;
1682 if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
1683 (result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
1684 (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
1685 (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
1686 (result = (atmp->tm_min - btmp->tm_min)) == 0)
1687 result = atmp->tm_sec - btmp->tm_sec;
1692 time2sub(tmp, funcp, offset, okayp, do_norm_secs)
1693 struct tm * const tmp;
1694 struct tm * (* const funcp)(const time_t*, long, struct tm*);
1697 const int do_norm_secs;
1699 register const struct state * sp;
1702 register int saved_seconds;
1709 struct tm yourtm, mytm;
1714 if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
1718 if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
1720 if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
1723 if (long_normalize_overflow(&y, &yourtm.tm_mon, MONSPERYEAR))
1726 ** Turn y into an actual year number for now.
1727 ** It is converted back to an offset from TM_YEAR_BASE later.
1729 if (long_increment_overflow(&y, TM_YEAR_BASE))
1731 while (yourtm.tm_mday <= 0) {
1732 if (long_increment_overflow(&y, -1))
1734 li = y + (1 < yourtm.tm_mon);
1735 yourtm.tm_mday += year_lengths[isleap(li)];
1737 while (yourtm.tm_mday > DAYSPERLYEAR) {
1738 li = y + (1 < yourtm.tm_mon);
1739 yourtm.tm_mday -= year_lengths[isleap(li)];
1740 if (long_increment_overflow(&y, 1))
1744 i = mon_lengths[isleap(y)][yourtm.tm_mon];
1745 if (yourtm.tm_mday <= i)
1747 yourtm.tm_mday -= i;
1748 if (++yourtm.tm_mon >= MONSPERYEAR) {
1750 if (long_increment_overflow(&y, 1))
1754 if (long_increment_overflow(&y, -TM_YEAR_BASE))
1757 if (yourtm.tm_year != y)
1759 if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
1761 else if (y + TM_YEAR_BASE < EPOCH_YEAR) {
1763 ** We can't set tm_sec to 0, because that might push the
1764 ** time below the minimum representable time.
1765 ** Set tm_sec to 59 instead.
1766 ** This assumes that the minimum representable time is
1767 ** not in the same minute that a leap second was deleted from,
1768 ** which is a safer assumption than using 58 would be.
1770 if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
1772 saved_seconds = yourtm.tm_sec;
1773 yourtm.tm_sec = SECSPERMIN - 1;
1775 saved_seconds = yourtm.tm_sec;
1779 ** Do a binary search (this works whatever time_t's type is).
1781 if (!TYPE_SIGNED(time_t)) {
1784 } else if (!TYPE_INTEGRAL(time_t)) {
1785 if (sizeof(time_t) > sizeof(float))
1786 hi = (time_t) DBL_MAX;
1787 else hi = (time_t) FLT_MAX;
1791 for (i = 0; i < (int) TYPE_BIT(time_t) - 1; ++i)
1796 t = lo / 2 + hi / 2;
1801 if ((*funcp)(&t, offset, &mytm) == NULL) {
1803 ** Assume that t is too extreme to be represented in
1804 ** a struct tm; arrange things so that it is less
1805 ** extreme on the next pass.
1807 dir = (t > 0) ? 1 : -1;
1808 } else dir = tmcomp(&mytm, &yourtm);
1815 } else if (t == hi) {
1828 if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
1831 ** Right time, wrong type.
1832 ** Hunt for right time, right type.
1833 ** It's okay to guess wrong since the guess
1836 sp = (const struct state *)
1837 ((funcp == localsub) ? lclptr : gmtptr);
1841 #endif /* defined ALL_STATE */
1842 for (i = sp->typecnt - 1; i >= 0; --i) {
1843 if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
1845 for (j = sp->typecnt - 1; j >= 0; --j) {
1846 if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
1848 newt = t + sp->ttis[j].tt_gmtoff -
1849 sp->ttis[i].tt_gmtoff;
1850 if ((*funcp)(&newt, offset, &mytm) == NULL)
1852 if (tmcomp(&mytm, &yourtm) != 0)
1854 if (mytm.tm_isdst != yourtm.tm_isdst)
1866 newt = t + saved_seconds;
1867 if ((newt < t) != (saved_seconds < 0))
1870 if ((*funcp)(&t, offset, tmp))
1876 time2(tmp, funcp, offset, okayp)
1877 struct tm * const tmp;
1878 struct tm * (* const funcp)(const time_t*, long, struct tm*);
1885 ** First try without normalization of seconds
1886 ** (in case tm_sec contains a value associated with a leap second).
1887 ** If that fails, try with normalization of seconds.
1889 t = time2sub(tmp, funcp, offset, okayp, FALSE);
1890 return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);
1894 time1(tmp, funcp, offset)
1895 struct tm * const tmp;
1896 struct tm * (* const funcp)(const time_t *, long, struct tm *);
1900 register const struct state * sp;
1901 register int samei, otheri;
1902 register int sameind, otherind;
1905 int seen[TZ_MAX_TYPES];
1906 int types[TZ_MAX_TYPES];
1913 if (tmp->tm_isdst > 1)
1915 t = time2(tmp, funcp, offset, &okay);
1918 ** PCTS code courtesy Grant Sullivan.
1922 if (tmp->tm_isdst < 0)
1923 tmp->tm_isdst = 0; /* reset to std and try again */
1924 #endif /* defined PCTS */
1926 if (okay || tmp->tm_isdst < 0)
1928 #endif /* !defined PCTS */
1930 ** We're supposed to assume that somebody took a time of one type
1931 ** and did some math on it that yielded a "struct tm" that's bad.
1932 ** We try to divine the type they started from and adjust to the
1935 sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr);
1939 #endif /* defined ALL_STATE */
1940 for (i = 0; i < sp->typecnt; ++i)
1943 for (i = sp->timecnt - 1; i >= 0; --i)
1944 if (!seen[sp->types[i]]) {
1945 seen[sp->types[i]] = TRUE;
1946 types[nseen++] = sp->types[i];
1948 for (sameind = 0; sameind < nseen; ++sameind) {
1949 samei = types[sameind];
1950 if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
1952 for (otherind = 0; otherind < nseen; ++otherind) {
1953 otheri = types[otherind];
1954 if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
1956 tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
1957 sp->ttis[samei].tt_gmtoff;
1958 tmp->tm_isdst = !tmp->tm_isdst;
1959 t = time2(tmp, funcp, offset, &okay);
1962 tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff -
1963 sp->ttis[samei].tt_gmtoff;
1964 tmp->tm_isdst = !tmp->tm_isdst;
1972 struct tm * const tmp;
1975 return time1(tmp, localsub, 0L);
1982 struct tm * const tmp;
1985 tmp->tm_isdst = -1; /* in case it wasn't initialized */
1991 struct tm * const tmp;
1995 return time1(tmp, gmtsub, 0L);
1999 timeoff(tmp, offset)
2000 struct tm * const tmp;
2005 return time1(tmp, gmtsub, offset);
2008 #endif /* defined STD_INSPIRED */
2013 ** The following is supplied for compatibility with
2014 ** previous versions of the CMUCS runtime library.
2019 struct tm * const tmp;
2021 const time_t t = mktime(tmp);
2028 #endif /* defined CMUCS */
2031 ** XXX--is the below the right way to conditionalize??
2037 ** IEEE Std 1003.1-1988 (POSIX) legislates that 536457599
2038 ** shall correspond to "Wed Dec 31 23:59:59 UTC 1986", which
2039 ** is not the case if we are accounting for leap seconds.
2040 ** So, we provide the following conversion routines for use
2041 ** when exchanging timestamps with POSIX conforming systems.
2048 register struct state * sp;
2049 register struct lsinfo * lp;
2056 if (*timep >= lp->ls_trans)
2067 return t - leapcorr(&t);
2079 ** For a positive leap second hit, the result
2080 ** is not unique. For a negative leap second
2081 ** hit, the corresponding time doesn't exist,
2082 ** so we return an adjacent second.
2084 x = t + leapcorr(&t);
2085 y = x - leapcorr(&x);
2089 y = x - leapcorr(&x);
2096 y = x - leapcorr(&x);
2104 #endif /* defined STD_INSPIRED */