Lines Matching +full:early +full:- +full:to +full:- +full:mid

1 /* Convert timestamp from time_t to struct tm.  */
5 ** 1996-06-05 by Arthur David Olson.
10 ** POSIX.1-1988 style TZ environment variable handling from Guy Harris.
28 #include "un-namespace.h"
53 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._"
61 ** Support non-POSIX platforms that distinguish between text and binary files.
75 ** 3. They might reference tzname[1] after setting to a time zone
77 ** 4. They might reference tzname[0] after setting to a time zone
80 ** What's best to do in the above cases is open to debate;
82 ** WILDABBR is used. Another possibility: initialize tzname[0] to the
84 ** And another: initialize tzname[0] to "ERA", with an explanation in the
94 static char const *utc = etc_utc + sizeof "Etc/" - 1;
97 ** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
98 ** Default to US rules as of 2017-05-07.
108 bool tt_isdst; /* used to set tm_isdst */
116 int_fast32_t ls_corr; /* correction to apply */
120 static char const UNSPEC[] = "-00";
123 This needs to be at least 1 for null termination in case the input
124 data isn't properly terminated, and it also needs to be big enough
125 for ttunspecified to work without crashing. */
126 enum { CHARS_EXTRA = max(sizeof UNSPEC, 2) - 1 };
128 /* Limit to time zone abbreviation length in proleptic TZ strings.
209 ** Section 4.12.3 of X3.159-1989 requires that
212 ** objects: a broken-down time structure and an array of char.
213 ** Thanks to Paul Eggert for noting this.
216 ** Follow the requirement if SUPPORT_C89, even though this is more likely to
238 /* Initialize *S to a value based on UTOFF, ISDST, and DESIGIDX. */
242 s->tt_utoff = utoff;
243 s->tt_isdst = isdst;
244 s->tt_desigidx = desigidx;
245 s->tt_ttisstd = false;
246 s->tt_ttisut = false;
253 char const *abbr = &sp->chars[sp->ttis[i].tt_desigidx];
254 /* memcmp is likely faster than strcmp, and is safe due to CHARS_EXTRA. */
264 int_fast32_t halfmaxval = one << (32 - 2);
265 int_fast32_t maxval = halfmaxval - 1 + halfmaxval;
266 int_fast32_t minval = -1 - maxval;
273 /* Do two's-complement negation even on non-two's-complement machines.
274 If the result would be minval - 1, return minval. */
275 result -= !TWOS_COMPLEMENT(int_fast32_t) && result != 0;
287 int_fast64_t halfmaxval = one << (64 - 2);
288 int_fast64_t maxval = halfmaxval - 1 + halfmaxval;
289 int_fast64_t minval = -TWOS_COMPLEMENT(int_fast64_t) - maxval;
296 /* Do two's-complement negation even on non-two's-complement machines.
297 If the result would be minval - 1, return minval. */
298 result -= !TWOS_COMPLEMENT(int_fast64_t) && result != 0;
308 tzname[ttisp->tt_isdst] = (char *) &sp->chars[ttisp->tt_desigidx];
311 if (!ttisp->tt_isdst)
312 timezone = - ttisp->tt_utoff;
315 if (ttisp->tt_isdst)
316 altzone = - ttisp->tt_utoff;
327 struct ttinfo *ttisp = &sp->ttis[type];
328 int this_bit = 1 << ttisp->tt_isdst;
361 ** And to get the latest time zone abbreviations into tzname. . .
364 for (i = sp->timecnt - 1; stddst_mask && 0 <= i; i--)
365 stddst_mask = may_update_tzname_etc(stddst_mask, sp, sp->types[i]);
366 for (i = sp->typecnt - 1; stddst_mask && 0 <= i; i--)
383 for (i = 0; i < sp->charcnt - (TZNAME_MAXIMUM + 1); ) {
384 int len = strlen(&sp->chars[i]);
391 for (i = 0; i < sp->charcnt; ++i)
392 if (strchr(TZ_ABBR_CHAR_SET, sp->chars[i]) == NULL)
393 sp->chars[i] = TZ_ABBR_ERR_CHAR;
401 * Returns: -1 on error
415 return -1;
462 /* The name of the file to be opened. Ideally this would have no
463 size limits, to support arbitrarily long Zone names.
464 Limiting Zone names to 1024 bytes should suffice for practical use.
465 However, there is no need for this to be smaller than struct
482 register union input_buffer *up = &lsp->u.u;
485 sp->goback = sp->goahead = false;
496 if (sizeof lsp->fullname - sizeof tzdirslash <= strlen(name))
502 memcpy(lsp->fullname, tzdirslash, sizeof tzdirslash);
503 strcpy(lsp->fullname + sizeof tzdirslash, name);
505 name = lsp->fullname;
510 * 'doextend' to ignore TZDEFRULES; the change_in_tz()
526 nread = _read(fid, up->buf, sizeof up->buf);
535 char version = up->tzhead.tzh_version[0];
538 int_fast32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt);
539 int_fast32_t ttisutcnt = detzcode(up->tzhead.tzh_ttisutcnt);
540 int_fast64_t prevtr = -1;
542 int_fast32_t leapcnt = detzcode(up->tzhead.tzh_leapcnt);
543 int_fast32_t timecnt = detzcode(up->tzhead.tzh_timecnt);
544 int_fast32_t typecnt = detzcode(up->tzhead.tzh_typecnt);
545 int_fast32_t charcnt = detzcode(up->tzhead.tzh_charcnt);
546 char const *p = up->buf + tzheadsize;
547 /* Although tzfile(5) currently requires typecnt to be nonzero,
574 sp->leapcnt = leapcnt;
575 sp->timecnt = timecnt;
576 sp->typecnt = typecnt;
577 sp->charcnt = charcnt;
583 for (i = 0; i < sp->timecnt; ++i) {
586 sp->types[i] = at <= TIME_T_MAX;
587 if (sp->types[i]) {
591 if (timecnt && attime <= sp->ats[timecnt - 1]) {
592 if (attime < sp->ats[timecnt - 1])
594 sp->types[i - 1] = 0;
595 timecnt--;
597 sp->ats[timecnt++] = attime;
603 for (i = 0; i < sp->timecnt; ++i) {
605 if (sp->typecnt <= typ)
607 if (sp->types[i])
608 sp->types[timecnt++] = typ;
610 sp->timecnt = timecnt;
611 for (i = 0; i < sp->typecnt; ++i) {
615 ttisp = &sp->ttis[i];
616 ttisp->tt_utoff = detzcode(p);
621 ttisp->tt_isdst = isdst;
623 if (! (desigidx < sp->charcnt))
625 ttisp->tt_desigidx = desigidx;
627 for (i = 0; i < sp->charcnt; ++i)
628 sp->chars[i] = *p++;
629 /* Ensure '\0'-terminated, and make it safe to call
631 memset(&sp->chars[i], 0, CHARS_EXTRA);
635 for (i = 0; i < sp->leapcnt; ++i) {
645 /* To avoid other botches in this code, each leap second's
649 RFC 8536, to allow future RFC extensions. */
654 || corr == prevcorr - 1))))
660 sp->lsis[leapcnt].ls_trans = tr;
661 sp->lsis[leapcnt].ls_corr = corr;
665 sp->leapcnt = leapcnt;
667 for (i = 0; i < sp->typecnt; ++i) {
670 ttisp = &sp->ttis[i];
672 ttisp->tt_ttisstd = false;
676 ttisp->tt_ttisstd = *p++;
679 for (i = 0; i < sp->typecnt; ++i) {
682 ttisp = &sp->ttis[i];
684 ttisp->tt_ttisut = false;
688 ttisp->tt_ttisut = *p++;
693 nread -= p - up->buf;
694 memmove(up->buf, p, nread);
701 up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
702 sp->typecnt + 2 <= TZ_MAX_TYPES) {
703 struct state *ts = &lsp->u.st;
705 up->buf[nread - 1] = '\0';
706 if (tzparse(&up->buf[1], ts, sp)) {
708 /* Attempt to reuse existing abbreviations.
711 sp->charcnt equals 40 (for LMT AST AWT APT AHST
712 AHDT YST AKDT AKST) and ts->charcnt equals 10
713 (for AKST AKDT). Reusing means sp->charcnt can
716 int charcnt = sp->charcnt;
717 for (i = 0; i < ts->typecnt; i++) {
718 char *tsabbr = ts->chars + ts->ttis[i].tt_desigidx;
721 if (strcmp(sp->chars + j, tsabbr) == 0) {
722 ts->ttis[i].tt_desigidx = j;
729 strcpy(sp->chars + j, tsabbr);
731 ts->ttis[i].tt_desigidx = j;
736 if (gotabbr == ts->typecnt) {
737 sp->charcnt = charcnt;
739 /* Ignore any trailing, no-op transitions generated
742 while (1 < sp->timecnt
743 && (sp->types[sp->timecnt - 1]
744 == sp->types[sp->timecnt - 2]))
745 sp->timecnt--;
747 sp->goahead = ts->goahead;
749 for (i = 0; i < ts->timecnt; i++) {
750 time_t t = ts->ats[i];
752 || (0 < sp->timecnt
753 && t <= sp->ats[sp->timecnt - 1]))
755 if (TZ_MAX_TIMES <= sp->timecnt) {
756 sp->goahead = false;
759 sp->ats[sp->timecnt] = t;
760 sp->types[sp->timecnt] = (sp->typecnt
761 + ts->types[i]);
762 sp->timecnt++;
764 for (i = 0; i < ts->typecnt; i++)
765 sp->ttis[sp->typecnt++] = ts->ttis[i];
769 if (sp->typecnt == 0)
814 ** Return a pointer to that character.
822 while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
831 ** Return a pointer to the delimiter.
835 ** We don't do any checking here; checking is done later in common-case code.
852 ** Otherwise, return a pointer to the first character not part of the number.
865 num = num * 10 + (c - '0');
880 ** Otherwise, return a pointer to the first character not part of the number
891 ** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-POSIX rules like
892 ** "M10.4.6/26", which does not conform to POSIX,
896 strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
902 strp = getnum(strp, &num, 0, MINSPERHOUR - 1);
920 ** [+-]hh[:mm[:ss]] form, from the string.
922 ** Otherwise, return a pointer to the first character not part of the time.
930 if (*strp == '-') {
939 *offsetp = -*offsetp;
948 ** Otherwise, return a pointer to the first character not part of the rule.
958 rulep->r_type = JULIAN_DAY;
960 strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
965 rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
967 strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
972 strp = getnum(strp, &rulep->r_week, 1, 5);
977 strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
982 rulep->r_type = DAY_OF_YEAR;
983 strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
992 strp = getoffset(strp, &rulep->r_time);
993 } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
999 ** effect, calculate the year-relative time that rule takes effect.
1012 switch (rulep->r_type) {
1016 ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
1018 ** In non-leap years, or if the day number is 59 or less, just
1019 ** add SECSPERDAY times the day number-1 to the time of
1020 ** January 1, midnight, to get the day.
1022 value = (rulep->r_day - 1) * SECSPERDAY;
1023 if (leapyear && rulep->r_day >= 60)
1029 ** n - day of year.
1030 ** Just add SECSPERDAY times the day number to the time of
1031 ** January 1, midnight, to get the day.
1033 value = rulep->r_day * SECSPERDAY;
1038 ** Mm.n.d - nth "dth day" of month m.
1042 ** Use Zeller's Congruence to get day-of-week of first day of
1045 m1 = (rulep->r_mon + 9) % 12 + 1;
1046 yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
1049 dow = ((26 * m1 - 2) / 10 +
1050 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
1055 ** "dow" is the day-of-week of the first day of the month. Get
1056 ** the day-of-month (zero-origin) of the first "dow" day of the
1059 d = rulep->r_day - dow;
1062 for (i = 1; i < rulep->r_week; ++i) {
1064 mon_lengths[leapyear][rulep->r_mon - 1])
1070 ** "d" is the day-of-month (zero-origin) of the day we want.
1073 for (i = 0; i < rulep->r_mon - 1; ++i)
1081 ** "value" is the year-relative time of 00:00:00 UT on the day in
1082 ** question. To get the year-relative time of the specified local
1086 return value + rulep->r_time + offset;
1113 stdlen = name - stdname;
1117 stdlen = name - stdname;
1126 if (0 < basep->timecnt)
1127 atlo = basep->ats[basep->timecnt - 1];
1129 sp->leapcnt = basep->leapcnt;
1130 memcpy(sp->lsis, basep->lsis, sp->leapcnt * sizeof *sp->lsis);
1134 sp->leapcnt = 0; /* So, we're off a little. */
1136 if (0 < sp->leapcnt)
1137 leaplo = sp->lsis[sp->leapcnt - 1].ls_trans;
1138 sp->goback = sp->goahead = false;
1145 dstlen = name - dstname;
1150 dstlen = name - dstname; /* length of DST abbr. */
1159 } else dstoffset = stdoffset - SECSPERHOUR;
1180 sp->typecnt = 2; /* standard time and DST */
1184 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0);
1185 init_ttinfo(&sp->ttis[1], -dstoffset, true, stdlen + 1);
1192 = year_lengths[isleap(yearbeg - 1)] * SECSPERDAY;
1194 yearbeg--;
1195 if (increment_overflow_time(&janfirst1, -yearsecs)) {
1196 janoffset = -yearsecs;
1201 && EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg);
1234 && endtime - starttime < yearsecs)) {
1235 if (TZ_MAX_TIMES - 2 < timecnt)
1237 sp->ats[timecnt] = janfirst;
1239 (&sp->ats[timecnt],
1241 && atlo <= sp->ats[timecnt])
1242 sp->types[timecnt++] = !reversed;
1243 sp->ats[timecnt] = janfirst;
1245 (&sp->ats[timecnt],
1247 && atlo <= sp->ats[timecnt]) {
1248 sp->types[timecnt++] = reversed;
1262 sp->timecnt = timecnt;
1264 sp->ttis[0] = sp->ttis[1];
1265 sp->typecnt = 1; /* Perpetual DST. */
1266 } else if (years_of_observations <= year - yearbeg)
1267 sp->goback = sp->goahead = true;
1282 for (i = 0; i < sp->timecnt; ++i) {
1283 j = sp->types[i];
1284 if (!sp->ttis[j].tt_isdst) {
1286 - sp->ttis[j].tt_utoff;
1291 for (i = 0; i < sp->timecnt; ++i) {
1292 j = sp->types[i];
1293 if (sp->ttis[j].tt_isdst) {
1295 - sp->ttis[j].tt_utoff;
1300 ** Initially we're assumed to be in standard time.
1307 for (i = 0; i < sp->timecnt; ++i) {
1308 j = sp->types[i];
1309 sp->types[i] = sp->ttis[j].tt_isdst;
1310 if (sp->ttis[j].tt_ttisut) {
1311 /* No adjustment to transition time */
1317 ** the daylight saving time offset to
1319 ** the standard time offset to the
1323 ** Transitions from DST to DDST
1328 if (isdst && !sp->ttis[j].tt_ttisstd) {
1329 sp->ats[i] += dstoffset -
1332 sp->ats[i] += stdoffset -
1336 theiroffset = -sp->ttis[j].tt_utoff;
1337 if (sp->ttis[j].tt_isdst)
1344 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0);
1345 init_ttinfo(&sp->ttis[1], -dstoffset, true, stdlen + 1);
1346 sp->typecnt = 2;
1350 sp->typecnt = 1; /* only standard time */
1351 sp->timecnt = 0;
1352 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0);
1354 sp->charcnt = charcnt;
1355 cp = sp->chars;
1383 * We want to recheck the timezone file every 61 sec.
1392 if ((current_time - last_checked > DETECT_TZ_CHANGES_INTERVAL) ||
1404 /* Initialize *SP to a value appropriate for the TZ setting NAME.
1413 sp->leapcnt = 0; /* so, we're off a little */
1414 sp->timecnt = 0;
1415 sp->typecnt = 0;
1416 sp->charcnt = 0;
1417 sp->goback = sp->goahead = false;
1418 init_ttinfo(&sp->ttis[0], 0, false, 0);
1419 strcpy(sp->chars, utc);
1435 int lcl = name ? strlen(name) < sizeof lcl_TZname : -1;
1525 ** POSIX.1-2024 removes ctime_r. Both have potential security problems that
1536 ** The easy way to behave "as if no library function calls" localtime
1537 ** is to not call it, so we drop its guts into "localsub", which can be
1543 ** however, it's OK to omit this step for proleptic TZ strings
1560 /* Don't bother to set tzname etc.; tzset has already done it. */
1563 if ((sp->goback && t < sp->ats[0]) ||
1564 (sp->goahead && t > sp->ats[sp->timecnt - 1])) {
1569 if (t < sp->ats[0])
1570 seconds = sp->ats[0] - t;
1571 else seconds = t - sp->ats[sp->timecnt - 1];
1572 --seconds;
1575 be close to the maximum time_t. */
1579 if (t < sp->ats[0])
1582 newt = t - seconds - SECSPERREPEAT;
1584 if (newt < sp->ats[0] ||
1585 newt > sp->ats[sp->timecnt - 1])
1590 if (t < sp->ats[0]
1591 ? ckd_sub(&result->tm_year,
1592 result->tm_year, years)
1593 : ckd_add(&result->tm_year,
1594 result->tm_year, years))
1599 newy = result->tm_year;
1600 if (t < sp->ats[0])
1601 newy -= years;
1605 result->tm_year = newy;
1610 if (sp->timecnt == 0 || t < sp->ats[0]) {
1614 register int hi = sp->timecnt;
1617 register int mid = (lo + hi) >> 1;
1619 if (t < sp->ats[mid])
1620 hi = mid;
1621 else lo = mid + 1;
1623 i = sp->types[lo - 1];
1625 ttisp = &sp->ttis[i];
1627 ** To get (wrong) behavior that's compatible with System V Release 2.0
1629 ** t += ttisp->tt_utoff;
1632 result = timesub(&t, ttisp->tt_utoff, sp, tmp);
1634 result->tm_isdst = ttisp->tt_isdst;
1636 result->TM_ZONE = (char *) &sp->chars[ttisp->tt_desigidx];
1713 ** gmtsub is to gmtime as localsub is to localtime.
1726 ** "+xx" or "-xx" if offset is non-zero,
1729 tmp->TM_ZONE = ((char *)
1730 (offset ? wildabbr : gmtptr ? gmtptr->chars : utc));
1736 * Re-entrant version of gmtime.
1783 Callers can instead use localtime_rz with a fixed-offset zone. */
1830 ** where, to make the math easy, the answer for year zero is defined as zero.
1836 return y / 4 - y / 100 + y / 400;
1843 ? -1 - leaps_thru_end_of_nonneg(-1 - y)
1861 to localtime tm_sec because of leap seconds. */
1865 i = (sp == NULL) ? 0 : sp->leapcnt;
1866 while (--i >= 0) {
1867 lp = &sp->lsis[i];
1868 if (*timep >= lp->ls_trans) {
1869 corr = lp->ls_corr;
1870 if ((i == 0 ? 0 : lp[-1].ls_corr) < corr)
1871 secs_since_posleap = *timep - lp->ls_trans;
1880 rem += offset % SECSPERDAY - corr % SECSPERDAY + 3 * SECSPERDAY;
1881 dayoff = offset / SECSPERDAY - corr / SECSPERDAY + rem / SECSPERDAY - 3;
1885 sans overflow. But calculate against 1570 (EPOCH_YEAR -
1890 y = (EPOCH_YEAR - YEARSPERREPEAT
1892 - ((dayrem % DAYSPERREPEAT) < 0)
1905 leapdays = leaps_thru_end_of(newy - 1) -
1906 leaps_thru_end_of(y - 1);
1907 idays -= ydelta * DAYSPERNYEAR;
1908 idays -= leapdays;
1913 if (ckd_add(&tmp->tm_year, y, -TM_YEAR_BASE)) {
1920 tmp->tm_year = signed_y - TM_YEAR_BASE;
1922 && y - TM_YEAR_BASE <= INT_MAX)
1923 tmp->tm_year = y - TM_YEAR_BASE;
1929 tmp->tm_yday = idays;
1933 tmp->tm_wday = (TM_WDAY_BASE
1934 + ((tmp->tm_year % DAYSPERWEEK)
1936 + leaps_thru_end_of(y - 1)
1937 - leaps_thru_end_of(TM_YEAR_BASE - 1)
1939 tmp->tm_wday %= DAYSPERWEEK;
1940 if (tmp->tm_wday < 0)
1941 tmp->tm_wday += DAYSPERWEEK;
1942 tmp->tm_hour = rem / SECSPERHOUR;
1944 tmp->tm_min = rem / SECSPERMIN;
1945 tmp->tm_sec = rem % SECSPERMIN;
1949 tmp->tm_sec += secs_since_posleap <= tmp->tm_sec;
1952 for (tmp->tm_mon = 0; idays >= ip[tmp->tm_mon]; ++(tmp->tm_mon))
1953 idays -= ip[tmp->tm_mon];
1954 tmp->tm_mday = idays + 1;
1955 tmp->tm_isdst = 0;
1957 tmp->TM_GMTOFF = offset;
1964 ** The "best" way to do mktime I think is based on an idea of Bob
1972 # define WRONG (-1)
1989 ** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
1991 ** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
1993 if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
2008 if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
2027 ? (TYPE_SIGNED(time_t) ? TIME_T_MIN - j <= *tp : -1 - j < *tp)
2028 : *tp <= TIME_T_MAX - j))
2042 (-1 - (-1 - *unitsptr) / base);
2043 *unitsptr -= tensdelta * base;
2054 (-1 - (-1 - *unitsptr) / base);
2055 *unitsptr -= tensdelta * base;
2065 if (atmp->tm_year != btmp->tm_year)
2066 return atmp->tm_year < btmp->tm_year ? -1 : 1;
2067 if ((result = (atmp->tm_mon - btmp->tm_mon)) == 0 &&
2068 (result = (atmp->tm_mday - btmp->tm_mday)) == 0 &&
2069 (result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
2070 (result = (atmp->tm_min - btmp->tm_min)) == 0)
2071 result = atmp->tm_sec - btmp->tm_sec;
2075 /* Copy to *DEST from *SRC. Copy only the members needed for mktime,
2080 dest->tm_sec = src->tm_sec;
2081 dest->tm_min = src->tm_min;
2082 dest->tm_hour = src->tm_hour;
2083 dest->tm_mday = src->tm_mday;
2084 dest->tm_mon = src->tm_mon;
2085 dest->tm_year = src->tm_year;
2086 dest->tm_isdst = src->tm_isdst;
2088 dest->TM_GMTOFF = src->TM_GMTOFF;
2129 ** It is converted back to an offset from TM_YEAR_BASE later.
2134 if (increment_overflow32(&y, -1))
2141 yourtm.tm_mday -= year_lengths[isleap(li)];
2149 yourtm.tm_mday -= i;
2157 if (ckd_add(&yourtm.tm_year, y, -TM_YEAR_BASE))
2160 if (increment_overflow32(&y, -TM_YEAR_BASE))
2168 else if (yourtm.tm_year < EPOCH_YEAR - TM_YEAR_BASE) {
2170 ** We can't set tm_sec to 0, because that might push the
2172 ** Set tm_sec to 59 instead.
2177 if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
2180 yourtm.tm_sec = SECSPERMIN - 1;
2198 ** Assume that t is too extreme to be represented in
2202 dir = (t > 0) ? 1 : -1;
2213 --t;
2214 --hi;
2226 ? (-SECSPERDAY <= yourtm.TM_GMTOFF
2239 int_fast32_t diff = mytm.TM_GMTOFF - yourtm.TM_GMTOFF;
2257 ** It's okay to guess wrong since the guess
2262 for (i = sp->typecnt - 1; i >= 0; --i) {
2263 if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
2265 for (j = sp->typecnt - 1; j >= 0; --j) {
2266 if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
2270 newt = (t + sp->ttis[j].tt_utoff
2271 - sp->ttis[i].tt_utoff);
2337 if (tmp->tm_isdst > 1)
2338 tmp->tm_isdst = 1;
2342 if (tmp->tm_isdst < 0)
2347 tmp->tm_isdst = 0; /* reset to std and try again */
2352 ** We're supposed to assume that somebody took a time of one type
2354 ** We try to divine the type they started from and adjust to the
2359 for (i = 0; i < sp->typecnt; ++i)
2362 for (i = sp->timecnt - 1; i >= 0; --i)
2363 if (!seen[sp->types[i]] && !ttunspecified(sp, sp->types[i])) {
2364 seen[sp->types[i]] = true;
2365 types[nseen++] = sp->types[i];
2369 if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
2373 if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
2375 tmp->tm_sec += (sp->ttis[otheri].tt_utoff
2376 - sp->ttis[samei].tt_utoff);
2377 tmp->tm_isdst = !tmp->tm_isdst;
2381 tmp->tm_sec -= (sp->ttis[otheri].tt_utoff
2382 - sp->ttis[samei].tt_utoff);
2383 tmp->tm_isdst = !tmp->tm_isdst;
2417 return -1;
2432 tmp->tm_isdst = -1; /* in case it wasn't initialized */
2445 Callers can instead use mktime_z with a fixed-offset zone. */
2450 tmp->tm_isdst = 0;
2461 tmcpy.tm_wday = -1;
2474 i = sp->leapcnt;
2475 while (--i >= 0) {
2476 lp = &sp->lsis[i];
2477 if (t >= lp->ls_trans)
2478 return lp->ls_corr;
2484 ** XXX--is the below the right way to conditionalize??
2489 /* NETBSD_INSPIRED_EXTERN functions are exported to callers if
2499 ** shall correspond to "Wed Dec 31 23:59:59 UTC 1986", which
2508 return t - leapcorr(sp, t);
2517 return -1;
2541 y = x - leapcorr(sp, x);
2545 y = x - leapcorr(sp, x);
2547 x -= y != t;
2550 --x;
2551 y = x - leapcorr(sp, x);
2564 return -1;
2588 /* Convert from the underlying system's time_t to the ersatz time_tz,
2594 Although this code appears to define a function named 'time' that
2595 returns time_t, the macros in private.h cause this code to actually
2597 to sys_time invokes the underlying system's 'time' function. */
2603 if (r != (time_t) -1) {
2605 if (increment_overflow32(&offset, -EPOCH_OFFSET)
2608 r = -1;