You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DT_trunc = copy(DT)[, times := as.POSIXct(trunc(times))]
17079
17079
tmp = tempfile()
17080
17080
## ISO8601 format (%FT%TZ) by default
17081
-
fwrite(DT, tmp)
17082
-
test(2150.01, fread(tmp), DT) # defaults for fwrite/fread simple and preserving
17083
-
fwrite(DT, tmp, dateTimeAs='write.csv') # as write.csv, writes the UTC times as-is not local because the time column has tzone=="UTC", but without the Z marker. Also truncates milliseconds, hence DT_trunc below.
17084
-
test(2150.021, env=list(TZ=NULL), sapply(fread(tmp,tz=""), typeof), c(dates="integer", times="character")) # from v1.14.0 tz="" needed to read datetime as character
17085
-
test(2150.022, env=list(TZ=NULL), fread(tmp,tz="UTC"), DT_trunc) # user can tell fread to interpret the unmarked datetimes as UTC
17086
-
test(2150.023, env=c(TZ='UTC'), fread(tmp), DT_trunc) # TZ environment variable is also recognized
17087
-
if (.Platform$OS.type!="windows") {
17088
-
test(2150.024, env=c(TZ=''), fread(tmp), DT_trunc) # on Windows this unsets TZ, see ?Sys.setenv
17089
-
# blank TZ env variable on non-Windows is recognized as UTC consistent with C and R; but R's tz= argument is the opposite and uses "" for local
17090
-
}
17081
+
local({
17082
+
old=options(digits.secs=0); on.exit(options(old))
17083
+
fwrite(DT, tmp)
17084
+
test(2150.01, fread(tmp), DT) # defaults for fwrite/fread simple and preserving
17085
+
fwrite(DT, tmp, dateTimeAs='write.csv') # as write.csv, writes the UTC times as-is not local because the time column has tzone=="UTC", but without the Z marker. Also truncates milliseconds, hence DT_trunc below.
17086
+
test(2150.021, env=list(TZ=NULL), sapply(fread(tmp,tz=""), typeof), c(dates="integer", times="character")) # from v1.14.0 tz="" needed to read datetime as character
17087
+
test(2150.022, env=list(TZ=NULL), fread(tmp,tz="UTC"), DT_trunc) # user can tell fread to interpret the unmarked datetimes as UTC
17088
+
test(2150.023, env=c(TZ='UTC'), fread(tmp), DT_trunc) # TZ environment variable is also recognized
17089
+
if (.Platform$OS.type!="windows") {
17090
+
test(2150.024, env=c(TZ=''), fread(tmp), DT_trunc) # on Windows this unsets TZ, see ?Sys.setenv
17091
+
# blank TZ env variable on non-Windows is recognized as UTC consistent with C and R; but R's tz= argument is the opposite and uses "" for local
17092
+
}
17093
+
})
17091
17094
# Notes:
17092
17095
# - from v1.14.0 tz="" needed
17093
17096
# - as.POSIXct puts "" on the result (testing the write.csv version here with missing tzone)
0 commit comments