Lines Matching +full:offset +full:- +full:y
5 ** 1996-06-05 by Arthur David Olson.
10 ** POSIX.1-1988 style TZ environment variable handling from Guy Harris.
29 #include "un-namespace.h"
54 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._"
62 ** Support non-POSIX platforms that distinguish between text and binary files.
95 static char const *utc = etc_utc + sizeof "Etc/" - 1;
99 ** Default to US rules as of 2017-05-07.
108 int_fast32_t tt_utoff; /* UT offset in seconds */
121 static char const UNSPEC[] = "-00";
127 enum { CHARS_EXTRA = max(sizeof UNSPEC, 2) - 1 };
210 ** Section 4.12.3 of X3.159-1989 requires that
213 ** objects: a broken-down time structure and an array of char.
243 s->tt_utoff = utoff; in init_ttinfo()
244 s->tt_isdst = isdst; in init_ttinfo()
245 s->tt_desigidx = desigidx; in init_ttinfo()
246 s->tt_ttisstd = false; in init_ttinfo()
247 s->tt_ttisut = false; in init_ttinfo()
254 char const *abbr = &sp->chars[sp->ttis[i].tt_desigidx]; in ttunspecified()
265 int_fast32_t halfmaxval = one << (32 - 2); in detzcode()
266 int_fast32_t maxval = halfmaxval - 1 + halfmaxval; in detzcode()
267 int_fast32_t minval = -1 - maxval; in detzcode()
274 /* Do two's-complement negation even on non-two's-complement machines. in detzcode()
275 If the result would be minval - 1, return minval. */ in detzcode()
276 result -= !TWOS_COMPLEMENT(int_fast32_t) && result != 0; in detzcode()
288 int_fast64_t halfmaxval = one << (64 - 2); in detzcode64()
289 int_fast64_t maxval = halfmaxval - 1 + halfmaxval; in detzcode64()
290 int_fast64_t minval = -TWOS_COMPLEMENT(int_fast64_t) - maxval; in detzcode64()
297 /* Do two's-complement negation even on non-two's-complement machines. in detzcode64()
298 If the result would be minval - 1, return minval. */ in detzcode64()
299 result -= !TWOS_COMPLEMENT(int_fast64_t) && result != 0; in detzcode64()
309 tzname[ttisp->tt_isdst] = (char *) &sp->chars[ttisp->tt_desigidx]; in update_tzname_etc()
312 if (!ttisp->tt_isdst) in update_tzname_etc()
313 timezone = - ttisp->tt_utoff; in update_tzname_etc()
316 if (ttisp->tt_isdst) in update_tzname_etc()
317 altzone = - ttisp->tt_utoff; in update_tzname_etc()
328 struct ttinfo *ttisp = &sp->ttis[type]; in may_update_tzname_etc()
329 int this_bit = 1 << ttisp->tt_isdst; in may_update_tzname_etc()
365 for (i = sp->timecnt - 1; stddst_mask && 0 <= i; i--) in settzname()
366 stddst_mask = may_update_tzname_etc(stddst_mask, sp, sp->types[i]); in settzname()
367 for (i = sp->typecnt - 1; stddst_mask && 0 <= i; i--) in settzname()
384 for (i = 0; i < sp->charcnt - (TZNAME_MAXIMUM + 1); ) { in scrub_abbrs()
385 int len = strlen(&sp->chars[i]); in scrub_abbrs()
392 for (i = 0; i < sp->charcnt; ++i) in scrub_abbrs()
393 if (strchr(TZ_ABBR_CHAR_SET, sp->chars[i]) == NULL) in scrub_abbrs()
394 sp->chars[i] = TZ_ABBR_ERR_CHAR; in scrub_abbrs()
402 * Returns: -1 on error
414 return -1; in change_in_tz()
481 register union input_buffer *up = &lsp->u.u; in tzloadbody()
484 sp->goback = sp->goahead = false; in tzloadbody()
495 if (sizeof lsp->fullname - sizeof tzdirslash <= strlen(name)) in tzloadbody()
501 memcpy(lsp->fullname, tzdirslash, sizeof tzdirslash); in tzloadbody()
502 strcpy(lsp->fullname + sizeof tzdirslash, name); in tzloadbody()
504 name = lsp->fullname; in tzloadbody()
513 case -1: in tzloadbody()
525 nread = _read(fid, up->buf, sizeof up->buf); in tzloadbody()
534 char version = up->tzhead.tzh_version[0]; in tzloadbody()
537 int_fast32_t ttisstdcnt = detzcode(up->tzhead.tzh_ttisstdcnt); in tzloadbody()
538 int_fast32_t ttisutcnt = detzcode(up->tzhead.tzh_ttisutcnt); in tzloadbody()
539 int_fast64_t prevtr = -1; in tzloadbody()
541 int_fast32_t leapcnt = detzcode(up->tzhead.tzh_leapcnt); in tzloadbody()
542 int_fast32_t timecnt = detzcode(up->tzhead.tzh_timecnt); in tzloadbody()
543 int_fast32_t typecnt = detzcode(up->tzhead.tzh_typecnt); in tzloadbody()
544 int_fast32_t charcnt = detzcode(up->tzhead.tzh_charcnt); in tzloadbody()
545 char const *p = up->buf + tzheadsize; in tzloadbody()
573 sp->leapcnt = leapcnt; in tzloadbody()
574 sp->timecnt = timecnt; in tzloadbody()
575 sp->typecnt = typecnt; in tzloadbody()
576 sp->charcnt = charcnt; in tzloadbody()
582 for (i = 0; i < sp->timecnt; ++i) { in tzloadbody()
585 sp->types[i] = at <= TIME_T_MAX; in tzloadbody()
586 if (sp->types[i]) { in tzloadbody()
590 if (timecnt && attime <= sp->ats[timecnt - 1]) { in tzloadbody()
591 if (attime < sp->ats[timecnt - 1]) in tzloadbody()
593 sp->types[i - 1] = 0; in tzloadbody()
594 timecnt--; in tzloadbody()
596 sp->ats[timecnt++] = attime; in tzloadbody()
602 for (i = 0; i < sp->timecnt; ++i) { in tzloadbody()
604 if (sp->typecnt <= typ) in tzloadbody()
606 if (sp->types[i]) in tzloadbody()
607 sp->types[timecnt++] = typ; in tzloadbody()
609 sp->timecnt = timecnt; in tzloadbody()
610 for (i = 0; i < sp->typecnt; ++i) { in tzloadbody()
614 ttisp = &sp->ttis[i]; in tzloadbody()
615 ttisp->tt_utoff = detzcode(p); in tzloadbody()
620 ttisp->tt_isdst = isdst; in tzloadbody()
622 if (! (desigidx < sp->charcnt)) in tzloadbody()
624 ttisp->tt_desigidx = desigidx; in tzloadbody()
626 for (i = 0; i < sp->charcnt; ++i) in tzloadbody()
627 sp->chars[i] = *p++; in tzloadbody()
628 /* Ensure '\0'-terminated, and make it safe to call in tzloadbody()
630 memset(&sp->chars[i], 0, CHARS_EXTRA); in tzloadbody()
634 for (i = 0; i < sp->leapcnt; ++i) { in tzloadbody()
653 || corr == prevcorr - 1)))) in tzloadbody()
659 sp->lsis[leapcnt].ls_trans = tr; in tzloadbody()
660 sp->lsis[leapcnt].ls_corr = corr; in tzloadbody()
664 sp->leapcnt = leapcnt; in tzloadbody()
666 for (i = 0; i < sp->typecnt; ++i) { in tzloadbody()
669 ttisp = &sp->ttis[i]; in tzloadbody()
671 ttisp->tt_ttisstd = false; in tzloadbody()
675 ttisp->tt_ttisstd = *p++; in tzloadbody()
678 for (i = 0; i < sp->typecnt; ++i) { in tzloadbody()
681 ttisp = &sp->ttis[i]; in tzloadbody()
683 ttisp->tt_ttisut = false; in tzloadbody()
687 ttisp->tt_ttisut = *p++; in tzloadbody()
692 nread -= p - up->buf; in tzloadbody()
693 memmove(up->buf, p, nread); in tzloadbody()
700 up->buf[0] == '\n' && up->buf[nread - 1] == '\n' && in tzloadbody()
701 sp->typecnt + 2 <= TZ_MAX_TYPES) { in tzloadbody()
702 struct state *ts = &lsp->u.st; in tzloadbody()
704 up->buf[nread - 1] = '\0'; in tzloadbody()
705 if (tzparse(&up->buf[1], ts, sp)) { in tzloadbody()
710 sp->charcnt equals 40 (for LMT AST AWT APT AHST in tzloadbody()
711 AHDT YST AKDT AKST) and ts->charcnt equals 10 in tzloadbody()
712 (for AKST AKDT). Reusing means sp->charcnt can in tzloadbody()
715 int charcnt = sp->charcnt; in tzloadbody()
716 for (i = 0; i < ts->typecnt; i++) { in tzloadbody()
717 char *tsabbr = ts->chars + ts->ttis[i].tt_desigidx; in tzloadbody()
720 if (strcmp(sp->chars + j, tsabbr) == 0) { in tzloadbody()
721 ts->ttis[i].tt_desigidx = j; in tzloadbody()
728 strcpy(sp->chars + j, tsabbr); in tzloadbody()
730 ts->ttis[i].tt_desigidx = j; in tzloadbody()
735 if (gotabbr == ts->typecnt) { in tzloadbody()
736 sp->charcnt = charcnt; in tzloadbody()
738 /* Ignore any trailing, no-op transitions generated in tzloadbody()
741 while (1 < sp->timecnt in tzloadbody()
742 && (sp->types[sp->timecnt - 1] in tzloadbody()
743 == sp->types[sp->timecnt - 2])) in tzloadbody()
744 sp->timecnt--; in tzloadbody()
746 sp->goahead = ts->goahead; in tzloadbody()
748 for (i = 0; i < ts->timecnt; i++) { in tzloadbody()
749 time_t t = ts->ats[i]; in tzloadbody()
751 || (0 < sp->timecnt in tzloadbody()
752 && t <= sp->ats[sp->timecnt - 1])) in tzloadbody()
754 if (TZ_MAX_TIMES <= sp->timecnt) { in tzloadbody()
755 sp->goahead = false; in tzloadbody()
758 sp->ats[sp->timecnt] = t; in tzloadbody()
759 sp->types[sp->timecnt] = (sp->typecnt in tzloadbody()
760 + ts->types[i]); in tzloadbody()
761 sp->timecnt++; in tzloadbody()
763 for (i = 0; i < ts->typecnt; i++) in tzloadbody()
764 sp->ttis[sp->typecnt++] = ts->ttis[i]; in tzloadbody()
768 if (sp->typecnt == 0) in tzloadbody()
821 while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && in getzname()
834 ** We don't do any checking here; checking is done later in common-case code.
864 num = num * 10 + (c - '0'); in getnum()
890 ** 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-POSIX rules like in getsecs()
895 strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); in getsecs()
901 strp = getnum(strp, &num, 0, MINSPERHOUR - 1); in getsecs()
918 ** Given a pointer into a timezone string, extract an offset, in
919 ** [+-]hh[:mm[:ss]] form, from the string.
929 if (*strp == '-') { in getoffset()
938 *offsetp = -*offsetp; in getoffset()
957 rulep->r_type = JULIAN_DAY; in getrule()
959 strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); in getrule()
964 rulep->r_type = MONTH_NTH_DAY_OF_WEEK; in getrule()
966 strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); in getrule()
971 strp = getnum(strp, &rulep->r_week, 1, 5); in getrule()
976 strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); in getrule()
981 rulep->r_type = DAY_OF_YEAR; in getrule()
982 strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); in getrule()
991 strp = getoffset(strp, &rulep->r_time); in getrule()
992 } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ in getrule()
997 ** Given a year, a rule, and the offset from UT at the time that rule takes
998 ** effect, calculate the year-relative time that rule takes effect.
1003 const int_fast32_t offset) in transtime() argument
1011 switch (rulep->r_type) { in transtime()
1015 ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap in transtime()
1017 ** In non-leap years, or if the day number is 59 or less, just in transtime()
1018 ** add SECSPERDAY times the day number-1 to the time of in transtime()
1021 value = (rulep->r_day - 1) * SECSPERDAY; in transtime()
1022 if (leapyear && rulep->r_day >= 60) in transtime()
1028 ** n - day of year. in transtime()
1032 value = rulep->r_day * SECSPERDAY; in transtime()
1037 ** Mm.n.d - nth "dth day" of month m. in transtime()
1041 ** Use Zeller's Congruence to get day-of-week of first day of in transtime()
1044 m1 = (rulep->r_mon + 9) % 12 + 1; in transtime()
1045 yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; in transtime()
1048 dow = ((26 * m1 - 2) / 10 + in transtime()
1049 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; in transtime()
1054 ** "dow" is the day-of-week of the first day of the month. Get in transtime()
1055 ** the day-of-month (zero-origin) of the first "dow" day of the in transtime()
1058 d = rulep->r_day - dow; in transtime()
1061 for (i = 1; i < rulep->r_week; ++i) { in transtime()
1063 mon_lengths[leapyear][rulep->r_mon - 1]) in transtime()
1069 ** "d" is the day-of-month (zero-origin) of the day we want. in transtime()
1072 for (i = 0; i < rulep->r_mon - 1; ++i) in transtime()
1080 ** "value" is the year-relative time of 00:00:00 UT on the day in in transtime()
1081 ** question. To get the year-relative time of the specified local in transtime()
1082 ** time on that day, add the transition time and the current offset in transtime()
1085 return value + rulep->r_time + offset; in transtime()
1112 stdlen = name - stdname; in tzparse()
1116 stdlen = name - stdname; in tzparse()
1125 if (0 < basep->timecnt) in tzparse()
1126 atlo = basep->ats[basep->timecnt - 1]; in tzparse()
1128 sp->leapcnt = basep->leapcnt; in tzparse()
1129 memcpy(sp->lsis, basep->lsis, sp->leapcnt * sizeof *sp->lsis); in tzparse()
1133 sp->leapcnt = 0; /* So, we're off a little. */ in tzparse()
1135 if (0 < sp->leapcnt) in tzparse()
1136 leaplo = sp->lsis[sp->leapcnt - 1].ls_trans; in tzparse()
1137 sp->goback = sp->goahead = false; in tzparse()
1144 dstlen = name - dstname; in tzparse()
1149 dstlen = name - dstname; /* length of DST abbr. */ in tzparse()
1158 } else dstoffset = stdoffset - SECSPERHOUR; in tzparse()
1179 sp->typecnt = 2; /* standard time and DST */ in tzparse()
1183 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0); in tzparse()
1184 init_ttinfo(&sp->ttis[1], -dstoffset, true, stdlen + 1); in tzparse()
1191 = year_lengths[isleap(yearbeg - 1)] * SECSPERDAY; in tzparse()
1193 yearbeg--; in tzparse()
1194 if (increment_overflow_time(&janfirst1, -yearsecs)) { in tzparse()
1195 janoffset = -yearsecs; in tzparse()
1200 && EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg); in tzparse()
1233 && endtime - starttime < yearsecs)) { in tzparse()
1234 if (TZ_MAX_TIMES - 2 < timecnt) in tzparse()
1236 sp->ats[timecnt] = janfirst; in tzparse()
1238 (&sp->ats[timecnt], in tzparse()
1240 && atlo <= sp->ats[timecnt]) in tzparse()
1241 sp->types[timecnt++] = !reversed; in tzparse()
1242 sp->ats[timecnt] = janfirst; in tzparse()
1244 (&sp->ats[timecnt], in tzparse()
1246 && atlo <= sp->ats[timecnt]) { in tzparse()
1247 sp->types[timecnt++] = reversed; in tzparse()
1261 sp->timecnt = timecnt; in tzparse()
1263 sp->ttis[0] = sp->ttis[1]; in tzparse()
1264 sp->typecnt = 1; /* Perpetual DST. */ in tzparse()
1265 } else if (years_of_observations <= year - yearbeg) in tzparse()
1266 sp->goback = sp->goahead = true; in tzparse()
1281 for (i = 0; i < sp->timecnt; ++i) { in tzparse()
1282 j = sp->types[i]; in tzparse()
1283 if (!sp->ttis[j].tt_isdst) { in tzparse()
1285 - sp->ttis[j].tt_utoff; in tzparse()
1290 for (i = 0; i < sp->timecnt; ++i) { in tzparse()
1291 j = sp->types[i]; in tzparse()
1292 if (sp->ttis[j].tt_isdst) { in tzparse()
1294 - sp->ttis[j].tt_utoff; in tzparse()
1306 for (i = 0; i < sp->timecnt; ++i) { in tzparse()
1307 j = sp->types[i]; in tzparse()
1308 sp->types[i] = sp->ttis[j].tt_isdst; in tzparse()
1309 if (sp->ttis[j].tt_ttisut) { in tzparse()
1316 ** the daylight saving time offset to in tzparse()
1318 ** the standard time offset to the in tzparse()
1325 ** DST offset. in tzparse()
1327 if (isdst && !sp->ttis[j].tt_ttisstd) { in tzparse()
1328 sp->ats[i] += dstoffset - in tzparse()
1331 sp->ats[i] += stdoffset - in tzparse()
1335 theiroffset = -sp->ttis[j].tt_utoff; in tzparse()
1336 if (sp->ttis[j].tt_isdst) in tzparse()
1343 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0); in tzparse()
1344 init_ttinfo(&sp->ttis[1], -dstoffset, true, stdlen + 1); in tzparse()
1345 sp->typecnt = 2; in tzparse()
1349 sp->typecnt = 1; /* only standard time */ in tzparse()
1350 sp->timecnt = 0; in tzparse()
1351 init_ttinfo(&sp->ttis[0], -stdoffset, false, 0); in tzparse()
1353 sp->charcnt = charcnt; in tzparse()
1354 cp = sp->chars; in tzparse()
1382 if ((now.tv_sec - last_checked >= __tz_change_interval) || in recheck_tzdata()
1403 sp->leapcnt = 0; /* so, we're off a little */ in zoneinit()
1404 sp->timecnt = 0; in zoneinit()
1405 sp->typecnt = 0; in zoneinit()
1406 sp->charcnt = 0; in zoneinit()
1407 sp->goback = sp->goahead = false; in zoneinit()
1408 init_ttinfo(&sp->ttis[0], 0, false, 0); in zoneinit()
1409 strcpy(sp->chars, utc); in zoneinit()
1425 int lcl = name ? strlen(name) < sizeof lcl_TZname : -1; in tzset_unlocked_name()
1515 ** POSIX.1-2024 removes ctime_r. Both have potential security problems that
1553 if ((sp->goback && t < sp->ats[0]) || in localsub()
1554 (sp->goahead && t > sp->ats[sp->timecnt - 1])) { in localsub()
1559 if (t < sp->ats[0]) in localsub()
1560 seconds = sp->ats[0] - t; in localsub()
1561 else seconds = t - sp->ats[sp->timecnt - 1]; in localsub()
1562 --seconds; in localsub()
1569 if (t < sp->ats[0]) in localsub()
1572 newt = t - seconds - SECSPERREPEAT; in localsub()
1574 if (newt < sp->ats[0] || in localsub()
1575 newt > sp->ats[sp->timecnt - 1]) in localsub()
1580 if (t < sp->ats[0] in localsub()
1581 ? ckd_sub(&result->tm_year, in localsub()
1582 result->tm_year, years) in localsub()
1583 : ckd_add(&result->tm_year, in localsub()
1584 result->tm_year, years)) in localsub()
1589 newy = result->tm_year; in localsub()
1590 if (t < sp->ats[0]) in localsub()
1591 newy -= years; in localsub()
1595 result->tm_year = newy; in localsub()
1600 if (sp->timecnt == 0 || t < sp->ats[0]) { in localsub()
1604 register int hi = sp->timecnt; in localsub()
1609 if (t < sp->ats[mid]) in localsub()
1613 i = sp->types[lo - 1]; in localsub()
1615 ttisp = &sp->ttis[i]; in localsub()
1619 ** t += ttisp->tt_utoff; in localsub()
1622 result = timesub(&t, ttisp->tt_utoff, sp, tmp); in localsub()
1624 result->tm_isdst = ttisp->tt_isdst; in localsub()
1626 result->TM_ZONE = (char *) &sp->chars[ttisp->tt_desigidx]; in localsub()
1708 int_fast32_t offset, struct tm *tmp) in gmtsub() argument
1712 result = timesub(timep, offset, gmtptr, tmp); in gmtsub()
1716 ** "+xx" or "-xx" if offset is non-zero, in gmtsub()
1719 tmp->TM_ZONE = ((char *) in gmtsub()
1720 (offset ? wildabbr : gmtptr ? gmtptr->chars : utc)); in gmtsub()
1726 * Re-entrant version of gmtime.
1773 Callers can instead use localtime_rz with a fixed-offset zone. */
1776 offtime_r(time_t const *restrict timep, long offset, struct tm *restrict tmp) in offtime_r() argument
1779 return gmtsub(gmtptr, timep, offset, tmp); in offtime_r()
1790 offtime(const time_t *timep, long offset) in offtime() argument
1813 return offtime_r(timep, offset, p_tm); in offtime()
1824 leaps_thru_end_of_nonneg(time_t y) in leaps_thru_end_of_nonneg() argument
1826 return y / 4 - y / 100 + y / 400; in leaps_thru_end_of_nonneg()
1830 leaps_thru_end_of(time_t y) in leaps_thru_end_of() argument
1832 return (y < 0 in leaps_thru_end_of()
1833 ? -1 - leaps_thru_end_of_nonneg(-1 - y) in leaps_thru_end_of()
1834 : leaps_thru_end_of_nonneg(y)); in leaps_thru_end_of()
1838 timesub(const time_t *timep, int_fast32_t offset, in timesub() argument
1847 time_t y; in timesub() local
1855 i = (sp == NULL) ? 0 : sp->leapcnt; in timesub()
1856 while (--i >= 0) { in timesub()
1857 lp = &sp->lsis[i]; in timesub()
1858 if (*timep >= lp->ls_trans) { in timesub()
1859 corr = lp->ls_corr; in timesub()
1860 if ((i == 0 ? 0 : lp[-1].ls_corr) < corr) in timesub()
1861 secs_since_posleap = *timep - lp->ls_trans; in timesub()
1870 rem += offset % SECSPERDAY - corr % SECSPERDAY + 3 * SECSPERDAY; in timesub()
1871 dayoff = offset / SECSPERDAY - corr / SECSPERDAY + rem / SECSPERDAY - 3; in timesub()
1873 /* y = (EPOCH_YEAR in timesub()
1875 sans overflow. But calculate against 1570 (EPOCH_YEAR - in timesub()
1880 y = (EPOCH_YEAR - YEARSPERREPEAT in timesub()
1882 - ((dayrem % DAYSPERREPEAT) < 0) in timesub()
1889 /* Increase Y and decrease IDAYS until IDAYS is in range for Y. */ in timesub()
1890 while (year_lengths[isleap(y)] <= idays) { in timesub()
1893 time_t newy = y + ydelta; in timesub()
1895 leapdays = leaps_thru_end_of(newy - 1) - in timesub()
1896 leaps_thru_end_of(y - 1); in timesub()
1897 idays -= ydelta * DAYSPERNYEAR; in timesub()
1898 idays -= leapdays; in timesub()
1899 y = newy; in timesub()
1903 if (ckd_add(&tmp->tm_year, y, -TM_YEAR_BASE)) { in timesub()
1908 if (!TYPE_SIGNED(time_t) && y < TM_YEAR_BASE) { in timesub()
1909 int signed_y = y; in timesub()
1910 tmp->tm_year = signed_y - TM_YEAR_BASE; in timesub()
1911 } else if ((!TYPE_SIGNED(time_t) || INT_MIN + TM_YEAR_BASE <= y) in timesub()
1912 && y - TM_YEAR_BASE <= INT_MAX) in timesub()
1913 tmp->tm_year = y - TM_YEAR_BASE; in timesub()
1919 tmp->tm_yday = idays; in timesub()
1923 tmp->tm_wday = (TM_WDAY_BASE in timesub()
1924 + ((tmp->tm_year % DAYSPERWEEK) in timesub()
1926 + leaps_thru_end_of(y - 1) in timesub()
1927 - leaps_thru_end_of(TM_YEAR_BASE - 1) in timesub()
1929 tmp->tm_wday %= DAYSPERWEEK; in timesub()
1930 if (tmp->tm_wday < 0) in timesub()
1931 tmp->tm_wday += DAYSPERWEEK; in timesub()
1932 tmp->tm_hour = rem / SECSPERHOUR; in timesub()
1934 tmp->tm_min = rem / SECSPERMIN; in timesub()
1935 tmp->tm_sec = rem % SECSPERMIN; in timesub()
1939 tmp->tm_sec += secs_since_posleap <= tmp->tm_sec; in timesub()
1941 ip = mon_lengths[isleap(y)]; in timesub()
1942 for (tmp->tm_mon = 0; idays >= ip[tmp->tm_mon]; ++(tmp->tm_mon)) in timesub()
1943 idays -= ip[tmp->tm_mon]; in timesub()
1944 tmp->tm_mday = idays + 1; in timesub()
1945 tmp->tm_isdst = 0; in timesub()
1947 tmp->TM_GMTOFF = offset; in timesub()
1962 # define WRONG (-1)
1979 ** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow. in increment_overflow()
1981 ** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow. in increment_overflow()
1983 if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i)) in increment_overflow()
1998 if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l)) in increment_overflow32()
2017 ? (TYPE_SIGNED(time_t) ? TIME_T_MIN - j <= *tp : -1 - j < *tp) in increment_overflow_time()
2018 : *tp <= TIME_T_MAX - j)) in increment_overflow_time()
2032 (-1 - (-1 - *unitsptr) / base); in normalize_overflow()
2033 *unitsptr -= tensdelta * base; in normalize_overflow()
2044 (-1 - (-1 - *unitsptr) / base); in normalize_overflow32()
2045 *unitsptr -= tensdelta * base; in normalize_overflow32()
2055 if (atmp->tm_year != btmp->tm_year) in tmcomp()
2056 return atmp->tm_year < btmp->tm_year ? -1 : 1; in tmcomp()
2057 if ((result = (atmp->tm_mon - btmp->tm_mon)) == 0 && in tmcomp()
2058 (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && in tmcomp()
2059 (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && in tmcomp()
2060 (result = (atmp->tm_min - btmp->tm_min)) == 0) in tmcomp()
2061 result = atmp->tm_sec - btmp->tm_sec; in tmcomp()
2070 dest->tm_sec = src->tm_sec; in mktmcpy()
2071 dest->tm_min = src->tm_min; in mktmcpy()
2072 dest->tm_hour = src->tm_hour; in mktmcpy()
2073 dest->tm_mday = src->tm_mday; in mktmcpy()
2074 dest->tm_mon = src->tm_mon; in mktmcpy()
2075 dest->tm_year = src->tm_year; in mktmcpy()
2076 dest->tm_isdst = src->tm_isdst; in mktmcpy()
2078 dest->TM_GMTOFF = src->TM_GMTOFF; in mktmcpy()
2087 const int_fast32_t offset, in time2sub() argument
2097 int_fast32_t y; in time2sub() local
2114 y = yourtm.tm_year; in time2sub()
2115 if (normalize_overflow32(&y, &yourtm.tm_mon, MONSPERYEAR)) in time2sub()
2118 ** Turn y into an actual year number for now. in time2sub()
2119 ** It is converted back to an offset from TM_YEAR_BASE later. in time2sub()
2121 if (increment_overflow32(&y, TM_YEAR_BASE)) in time2sub()
2124 if (increment_overflow32(&y, -1)) in time2sub()
2126 li = y + (1 < yourtm.tm_mon); in time2sub()
2130 li = y + (1 < yourtm.tm_mon); in time2sub()
2131 yourtm.tm_mday -= year_lengths[isleap(li)]; in time2sub()
2132 if (increment_overflow32(&y, 1)) in time2sub()
2136 i = mon_lengths[isleap(y)][yourtm.tm_mon]; in time2sub()
2139 yourtm.tm_mday -= i; in time2sub()
2142 if (increment_overflow32(&y, 1)) in time2sub()
2147 if (ckd_add(&yourtm.tm_year, y, -TM_YEAR_BASE)) in time2sub()
2150 if (increment_overflow32(&y, -TM_YEAR_BASE)) in time2sub()
2152 if (! (INT_MIN <= y && y <= INT_MAX)) in time2sub()
2154 yourtm.tm_year = y; in time2sub()
2158 else if (yourtm.tm_year < EPOCH_YEAR - TM_YEAR_BASE) { in time2sub()
2167 if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN)) in time2sub()
2170 yourtm.tm_sec = SECSPERMIN - 1; in time2sub()
2186 if (! funcp(sp, &t, offset, &mytm)) { in time2sub()
2192 dir = (t > 0) ? 1 : -1; in time2sub()
2203 --t; in time2sub()
2204 --hi; in time2sub()
2216 ? (-SECSPERDAY <= yourtm.TM_GMTOFF in time2sub()
2224 /* MYTM matches YOURTM except with the wrong UT offset. in time2sub()
2229 int_fast32_t diff = mytm.TM_GMTOFF - yourtm.TM_GMTOFF; in time2sub()
2232 if (funcp(sp, &altt, offset, &alttm) in time2sub()
2252 for (i = sp->typecnt - 1; i >= 0; --i) { in time2sub()
2253 if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) in time2sub()
2255 for (j = sp->typecnt - 1; j >= 0; --j) { in time2sub()
2256 if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) in time2sub()
2260 newt = (t + sp->ttis[j].tt_utoff in time2sub()
2261 - sp->ttis[i].tt_utoff); in time2sub()
2262 if (! funcp(sp, &newt, offset, &mytm)) in time2sub()
2282 if (funcp(sp, &t, offset, tmp)) in time2sub()
2292 const int_fast32_t offset, in time2() argument
2302 t = time2sub(tmp, funcp, sp, offset, okayp, false); in time2()
2303 return *okayp ? t : time2sub(tmp, funcp, sp, offset, okayp, true); in time2()
2311 const int_fast32_t offset) in time1() argument
2327 if (tmp->tm_isdst > 1) in time1()
2328 tmp->tm_isdst = 1; in time1()
2329 t = time2(tmp, funcp, sp, offset, &okay); in time1()
2332 if (tmp->tm_isdst < 0) in time1()
2337 tmp->tm_isdst = 0; /* reset to std and try again */ in time1()
2349 for (i = 0; i < sp->typecnt; ++i) in time1()
2352 for (i = sp->timecnt - 1; i >= 0; --i) in time1()
2353 if (!seen[sp->types[i]] && !ttunspecified(sp, sp->types[i])) { in time1()
2354 seen[sp->types[i]] = true; in time1()
2355 types[nseen++] = sp->types[i]; in time1()
2359 if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) in time1()
2363 if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) in time1()
2365 tmp->tm_sec += (sp->ttis[otheri].tt_utoff in time1()
2366 - sp->ttis[samei].tt_utoff); in time1()
2367 tmp->tm_isdst = !tmp->tm_isdst; in time1()
2368 t = time2(tmp, funcp, sp, offset, &okay); in time1()
2371 tmp->tm_sec -= (sp->ttis[otheri].tt_utoff in time1()
2372 - sp->ttis[samei].tt_utoff); in time1()
2373 tmp->tm_isdst = !tmp->tm_isdst; in time1()
2407 return -1; in mktime()
2422 tmp->tm_isdst = -1; /* in case it wasn't initialized */ in timelocal()
2435 Callers can instead use mktime_z with a fixed-offset zone. */
2437 timeoff(struct tm *tmp, long offset) in timeoff() argument
2440 tmp->tm_isdst = 0; in timeoff()
2442 return time1(tmp, gmtsub, gmtptr, offset); in timeoff()
2451 tmcpy.tm_wday = -1; in timegm()
2464 i = sp->leapcnt; in leapcorr()
2465 while (--i >= 0) { in leapcorr()
2466 lp = &sp->lsis[i]; in leapcorr()
2467 if (t >= lp->ls_trans) in leapcorr()
2468 return lp->ls_corr; in leapcorr()
2474 ** XXX--is the below the right way to conditionalize??
2498 return t - leapcorr(sp, t); in time2posix_z()
2507 return -1; in time2posix()
2523 time_t y; in posix2time_z() local
2531 y = x - leapcorr(sp, x); in posix2time_z()
2532 if (y < t) { in posix2time_z()
2535 y = x - leapcorr(sp, x); in posix2time_z()
2536 } while (y < t); in posix2time_z()
2537 x -= y != t; in posix2time_z()
2538 } else if (y > t) { in posix2time_z()
2540 --x; in posix2time_z()
2541 y = x - leapcorr(sp, x); in posix2time_z()
2542 } while (y > t); in posix2time_z()
2543 x += y != t; in posix2time_z()
2554 return -1; in posix2time()
2593 if (r != (time_t) -1) { in time()
2594 int_fast32_t offset = EPOCH_LOCAL ? (daylight ? timezone : altzone) : 0; in time() local
2595 if (increment_overflow32(&offset, -EPOCH_OFFSET) in time()
2596 || increment_overflow_time(&r, offset)) { in time()
2598 r = -1; in time()