Debian Codegraph @

tests/testthat/test-timezone.R

raw
1 describe("with_timezone", {
2 it("changes the time zone", {
3 expect_equal(with_timezone("CET", Sys.timezone()), "CET")
4 expect_equal(with_timezone("GMT", Sys.timezone()), "GMT")
5 expect_true(
6 with_timezone("CET", format(Sys.time(), "%Z")) %in% c("CET", "CEST"))
7 expect_true(
8 with_timezone("America/Los_Angeles", format(Sys.time(), "%Z")) %in% c("PDT", "PST"))
9
10 })
11
12 it("restores the time zone", {
13 cur <- Sys.timezone()
14 expect_equal(with_timezone("CET", Sys.timezone()), "CET")
15 expect_identical(cur, Sys.timezone())
16
17 cur <- Sys.timezone()
18 expect_equal(with_timezone("America/Los_Angeles", Sys.timezone()), "America/Los_Angeles")
19 expect_identical(cur, Sys.timezone())
20 })
21 })
22
23 describe("local_timezone", {
24 it("changes the time zone", {
25 fun <- function(tzone) {
26 local_timezone(tzone)
27 Sys.timezone()
28 }
29 expect_identical(
30 with_timezone("CET", Sys.timezone()),
31 fun("CET"))
32 expect_identical(
33 with_timezone("America/Los_Angeles", Sys.timezone()),
34 fun("America/Los_Angeles"))
35 })
36
37 it("restores the time zone", {
38 cur <- Sys.timezone()
39 fun <- function(tzone) {
40 local_timezone(tzone)
41 "foobar"
42 }
43 fun("CET")
44 expect_identical(cur, Sys.timezone())
45 fun("America/Los_Angeles")
46 expect_identical(cur, Sys.timezone())
47 })
48 })