Skip to content

Commit e70f5da

Browse files
authored
Merge branch 'master' into fix-3339
2 parents 219258a + 3a45206 commit e70f5da

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050

5151
9. `fread()` no longer replaces a literal header column name `"NA"` with an auto-generated `Vn` name when `na.strings` includes `"NA"`, [#5124](https://github.com/Rdatatable/data.table/issues/5124). Data rows still continue to parse `"NA"` as missing. Thanks @Mashin6 for the report and @shrektan for the fix.
5252

53-
10. `fread()` would not give a warning when every second line of input was empty, [#3339](https://github.com/Rdatatable/data.table/issues/3339). Now, a warning message 'The rows in this file appear to be separated by blank lines.' is given and suggests to set `blank.lines.skip` to `TRUE`. Thanks to @Henrik-P for the report and @Asa-Henry for the fix.
53+
10. `fread()` no longer misreads dates with negative years, [#7704](https://github.com/Rdatatable/data.table/issues/7704). Thanks to @kevinushey for the report and @aitap for the fix.
54+
55+
11. `fread()` would not give a warning when every second line of input was empty, [#3339](https://github.com/Rdatatable/data.table/issues/3339). Now, a warning message 'The rows in this file appear to be separated by blank lines.' is given and suggests to set `blank.lines.skip` to `TRUE`. Thanks to @Henrik-P for the report and @Asa-Henry for the fix.
5456

5557
### Notes
5658

inst/tests/tests.Rraw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21587,3 +21587,9 @@ close(con)
2158721587
file.create(f <- tempfile())
2158821588
test(2367.6, fread(file(f)), data.table(), warning="Connection has size 0.")
2158921589
unlink(f)
21590+
21591+
# negative years caused UB in leap year calculation, #7704
21592+
x = fread("x\n-1-01-01")$x
21593+
test(2368.1, year(x), -1L)
21594+
test(2368.2, month(x), 1L)
21595+
test(2368.3, mday(x), 1L)

src/fread.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,13 @@ static void parse_iso8601_date_core(const char **pch, int32_t *target)
10871087
if (day == NA_INT32 || day < 1 || (day > (isLeapYear ? leapYearDays[month - 1] : normYearDays[month - 1])))
10881088
return;
10891089

1090+
int32_t cycle_year = year % 400;
1091+
if (cycle_year < 0) cycle_year += 400;
1092+
int32_t cycle = (year - cycle_year) / 400;
1093+
10901094
*target =
1091-
(year / 400 - 4) * cumDaysCycleYears[400] + // days to beginning of 400-year cycle
1092-
cumDaysCycleYears[year % 400] + // days to beginning of year within 400-year cycle
1095+
(cycle - 4) * cumDaysCycleYears[400] + // days to beginning of 400-year cycle
1096+
cumDaysCycleYears[cycle_year] + // days to beginning of year within 400-year cycle
10931097
(isLeapYear ? cumDaysCycleMonthsLeap[month - 1] : cumDaysCycleMonthsNorm[month - 1]) + // days to beginning of month within year
10941098
day - 1; // day within month (subtract 1: 1970-01-01 -> 0)
10951099

0 commit comments

Comments
 (0)