MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / timesub

Function timesub

src/date.cpp:1226–1353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1224 }
1225
1226 static struct tm * timesub(const time_t *const timep, const int_fast32_t offset,
1227 const struct state *const sp, struct tm *const tmp) {
1228 const struct lsinfo * lp;
1229 time_t tdays;
1230 int idays; /* unsigned would be so 2003 */
1231 int_fast64_t rem;
1232 int y;
1233 const int * ip;
1234 int_fast64_t corr;
1235 int hit;
1236 int i;
1237
1238 corr = 0;
1239 hit = 0;
1240 i = sp->leapcnt;
1241 while (--i >= 0) {
1242 lp = &sp->lsis[i]; // #nocov start
1243 if (*timep >= lp->ls_trans) {
1244 if (*timep == lp->ls_trans) {
1245 hit = ((i == 0 && lp->ls_corr > 0) ||
1246 lp->ls_corr > sp->lsis[i - 1].ls_corr);
1247 if (hit)
1248 while (i > 0 &&
1249 sp->lsis[i].ls_trans ==
1250 sp->lsis[i - 1].ls_trans + 1 &&
1251 sp->lsis[i].ls_corr ==
1252 sp->lsis[i - 1].ls_corr + 1) {
1253 ++hit;
1254 --i;
1255 }
1256 }
1257 corr = lp->ls_corr;
1258 break; // #nocov end
1259 }
1260 }
1261 y = EPOCH_YEAR;
1262 tdays = *timep / SECSPERDAY;
1263 rem = *timep - tdays * SECSPERDAY;
1264 while (tdays < 0 || tdays >= year_lengths[isleap(y)]) {
1265 int newy;
1266 time_t tdelta;
1267 int idelta;
1268 int leapdays;
1269
1270 tdelta = tdays / DAYSPERLYEAR;
1271 if (! ((! TYPE_SIGNED(time_t) || INT_MIN <= tdelta)
1272 && tdelta <= INT_MAX))
1273 return NULL; // #nocov
1274 idelta = (int)tdelta;
1275 if (idelta == 0)
1276 idelta = (tdays < 0) ? -1 : 1;
1277 newy = y;
1278 if (increment_overflow(&newy, idelta))
1279 return NULL; // #nocov
1280 leapdays = leaps_thru_end_of(newy - 1) -
1281 leaps_thru_end_of(y - 1);
1282 tdays -= ((time_t) newy - y) * DAYSPERNYEAR;
1283 tdays -= leapdays;

Callers 1

gmtsubFunction · 0.85

Calls 2

increment_overflowFunction · 0.85
leaps_thru_end_ofFunction · 0.85

Tested by

no test coverage detected