@@ -47,8 +47,6 @@ test_that("coerce_datetime fills the void", {
47
47
})
48
48
49
49
test_that(" parse_connect_rfc3339() parses timestamps with offsets as expected" , {
50
- withr :: defer(Sys.setenv(TZ = Sys.getenv(" TZ" )))
51
-
52
50
x_mixed <- c(
53
51
" 2023-08-22T14:13:14Z" ,
54
52
" 2020-01-01T01:02:03Z" ,
@@ -75,32 +73,47 @@ test_that("parse_connect_rfc3339() parses timestamps with offsets as expected",
75
73
76
74
single_offset <- " 2023-08-22T15:13:14+01:00"
77
75
76
+ withr :: local_envvar(TZ = " America/New_York" )
78
77
expected <- as.POSIXct(strptime(
79
78
c(
80
79
" 2023-08-22T14:13:14+0000" ,
81
80
" 2020-01-01T01:02:03+0000"
82
81
),
83
82
format = " %Y-%m-%dT%H:%M:%S%z" ,
84
- tz = " UTC "
83
+ tz = Sys.timezone()
85
84
))
86
-
87
- Sys.setenv(TZ = " America/New_York" )
88
85
expect_identical(parse_connect_rfc3339(x_mixed ), rep(expected , 2 ))
89
86
expect_identical(parse_connect_rfc3339(x_zero_offset ), expected )
90
87
expect_identical(parse_connect_rfc3339(x_plus_one ), expected )
91
88
expect_identical(parse_connect_rfc3339(x_minus_one ), expected )
92
89
expect_identical(parse_connect_rfc3339(single_zero_offset ), expected [1 ])
93
90
expect_identical(parse_connect_rfc3339(single_offset ), expected [1 ])
94
91
95
- Sys.setenv(TZ = " UTC" )
92
+ withr :: local_envvar(TZ = " UTC" )
93
+ expected <- as.POSIXct(strptime(
94
+ c(
95
+ " 2023-08-22T14:13:14+0000" ,
96
+ " 2020-01-01T01:02:03+0000"
97
+ ),
98
+ format = " %Y-%m-%dT%H:%M:%S%z" ,
99
+ tz = Sys.timezone()
100
+ ))
96
101
expect_identical(parse_connect_rfc3339(x_mixed ), rep(expected , 2 ))
97
102
expect_identical(parse_connect_rfc3339(x_zero_offset ), expected )
98
103
expect_identical(parse_connect_rfc3339(x_plus_one ), expected )
99
104
expect_identical(parse_connect_rfc3339(x_minus_one ), expected )
100
105
expect_identical(parse_connect_rfc3339(single_zero_offset ), expected [1 ])
101
106
expect_identical(parse_connect_rfc3339(single_offset ), expected [1 ])
102
107
103
- Sys.setenv(TZ = " Asia/Tokyo" )
108
+ withr :: local_envvar(TZ = " Asia/Tokyo" )
109
+ expected <- as.POSIXct(strptime(
110
+ c(
111
+ " 2023-08-22T14:13:14+0000" ,
112
+ " 2020-01-01T01:02:03+0000"
113
+ ),
114
+ format = " %Y-%m-%dT%H:%M:%S%z" ,
115
+ tz = Sys.timezone()
116
+ ))
104
117
expect_identical(parse_connect_rfc3339(x_mixed ), rep(expected , 2 ))
105
118
expect_identical(parse_connect_rfc3339(x_zero_offset ), expected )
106
119
expect_identical(parse_connect_rfc3339(x_plus_one ), expected )
@@ -109,7 +122,9 @@ test_that("parse_connect_rfc3339() parses timestamps with offsets as expected",
109
122
expect_identical(parse_connect_rfc3339(single_offset ), expected [1 ])
110
123
})
111
124
125
+
112
126
test_that(" parse_connect_rfc3339() handles fractional seconds" , {
127
+ withr :: local_envvar(TZ = " UTC" )
113
128
expected <- as.POSIXct(strptime(
114
129
c(
115
130
" 2024-12-06T19:09:29.948016766+0000" ,
@@ -125,8 +140,6 @@ test_that("parse_connect_rfc3339() handles fractional seconds", {
125
140
})
126
141
127
142
test_that(" make_timestamp produces expected output" , {
128
- withr :: defer(Sys.setenv(TZ = Sys.getenv(" TZ" )))
129
-
130
143
x_mixed <- c(
131
144
" 2023-08-22T14:13:14Z" ,
132
145
" 2020-01-01T01:02:03Z" ,
@@ -158,7 +171,7 @@ test_that("make_timestamp produces expected output", {
158
171
" 2020-01-01T01:02:03Z"
159
172
)
160
173
161
- Sys.setenv (TZ = " America/New_York" )
174
+ withr :: local_envvar (TZ = " America/New_York" )
162
175
expect_equal(
163
176
make_timestamp(coerce_datetime(x_mixed , NA_datetime_ )),
164
177
rep(outcome , 2 )
@@ -185,7 +198,7 @@ test_that("make_timestamp produces expected output", {
185
198
)
186
199
expect_equal(make_timestamp(outcome ), outcome )
187
200
188
- Sys.setenv (TZ = " UTC" )
201
+ withr :: local_envvar (TZ = " UTC" )
189
202
expect_equal(
190
203
make_timestamp(coerce_datetime(x_mixed , NA_datetime_ )),
191
204
rep(outcome , 2 )
@@ -212,7 +225,7 @@ test_that("make_timestamp produces expected output", {
212
225
)
213
226
expect_equal(make_timestamp(outcome ), outcome )
214
227
215
- Sys.setenv (TZ = " Asia/Tokyo" )
228
+ withr :: local_envvar (TZ = " Asia/Tokyo" )
216
229
expect_equal(
217
230
make_timestamp(coerce_datetime(x_mixed , NA_datetime_ )),
218
231
rep(outcome , 2 )
0 commit comments