-
Notifications
You must be signed in to change notification settings - Fork 1k
fwrite: fix integer-backed POSIXct writing epoch instead of ISO #3535 #7728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21585,3 +21585,20 @@ close(con) | |
| file.create(f <- tempfile()) | ||
| test(2367.6, fread(file(f)), data.table(), warning="Connection has size 0.") | ||
| unlink(f) | ||
| # fwrite ignores dateTimeAs for integer-backed POSIXct created by seq() #3535 | ||
| oldtz = Sys.getenv('TZ') | ||
| Sys.setenv(TZ = 'UTC') | ||
| tmp <- tempfile() | ||
| on.exit(Sys.setenv(TZ = oldtz), add = TRUE) | ||
| DT <- data.table(x = seq(as.POSIXct('1970-01-01'), by = '1 sec', length = 6)) | ||
| fwrite(DT, tmp) | ||
| test(2368.1, capture.output(cat(readLines(tmp), sep = '\n')), c( | ||
|
Comment on lines
+21594
to
+21595
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't give an output argument to
|
||
| "x", | ||
| "1970-01-01T00:00:00Z", | ||
| "1970-01-01T00:00:01Z", | ||
| "1970-01-01T00:00:02Z", | ||
| "1970-01-01T00:00:03Z", | ||
| "1970-01-01T00:00:04Z", | ||
| "1970-01-01T00:00:05Z" | ||
| )) | ||
| rm(DT, tmp, oldtz) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -480,6 +480,16 @@ void writePOSIXct(const void *col, int64_t row, char **pch) | |
| *pch = ch; | ||
| } | ||
|
|
||
| void writePOSIXctInt(const void *col, int64_t row, char **pch) | ||
| { | ||
| // integer-backed POSIXct | ||
| // before formatting, since writePOSIXct expects double storage | ||
| int32_t xi = ((const int32_t*)col)[row]; | ||
| double x = (xi == INT32_MIN) ? NAN : (double)xi; | ||
| const void *tmp = &x; | ||
| writePOSIXct(tmp, 0, pch); | ||
|
Comment on lines
+489
to
+490
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can give |
||
| } | ||
|
|
||
| // # nocov start. Covered in other.Rraw test 22, not the main suite. | ||
| void writeNanotime(const void *col, int64_t row, char **pch) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ writer_fun_t writeITime; | |
| writer_fun_t writeDateInt32; | ||
| writer_fun_t writeDateFloat64; | ||
| writer_fun_t writePOSIXct; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about renaming this function to |
||
| writer_fun_t writePOSIXctInt; | ||
| writer_fun_t writeNanotime; | ||
| writer_fun_t writeString; | ||
| writer_fun_t writeCategString; | ||
|
|
@@ -42,6 +43,7 @@ typedef enum { // same order as fun[] above | |
| WF_DateInt32, | ||
| WF_DateFloat64, | ||
| WF_POSIXct, | ||
| WF_POSIXctInt, | ||
| WF_Nanotime, | ||
| WF_String, | ||
| WF_CategString, | ||
|
|
@@ -60,6 +62,7 @@ static const int writerMaxLen[] = { // same order as fun[] and WFs above; max f | |
| 16, //&writeDateInt32 | ||
| 16, //&writeDateFloat64 | ||
| 32, //&writePOSIXct | ||
| 32, //&writePOSIXctInt | ||
| 48, //&writeNanotime | ||
| 0, //&writeString | ||
| 0, //&writeCategString | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to adjust
TZ, just give thetz = 'UTC'argument toas.POSIXct().