Lines Matching +full:start +full:- +full:year

2  * ntp_calendar.c - calendar and helper functions
7 * --------------------------------------------------------------------
17 * constant-divider case.
61 * macros are not defined, check a few well-known compiler/architecture
63 * integers is unknown and shift-arithmetic-right is not available.
92 *---------------------------------------------------------------------
94 *---------------------------------------------------------------------
124 *---------------------------------------------------------------------
126 *---------------------------------------------------------------------
137 * true, though -- On 8bit CPUs or machines without barrel in int32_sflag()
148 return UINT32_C(0) - (uint32_t)(v < 0); in int32_sflag()
174 v = -(int32_t)(~vu) - 1; in uint32_2cpl_to_int32()
184 *---------------------------------------------------------------------
186 *---------------------------------------------------------------------
202 res.D_s.lo = (uint32_t)-tt; in time_to_vint64()
214 * shifting negative signed quantities is compiler-dependent, so in time_to_vint64()
219 tt = -tt; in time_to_vint64()
243 res = (time_t)tv->D_s.lo; in vint64_to_time()
247 res = (time_t)tv->q_s; in vint64_to_time()
251 res = ((time_t)tv->d_s.hi << 32) | tv->D_s.lo; in vint64_to_time()
259 *---------------------------------------------------------------------
261 *---------------------------------------------------------------------
276 * implementation-defined valid date shall be supplied. in ntpcal_get_build_date()
282 * implementation-defined valid time shall be supplied. in ntpcal_get_build_date()
286 * statement about this. As a result, we may be +/-12hrs off in ntpcal_get_build_date()
300 unsigned short hour, minute, second, day, year; in ntpcal_get_build_date() local
302 * so using 'uint16_t' is contra-indicated! in ntpcal_get_build_date()
310 jd->year = 1970; in ntpcal_get_build_date()
311 jd->month = 1; in ntpcal_get_build_date()
312 jd->monthday = 1; in ntpcal_get_build_date()
326 &hour, &minute, &second, monstr, &day, &year)) { in ntpcal_get_build_date()
329 jd->year = year; in ntpcal_get_build_date()
330 jd->month = (uint8_t)((cp - mlist) / 3 + 1); in ntpcal_get_build_date()
331 jd->monthday = (uint8_t)day; in ntpcal_get_build_date()
332 jd->hour = (uint8_t)hour; in ntpcal_get_build_date()
333 jd->minute = (uint8_t)minute; in ntpcal_get_build_date()
334 jd->second = (uint8_t)second; in ntpcal_get_build_date()
345 *---------------------------------------------------------------------
347 *---------------------------------------------------------------------
357 * the start of the NTP epoch.
362 * 1970-01-01/03:04:05 means 'IN the 1970st. year, IN the first month,
367 * and full days before a date: 1970-01-01 would be (1969, 0, 0) in
371 * normal range are acceptable: 2001-03-00 will be treated as the day
372 * before 2001-03-01, 2000-13-32 will give the same result as
373 * 2001-02-01 and so on.
376 * (day number). This is the number of days elapsed since 0000-12-31
378 * (0001-01-01) is RD(1).
390 *---------------------------------------------------------------------
392 *---------------------------------------------------------------------
406 * this one is ARM-friendly because of a mask that fits into 16 in u32mod7()
413 * M <- ceil(ldexp(8/7, 29)) in u32mod7()
423 /* We add (2**32 - 2**32 % 7), which is (2**32 - 4), to negative in i32mod7()
424 * numbers to map them into the postive range. Only the term '-4' in i32mod7()
428 return u32mod7((x < 0) ? (ux - 4u) : ux); in i32mod7()
438 uint32_t sf = UINT32_C(0) - (x < 0); in i32fmod()
444 *---------------------------------------------------------------------
458 * divider and modulus to have the same sign for a non-zero modulus.
462 * + let Y be a calendar year and V a truncated 2-digit year: then
463 * periodic_extend(Y-50, V, 100)
464 * is the closest expansion of the truncated year with respect to
465 * the full year, that is a 4-digit year with a difference of less
466 * than 50 years to the year Y. ("century unfolding")
468 * + let T be a UN*X time stamp and V be seconds-of-day: then
469 * perodic_extend(T-43200, V, 86400)
470 * is a time stamp that has the same seconds-of-day as the input
474 * + Wherever you have a truncated periodic value and a non-truncated
477 * Basically, the function delivers 'pivot + (value - pivot) % cycle',
479 * integer overflows in the '(value - pivot) % cycle' part and adheres
488 *---------------------------------------------------------------------
497 /* Implement a 4-quadrant modulus calculation by 2 2-quadrant in ntpcal_periodic_extend()
505 * that is, we don't actually divide for cycles of -1,0,1 and in ntpcal_periodic_extend()
515 sf = UINT32_C(0) - (value < pivot); in ntpcal_periodic_extend()
517 uv = sf ^ (uv - up); in ntpcal_periodic_extend()
521 else if (cycle < -1) in ntpcal_periodic_extend()
524 sf = UINT32_C(0) - (value > pivot); in ntpcal_periodic_extend()
526 uv = sf ^ (up - uv); in ntpcal_periodic_extend()
528 pivot -= (uc & sf) + (sf ^ uv); in ntpcal_periodic_extend()
533 /*---------------------------------------------------------------------
539 * res.Q_s -= 0x80000000;
549 * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
561 *---------------------------------------------------------------------
565 * timestamps before 1970-01-01, so be aware of possible trouble on
571 *---------------------------------------------------------------------
586 res.Q_s -= 0x80000000u; /* unshift of half range */ in ntpcal_ntp_to_time()
587 ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */ in ntpcal_ntp_to_time()
588 ntp -= res.D_s.lo; /* cycle difference */ in ntpcal_ntp_to_time()
600 ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */ in ntpcal_ntp_to_time()
601 ntp -= res.D_s.lo; /* cycle difference */ in ntpcal_ntp_to_time()
610 *---------------------------------------------------------------------
620 *---------------------------------------------------------------------
635 res.Q_s -= 0x80000000u; /* unshift of half range */ in ntpcal_ntp_to_ntp()
637 ntp -= res.D_s.lo; /* cycle difference */ in ntpcal_ntp_to_ntp()
650 ntp -= res.D_s.lo; /* cycle difference */ in ntpcal_ntp_to_ntp()
668 *---------------------------------------------------------------------
672 * timestamps before the respective epoch start.
673 *---------------------------------------------------------------------
688 uint64_t sf64 = (uint64_t)-(ts->q_s < 0); in ntpcal_daysplit()
689 Q = (uint32_t)(sf64 ^ ((sf64 ^ ts->Q_s) / SECSPERDAY)); in ntpcal_daysplit()
690 R = (uint32_t)(ts->Q_s - Q * SECSPERDAY); in ntpcal_daysplit()
696 * for ARM CPUs, the sum-by-digit code in the next section is in ntpcal_daysplit()
698 * the 64bit-by-32bit division will never outperform the exact in ntpcal_daysplit()
701 if (ts->q_s < 0) in ntpcal_daysplit()
702 Q = ~(uint32_t)(~ts->Q_s / SECSPERDAY); in ntpcal_daysplit()
704 Q = (uint32_t)( ts->Q_s / SECSPERDAY); in ntpcal_daysplit()
705 R = ts->D_s.lo - Q * SECSPERDAY; in ntpcal_daysplit()
714 * Remember: 86400 <--> 128 * 675 in ntpcal_daysplit()
721 * Then we use a digit-wise pseudo-reduction, where a 'digit' is in ntpcal_daysplit()
722 * actually a 16-bit group. This is followed by a full reduction in ntpcal_daysplit()
741 uint32_t al = ts->D_s.lo; in ntpcal_daysplit()
742 uint32_t ah = ts->D_s.hi; in ntpcal_daysplit()
748 R = (ts->d_s.hi < 0) ? 239 : 0;/* sign bit value */ in ntpcal_daysplit()
754 Q = (al - R) * 0x2D21C10Bu; /* modinv(675, 2**32) */ in ntpcal_daysplit()
755 R = (R << 7) | (ts->d_s.lo & 0x07F); in ntpcal_daysplit()
766 *---------------------------------------------------------------------
768 * elapsed seconds since week start in 'res.lo' using explicit floor
770 * timestamps before the respective epoch start.
771 *---------------------------------------------------------------------
787 uint64_t sf64 = (uint64_t)-(ts->q_s < 0); in ntpcal_weeksplit()
788 Q = (uint32_t)(sf64 ^ ((sf64 ^ ts->Q_s) / SECSPERWEEK)); in ntpcal_weeksplit()
789 R = (uint32_t)(ts->Q_s - Q * SECSPERWEEK); in ntpcal_weeksplit()
793 if (ts->q_s < 0) in ntpcal_weeksplit()
794 Q = ~(uint32_t)(~ts->Q_s / SECSPERWEEK); in ntpcal_weeksplit()
796 Q = (uint32_t)( ts->Q_s / SECSPERWEEK); in ntpcal_weeksplit()
797 R = ts->D_s.lo - Q * SECSPERWEEK; in ntpcal_weeksplit()
801 /* Remember: 7*86400 <--> 604800 <--> 128 * 4725 */ in ntpcal_weeksplit()
802 uint32_t al = ts->D_s.lo; in ntpcal_weeksplit()
803 uint32_t ah = ts->D_s.hi; in ntpcal_weeksplit()
808 R = (ts->d_s.hi < 0) ? 2264 : 0;/* sign bit value */ in ntpcal_weeksplit()
814 Q = (al - R) * 0x98BBADDDu; /* modinv(4725, 2**32) */ in ntpcal_weeksplit()
815 R = (R << 7) | (ts->d_s.lo & 0x07F); in ntpcal_weeksplit()
826 *---------------------------------------------------------------------
830 *---------------------------------------------------------------------
855 split[0] = (int32_t)(uh - ud * HRSPERDAY ); in priv_timesplit()
856 split[1] = (int32_t)(um - uh * MINSPERHR ); in priv_timesplit()
857 split[2] = (int32_t)(us - um * SECSPERMIN); in priv_timesplit()
863 *---------------------------------------------------------------------
866 * of elapsed days of that year in 'res.lo'.
869 * regular years and a non-zero value for leap years.
870 *---------------------------------------------------------------------
885 int32_t n100, n001; /* calendar year cycles */ in ntpcal_split_eradays()
900 sf64 = (uint64_t)-(days < 0); in ntpcal_split_eradays()
902 uday = (uint32_t)(ud64 - Q * GREGORIAN_CYCLE_DAYS); in ntpcal_split_eradays()
911 * We start with a partial reduction by digit sums, extracting in ntpcal_split_eradays()
918 * (-2^33) % 146097 --> 130717 : the sign bit value in ntpcal_split_eradays()
919 * ( 2^20) % 146097 --> 25897 : the upper digit value in ntpcal_split_eradays()
920 * modinv(146097, 2^32) --> 660721233 : the inverse in ntpcal_split_eradays()
927 Q = (ux - uday) * 660721233u; /* exact div */ in ntpcal_split_eradays()
932 /* Split off years in century -- days >= 0 here, and we're far in ntpcal_split_eradays()
936 uday -= n001 * GREGORIAN_NORMAL_LEAP_CYCLE_DAYS; in ntpcal_split_eradays()
938 /* Assemble the year and day in year */ in ntpcal_split_eradays()
942 /* Possibly set the leap year flag */ in ntpcal_split_eradays()
953 *---------------------------------------------------------------------
954 * Given a number of elapsed days in a year and a leap year indicator,
958 * This function will fail and return {-1,-1} if the number of elapsed
960 *---------------------------------------------------------------------
968 /* Use the unshifted-year, February-with-30-days approach here. in ntpcal_split_yeardays()
970 * the smallest power-of-two divider to avoid any true division. in ntpcal_split_yeardays()
972 ntpcal_split res = {-1, -1}; in ntpcal_split_yeardays()
977 if (eyd >= 61 - isleap) in ntpcal_split_yeardays()
982 res.lo = eyd - ((489 * res.hi + 8) >> 4); in ntpcal_split_yeardays()
989 *---------------------------------------------------------------------
991 *---------------------------------------------------------------------
1003 /* Get day-of-week first. It's simply the RD (mod 7)... */ in ntpcal_rd_to_date()
1004 jd->weekday = i32mod7(rd); in ntpcal_rd_to_date()
1006 split = ntpcal_split_eradays(rd - 1, &leapy); in ntpcal_rd_to_date()
1007 /* Get year and day-of-year, with overflow check. If any of the in ntpcal_rd_to_date()
1008 * upper 16 bits is set after shifting to unity-based years, we in ntpcal_rd_to_date()
1010 * year. Shifting to the right is OK here, since it does not in ntpcal_rd_to_date()
1014 ymask = 0u - ((split.hi >> 16) == 0); in ntpcal_rd_to_date()
1015 jd->year = (uint16_t)(split.hi & ymask); in ntpcal_rd_to_date()
1016 jd->yearday = (uint16_t)split.lo + 1; in ntpcal_rd_to_date()
1020 jd->month = (uint8_t)split.hi + 1; in ntpcal_rd_to_date()
1021 jd->monthday = (uint8_t)split.lo + 1; in ntpcal_rd_to_date()
1023 return ymask ? leapy : -1; in ntpcal_rd_to_date()
1027 *---------------------------------------------------------------------
1029 *---------------------------------------------------------------------
1040 /* get day-of-week first */ in ntpcal_rd_to_tm()
1041 utm->tm_wday = i32mod7(rd); in ntpcal_rd_to_tm()
1043 /* get year and day-of-year */ in ntpcal_rd_to_tm()
1044 split = ntpcal_split_eradays(rd - 1, &leapy); in ntpcal_rd_to_tm()
1045 utm->tm_year = split.hi - 1899; in ntpcal_rd_to_tm()
1046 utm->tm_yday = split.lo; /* 0-based */ in ntpcal_rd_to_tm()
1050 utm->tm_mon = split.hi; /* 0-based */ in ntpcal_rd_to_tm()
1051 utm->tm_mday = split.lo + 1; /* 1-based */ in ntpcal_rd_to_tm()
1057 *---------------------------------------------------------------------
1060 *---------------------------------------------------------------------
1072 jd->hour = (uint8_t)ts[0]; in ntpcal_daysec_to_date()
1073 jd->minute = (uint8_t)ts[1]; in ntpcal_daysec_to_date()
1074 jd->second = (uint8_t)ts[2]; in ntpcal_daysec_to_date()
1080 *---------------------------------------------------------------------
1083 *---------------------------------------------------------------------
1095 utm->tm_hour = ts[0]; in ntpcal_daysec_to_tm()
1096 utm->tm_min = ts[1]; in ntpcal_daysec_to_tm()
1097 utm->tm_sec = ts[2]; in ntpcal_daysec_to_tm()
1103 *---------------------------------------------------------------------
1104 * take a split representation for day/second-of-day and day offset
1108 * returns >0 if the result is in a leap year, 0 if in a regular
1109 * year and <0 if the result did not fit into the calendar struct.
1110 *---------------------------------------------------------------------
1119 dof += ntpcal_daysec_to_date(jd, ds->lo); in ntpcal_daysplit_to_date()
1120 return ntpcal_rd_to_date(jd, ds->hi + dof); in ntpcal_daysplit_to_date()
1124 *---------------------------------------------------------------------
1125 * take a split representation for day/second-of-day and day offset
1129 * returns 1 if the result is in a leap year and zero if in a regular
1130 * year.
1131 *---------------------------------------------------------------------
1140 dof += ntpcal_daysec_to_tm(utm, ds->lo); in ntpcal_daysplit_to_tm()
1142 return ntpcal_rd_to_tm(utm, ds->hi + dof); in ntpcal_daysplit_to_tm()
1146 *---------------------------------------------------------------------
1148 *---------------------------------------------------------------------
1193 sf = (uint32_t)-(hi < 0); in _dwjoin()
1196 /* assemble major units: res <- |hi| * mul */ in _dwjoin()
1204 /* mul by 128, using shift: res <-- res << 7 */ in _dwjoin()
1208 /* fix up sign: res <-- (res + [sf|sf]) ^ [sf|sf] */ in _dwjoin()
1213 /* properly add seconds: res <-- res + [sx(lo)|lo] */ in _dwjoin()
1214 p2 = (uint32_t)-(lo < 0); in _dwjoin()
1222 *---------------------------------------------------------------------
1225 *---------------------------------------------------------------------
1251 *---------------------------------------------------------------------
1254 *---------------------------------------------------------------------
1280 *---------------------------------------------------------------------
1282 *---------------------------------------------------------------------
1289 /* We use the in-out-in algorithm here, using the one's in ntpcal_leapyears_in_years()
1301 sum = (uyear /= 4u); /* 4yr rule --> IN */ in ntpcal_leapyears_in_years()
1302 sum -= (uyear /= 25u); /* 100yr rule --> OUT */ in ntpcal_leapyears_in_years()
1303 sum += (uyear /= 4u); /* 400yr rule --> IN */ in ntpcal_leapyears_in_years()
1315 *---------------------------------------------------------------------
1317 *---------------------------------------------------------------------
1328 *---------------------------------------------------------------------
1329 * Convert a number of elapsed month in a year into elapsed days in year.
1333 * while 'res.lo' will contain the number of elapsed days since start
1334 * of the year.
1336 * This code uses the shifted-month-approach to convert month to days,
1337 * because then there is no need to have explicit leap year
1339 * the result is a negative value, and the year excess is one; the
1340 * conversion is then simply based on the start of the following year.
1341 *---------------------------------------------------------------------
1350 /* Add ten months with proper year adjustment. */ in ntpcal_days_in_months()
1355 res.lo = m - 2; in ntpcal_days_in_months()
1368 res.lo = mu - Q * 12u; in ntpcal_days_in_months()
1371 /* Get cummulated days in year with unshift. Use the fractional in ntpcal_days_in_months()
1375 res.lo = ((res.lo * 979 + 16) >> 5) - 306; in ntpcal_days_in_months()
1381 *---------------------------------------------------------------------
1385 * If you want to convert years and days-of-year, just give a month of
1387 *---------------------------------------------------------------------
1410 *---------------------------------------------------------------------
1412 * days in year.
1414 * Note: This will give the true difference to the start of the given
1415 * year, even if months & days are off-scale.
1416 *---------------------------------------------------------------------
1429 mdays -= 2 - is_leapyear(years+1); in ntpcal_edate_to_yeardays()
1435 - ntpcal_days_in_years(years); in ntpcal_edate_to_yeardays()
1442 *---------------------------------------------------------------------
1449 *---------------------------------------------------------------------
1466 *---------------------------------------------------------------------
1467 * Convert the date part of a 'struct tm' (that is, year, month,
1468 * day-of-month) into the RD of that day.
1469 *---------------------------------------------------------------------
1476 return ntpcal_edate_to_eradays(utm->tm_year + 1899, in ntpcal_tm_to_rd()
1477 utm->tm_mon, in ntpcal_tm_to_rd()
1478 utm->tm_mday - 1) + 1; in ntpcal_tm_to_rd()
1482 *---------------------------------------------------------------------
1483 * Convert the date part of a 'struct calendar' (that is, year, month,
1484 * day-of-month) into the RD of that day.
1485 *---------------------------------------------------------------------
1492 return ntpcal_edate_to_eradays((int32_t)jd->year - 1, in ntpcal_date_to_rd()
1493 (int32_t)jd->month - 1, in ntpcal_date_to_rd()
1494 (int32_t)jd->monthday - 1) + 1; in ntpcal_date_to_rd()
1498 *---------------------------------------------------------------------
1499 * convert a year number to rata die of year start
1500 *---------------------------------------------------------------------
1504 int32_t year in ntpcal_year_to_ystart() argument
1507 return ntpcal_days_in_years(year - 1) + 1; in ntpcal_year_to_ystart()
1511 *---------------------------------------------------------------------
1512 * For a given RD, get the RD of the associated year start,
1514 *---------------------------------------------------------------------
1526 return rd - ntpcal_split_eradays(rd - 1, NULL).lo; in ntpcal_rd_to_ystart()
1530 *---------------------------------------------------------------------
1531 * For a given RD, get the RD of the associated month start.
1532 *---------------------------------------------------------------------
1542 split = ntpcal_split_eradays(rd - 1, &leaps); in ntpcal_rd_to_mstart()
1545 return rd - split.lo; in ntpcal_rd_to_mstart()
1549 *---------------------------------------------------------------------
1550 * take a 'struct calendar' and get the seconds-of-day from it.
1551 *---------------------------------------------------------------------
1558 return ntpcal_etime_to_seconds(jd->hour, jd->minute, in ntpcal_date_to_daysec()
1559 jd->second); in ntpcal_date_to_daysec()
1563 *---------------------------------------------------------------------
1564 * take a 'struct tm' and get the seconds-of-day from it.
1565 *---------------------------------------------------------------------
1572 return ntpcal_etime_to_seconds(utm->tm_hour, utm->tm_min, in ntpcal_tm_to_daysec()
1573 utm->tm_sec); in ntpcal_tm_to_daysec()
1577 *---------------------------------------------------------------------
1579 *---------------------------------------------------------------------
1589 days = ntpcal_date_to_rd(jd) - DAY_UNIX_STARTS; in ntpcal_date_to_time()
1645 return ntpcal_dayjoin(ntpcal_date_to_rd(jd) - DAY_NTP_STARTS, in ntpcal_date_to_ntp64()
1666 * day-of-week calculations
1671 * Given a RataDie and a day-of-week, calculate a RDN that is reater-than,
1672 * greater-or equal, closest, less-or-equal or less-than the given RDN
1673 * and denotes the given day-of-week
1699 return ntpcal_periodic_extend(rdn-3, dow, 7); in ntpcal_weekday_close()
1708 return ntpcal_periodic_extend(rdn, dow, -7); in ntpcal_weekday_le()
1717 return ntpcal_periodic_extend(rdn-1, dow, -7); in ntpcal_weekday_lt()
1723 * ISO week-calendar conversions
1726 * It is related to the Gregorian calendar, and a ISO year starts at the
1727 * Monday closest to Jan,1st of the corresponding Gregorian year. A ISO
1728 * calendar year has always 52 or 53 weeks, and like the Grogrian
1737 * interpolate from years to weeks over a full 400 year range; cyclic
1739 * possible to interpolate over every single century of the 400-year
1740 * cycle. (The centennial leap year rule seems to be the culprit here.)
1752 * of the century in a 400-year period.
1769 * Given a number of elapsed (ISO-)years since the begin of the
1791 yu -= cc * 100u; in isocal_weeks_in_years()
1819 * the number of elapsed weeks in the remaining partial year.)
1836 /* Use two fast cycle-split divisions again. Herew e want to in isocal_split_eraweeks()
1850 sf64 = (uint64_t)-(weeks < 0); in isocal_split_eraweeks()
1853 sw = (uint32_t)(sw64 - Q * GREGORIAN_CYCLE_WEEKS); in isocal_split_eraweeks()
1859 * (-2^33) % 20871 --> 5491 : the sign bit value in isocal_split_eraweeks()
1860 * ( 2^20) % 20871 --> 5026 : the upper digit value in isocal_split_eraweeks()
1861 * modinv(20871, 2^32) --> 330081335 : the inverse in isocal_split_eraweeks()
1868 Q = (ux - sw) * 330081335u; /* exact div */ in isocal_split_eraweeks()
1883 * the year. in isocal_split_eraweeks()
1914 id->hour = (uint8_t)ts[0]; in isocal_ntp64_to_date()
1915 id->minute = (uint8_t)ts[1]; in isocal_ntp64_to_date()
1916 id->second = (uint8_t)ts[2]; in isocal_ntp64_to_date()
1919 ds.hi += DAY_NTP_STARTS - 1; /* shift from NTP to RDN */ in isocal_ntp64_to_date()
1923 ud -= uw * DAYSPERWEEK; in isocal_ntp64_to_date()
1928 id->weekday = (uint8_t)ds.lo + 1; /* weekday result */ in isocal_ntp64_to_date()
1930 /* get year and week in year */ in isocal_ntp64_to_date()
1932 id->year = (uint16_t)ds.hi + 1; /* shift to current */ in isocal_ntp64_to_date()
1933 id->week = (uint8_t )ds.lo + 1; in isocal_ntp64_to_date()
1966 weeks = isocal_weeks_in_years((int32_t)id->year - 1) in isocal_date_to_ntp64()
1967 + (int32_t)id->week - 1; in isocal_date_to_ntp64()
1968 days = weeks * 7 + (int32_t)id->weekday; in isocal_date_to_ntp64()
1970 secs = ntpcal_etime_to_seconds(id->hour, id->minute, id->second); in isocal_date_to_ntp64()
1972 return ntpcal_dayjoin(days - DAY_NTP_STARTS, secs); in isocal_date_to_ntp64()
2007 * before the UNIX epoch (1970-01-01). It's probably not possible in basedate_eval_buildstamp()
2011 jd.monthday -= 1; in basedate_eval_buildstamp()
2012 ed = ntpcal_date_to_rd(&jd) - DAY_NTP_STARTS; in basedate_eval_buildstamp()
2027 rc = sscanf(str, "%4hu-%2hu-%2hu%n", &y, &m, &d, &nc); in basedate_eval_string()
2030 return ntpcal_edate_to_eradays(y-1, m-1, d) in basedate_eval_string()
2031 - DAY_NTP_STARTS; in basedate_eval_string()
2073 msyslog(LOG_INFO, "basedate set to %04hu-%02hu-%02hu", in basedate_set_day()
2074 jd.year, (u_short)jd.month, (u_short)jd.monthday); in basedate_set_day()
2078 - DAY_NTP_STARTS; in basedate_set_day()
2081 s_gpsweek = (day - NTP_TO_GPS_DAYS) / DAYSPERWEEK; in basedate_set_day()
2083 msyslog(LOG_INFO, "gps base set to %04hu-%02hu-%02hu (week %d)", in basedate_set_day()
2084 jd.year, (u_short)jd.month, (u_short)jd.monthday, s_gpsweek); in basedate_set_day()
2093 retv = (time_t)(s_baseday - NTP_TO_UNIX_DAYS); in basedate_get_eracenter()
2103 retv = (time_t)(s_baseday - NTP_TO_UNIX_DAYS); in basedate_get_erabase()
2120 * unsigned and we cannot go before the start of the GPS epoch in basedate_expand_gpsweek()
2125 # error GPSWEEKS defined wrong -- should be 1024! in basedate_expand_gpsweek()
2129 diff = ((uint32_t)weekno - s_gpsweek) & (GPSWEEKS - 1); in basedate_expand_gpsweek()
2139 /* --------------------------------------------------------------------
2140 * reconstruct the centrury from a truncated date and a day-of-week
2142 * Given a date with truncated year (2-digit, 0..99) and a day-of-week
2143 * from 1(Mon) to 7(Sun), recover the full year between 1900AD and 2300AD.
2159 * 3) For calendar math, a century starts with the 1st year, in ntpcal_expand_century()
2160 * which is year 1, !not! zero. in ntpcal_expand_century()
2162 * So we start with taking the weekday difference (mod 7) in ntpcal_expand_century()
2173 * If this yields a result of 4/5/6, the given date/day-of-week in ntpcal_expand_century()
2175 * year to indicate failure. in ntpcal_expand_century()
2177 * Then we remap the century to the range starting with year in ntpcal_expand_century()
2184 if ((y >= 100u) || (--m >= 12u) || (--d >= 31u)) in ntpcal_expand_century()
2188 m -= 12u; in ntpcal_expand_century()
2189 else if (--y >= 100u) in ntpcal_expand_century()
2191 d += y + (y >> 2) + 2u; /* year share */ in ntpcal_expand_century()
2194 /* get (wd - d), shifted to positive value, and multiply with in ntpcal_expand_century()
2198 * '--d' above, so we add just 251 here! in ntpcal_expand_century()
2200 c = u32mod7(3 * (251u + wd - d)); in ntpcal_expand_century()
2205 y -= 100u; in ntpcal_expand_century()
2225 len = snprintf(buf, len, "%04u-%02u-%02uT%02u:%02u:%02u", in ntpcal_iso8601std()
2226 cdp->year, cdp->month, cdp->monthday, in ntpcal_iso8601std()
2227 cdp->hour, cdp->minute, cdp->second); in ntpcal_iso8601std()
2234 /* -*-EOF-*- */