From 5553c225a4e3b17a1dfb3291faf36108a1422b8b Mon Sep 17 00:00:00 2001 From: Aakriti Kushwaha Date: Thu, 29 Jan 2026 17:23:07 +0530 Subject: [PATCH 1/4] test: fwrite POSIXct should preserve ISO-8601 datetime --- inst/tests/fwrite-datetime.Rraw.R | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 inst/tests/fwrite-datetime.Rraw.R diff --git a/inst/tests/fwrite-datetime.Rraw.R b/inst/tests/fwrite-datetime.Rraw.R new file mode 100644 index 000000000..c04fa3d31 --- /dev/null +++ b/inst/tests/fwrite-datetime.Rraw.R @@ -0,0 +1,30 @@ +test(### + #"fwrite: POSIXct should be written as ISO-8601, not numeric seconds", + { + oldtz = Sys.getenv("TZ", unset = NA) + on.exit({ + if (is.na(oldtz)) Sys.unsetenv("TZ") else Sys.setenv(TZ = oldtz) + }, add = TRUE) + + Sys.setenv(TZ = "UTC") + + DT = data.table( + x = seq( + as.POSIXct("1970-01-01", tz = "UTC"), + by = "1 sec", + length.out = 3 + ) + ) + + tmp = tempfile() + fwrite(DT, tmp) + + out = readLines(tmp) + + stopifnot( + out[1L] == "x", + out[2L] == "1970-01-01T00:00:00Z", + out[3L] == "1970-01-01T00:00:01Z", + out[4L] == "1970-01-01T00:00:02Z" + ) + }) \ No newline at end of file From 618df03d830b53fdb620ffc97d54615edc509a14 Mon Sep 17 00:00:00 2001 From: Aakriti Kushwaha Date: Thu, 29 Jan 2026 18:01:16 +0530 Subject: [PATCH 2/4] Fix fwrite POSIXct writing to ISO format #xxxx --- R/fwrite.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/fwrite.R b/R/fwrite.R index 5d91b4e34..c302ebf32 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -121,6 +121,16 @@ fwrite = function(x, file="", append=FALSE, quote="auto", x }) } + + # ensure POSIXct columns are double for proper ISO formatting + x <- lapply(x, function(col) { + if (inherits(col, "POSIXt")) { + # coerce integer-backed to double + storage.mode(col) <- "double" + } + col + }) + .Call(CfwriteR, x, file, sep, sep2, eol, na, dec, quote, qmethod=="escape", append, row.names, col.names, logical01, scipen, dateTimeAs, buffMB, nThread, showProgress, is_gzip, compressLevel, bom, yaml, verbose, encoding, forceDecimal) From b392b5e8aebd0ef696a032a73e63ae078e97effe Mon Sep 17 00:00:00 2001 From: Aakriti Kushwaha Date: Thu, 29 Jan 2026 18:03:19 +0530 Subject: [PATCH 3/4] Add test for fwrite POSIXct UTC output (ISO 8601) --- inst/tests/tests.Rraw | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 1c7ab6837..4c0c4fc8e 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -21509,3 +21509,4 @@ setdroplevels(x) setdroplevels(y) test(2364.2, levels(x$a), levels(y$a)) rm(x, y) + From a280b9a4860abed1bfc8b4dc99024107d1d24afd Mon Sep 17 00:00:00 2001 From: Aakriti Kushwaha Date: Thu, 29 Jan 2026 18:39:39 +0530 Subject: [PATCH 4/4] Add test for fwrite POSIXct ISO-8601 output --- inst/tests/fwrite-datetime.Rraw.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/tests/fwrite-datetime.Rraw.R b/inst/tests/fwrite-datetime.Rraw.R index c04fa3d31..38d840438 100644 --- a/inst/tests/fwrite-datetime.Rraw.R +++ b/inst/tests/fwrite-datetime.Rraw.R @@ -1,5 +1,5 @@ -test(### - #"fwrite: POSIXct should be written as ISO-8601, not numeric seconds", +test( + "fwrite: POSIXct should be written as ISO-8601, not numeric seconds", { oldtz = Sys.getenv("TZ", unset = NA) on.exit({