1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
- // jedit: :folding=explicit:
1
+
3
2
//
4
3
// Date.cpp: Rcpp R/C++ interface class library -- Date type
5
4
//
6
- // Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
5
+ // Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
7
6
//
8
7
// The mktime00() as well as the gmtime_() replacement function are
9
8
// Copyright (C) 2000 - 2010 The R Development Core Team.
@@ -85,11 +84,11 @@ namespace Rcpp {
85
84
year0 = year_base + tm.tm_year ;
86
85
/* safety check for unbounded loops */
87
86
if (year0 > 3000 ) {
88
- excess = (int )(year0/2000 ) - 1 ;
87
+ excess = (int )(year0/2000 ) - 1 ; // #nocov start
89
88
year0 -= excess * 2000 ;
90
89
} else if (year0 < 0 ) {
91
90
excess = -1 - (int )(-year0/2000 );
92
- year0 -= excess * 2000 ;
91
+ year0 -= excess * 2000 ; // #nocov end
93
92
}
94
93
95
94
for (i = 0 ; i < tm.tm_mon ; i++) day += days_in_month[i];
@@ -461,12 +460,12 @@ struct tzhead {
461
460
** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
462
461
*/
463
462
if ((i >= 0 ) ? (j > INT_MAX - i) : (j < INT_MIN - i))
464
- return TRUE ;
463
+ return TRUE ; // #nocov
465
464
*ip += j;
466
465
return FALSE ;
467
466
}
468
467
469
- static int increment_overflow_time (time_t *tp, int_fast32_t j) {
468
+ static int increment_overflow_time (time_t *tp, int_fast32_t j) { // #nocov start
470
469
/*
471
470
** This is like
472
471
** 'if (! (time_t_min <= *tp + j && *tp + j <= time_t_max)) ...',
@@ -477,10 +476,10 @@ struct tzhead {
477
476
: *tp <= time_t_max - j))
478
477
return TRUE ;
479
478
*tp += j;
480
- return FALSE ;
479
+ return FALSE ;
481
480
}
482
481
483
- static int_fast32_t detzcode (const char *const codep) { // #nocov start
482
+ static int_fast32_t detzcode (const char *const codep) {
484
483
int_fast32_t result = (codep[0 ] & 0x80 ) ? -1 : 0 ;
485
484
for (int i = 0 ; i < 4 ; ++i)
486
485
result = (result << 8 ) | (codep[i] & 0xff );
@@ -1241,7 +1240,7 @@ struct tzhead {
1241
1240
hit = 0 ;
1242
1241
i = sp->leapcnt ;
1243
1242
while (--i >= 0 ) {
1244
- lp = &sp->lsis [i];
1243
+ lp = &sp->lsis [i]; // #nocov start
1245
1244
if (*timep >= lp->ls_trans ) {
1246
1245
if (*timep == lp->ls_trans ) {
1247
1246
hit = ((i == 0 && lp->ls_corr > 0 ) ||
@@ -1257,7 +1256,7 @@ struct tzhead {
1257
1256
}
1258
1257
}
1259
1258
corr = lp->ls_corr ;
1260
- break ;
1259
+ break ; // #nocov end
1261
1260
}
1262
1261
}
1263
1262
y = EPOCH_YEAR;
@@ -1272,7 +1271,7 @@ struct tzhead {
1272
1271
tdelta = tdays / DAYSPERLYEAR;
1273
1272
if (! ((! TYPE_SIGNED (time_t ) || INT_MIN <= tdelta)
1274
1273
&& tdelta <= INT_MAX))
1275
- return NULL ;
1274
+ return NULL ; // #nocov
1276
1275
idelta = (int )tdelta;
1277
1276
if (idelta == 0 )
1278
1277
idelta = (tdays < 0 ) ? -1 : 1 ;
@@ -1297,7 +1296,7 @@ struct tzhead {
1297
1296
*/
1298
1297
idays = (int )tdays;
1299
1298
rem += offset - corr;
1300
- while (rem < 0 ) {
1299
+ while (rem < 0 ) { // #nocov start
1301
1300
rem += SECSPERDAY;
1302
1301
--idays;
1303
1302
}
@@ -1313,14 +1312,14 @@ struct tzhead {
1313
1312
while (idays >= year_lengths[isleap (y)]) {
1314
1313
idays -= year_lengths[isleap (y)];
1315
1314
if (increment_overflow (&y, 1 ))
1316
- return NULL ;
1315
+ return NULL ; // #nocov end
1317
1316
}
1318
1317
// Previously we returned 'year + base', so keep behaviour
1319
1318
// It seems like R now returns just 'year - 1900' (as libc does)
1320
1319
// But better for continuity to do as before
1321
1320
tmp->tm_year = y + TM_YEAR_BASE;
1322
1321
if (increment_overflow (&tmp->tm_year , -TM_YEAR_BASE))
1323
- return NULL ;
1322
+ return NULL ; // #nocov
1324
1323
tmp->tm_yday = idays;
1325
1324
/*
1326
1325
** The "extra" mods below avoid overflow problems.
@@ -1333,7 +1332,7 @@ struct tzhead {
1333
1332
idays;
1334
1333
tmp->tm_wday %= DAYSPERWEEK;
1335
1334
if (tmp->tm_wday < 0 )
1336
- tmp->tm_wday += DAYSPERWEEK;
1335
+ tmp->tm_wday += DAYSPERWEEK; // #nocov
1337
1336
tmp->tm_hour = (int ) (rem / SECSPERHOUR);
1338
1337
rem %= SECSPERHOUR;
1339
1338
tmp->tm_min = (int ) (rem / SECSPERMIN);
0 commit comments