Skip to content

Commit

Permalink
Use geographical region for timezones
Browse files Browse the repository at this point in the history
Fixes:

── Error ('test-timezone.R:7:5'): with_timezone: changes the time zone ─────────
Error in `format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...)`: output string exceeded 2048 bytes
Backtrace:
▆
1. ├─testthat::expect_true(...) at test-timezone.R:7:4
2. │ └─testthat::quasi_label(enquo(object), label, arg = "object")
3. │ └─rlang::eval_bare(expr, quo_get_env(quo))
4. ├─... %in% c("PDT", "PST")
5. ├─withr::with_timezone("US/Pacific", format(Sys.time(), "%Z"))
6. │ └─withr::with_envvar(c(TZ = tz), code)
7. │ └─base::force(code)
8. ├─base::format(Sys.time(), "%Z")
9. └─base::format.POSIXct(Sys.time(), "%Z")
10. ├─base::structure(...)
11. └─base::format.POSIXlt(as.POSIXlt(x, tz), format, usetz, ...)

Notes from Kurt:

The errors for r-devel-linux-x86_64-debian-gcc (which will eventually
also show for the other Debian-based checks) are from a recent system
upgrade of the tzdata package which dropped the legacy timezone
symlinks that are not following the current rule of using the
geographical region
(continent or ocean) and city name (the "backward" links from tzdata),
such as

  GB            -> Europe/London
  NZ            -> Pacific/Auckland
  US/Eastern    -> America/New_York
  US/Pacific    -> America/Los_Angeles
  • Loading branch information
lionel- committed Sep 26, 2023
1 parent ce29fab commit ba5beb5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions R/timezone.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @examples
#' Sys.time()
#' with_timezone("Europe/Paris", print(Sys.time()))
#' with_timezone("US/Pacific", print(Sys.time()))
#' with_timezone("America/Los_Angeles", print(Sys.time()))
#'
with_timezone <- function(tz, code) {
reset_timezone()
Expand All @@ -34,7 +34,7 @@ with_timezone <- function(tz, code) {
#' }
#'
#' fun2 <- function() {
#' local_timezone("US/Pacific")
#' local_timezone("America/Los_Angeles")
#' print(Sys.time())
#' }
#' Sys.time()
Expand Down
4 changes: 2 additions & 2 deletions man/with_tempfile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/with_timezone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/testthat/test-timezone.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("with_timezone", {
expect_true(
with_timezone("CET", format(Sys.time(), "%Z")) %in% c("CET", "CEST"))
expect_true(
with_timezone("US/Pacific", format(Sys.time(), "%Z")) %in% c("PDT", "PST"))
with_timezone("America/Los_Angeles", format(Sys.time(), "%Z")) %in% c("PDT", "PST"))

})

Expand All @@ -15,7 +15,7 @@ describe("with_timezone", {
expect_identical(cur, Sys.timezone())

cur <- Sys.timezone()
expect_equal(with_timezone("US/Pacific", Sys.timezone()), "US/Pacific")
expect_equal(with_timezone("America/Los_Angeles", Sys.timezone()), "America/Los_Angeles")
expect_identical(cur, Sys.timezone())
})
})
Expand All @@ -30,8 +30,8 @@ describe("local_timezone", {
with_timezone("CET", Sys.timezone()),
fun("CET"))
expect_identical(
with_timezone("US/Pacific", Sys.timezone()),
fun("US/Pacific"))
with_timezone("America/Los_Angeles", Sys.timezone()),
fun("America/Los_Angeles"))
})

it("restores the time zone", {
Expand All @@ -42,7 +42,7 @@ describe("local_timezone", {
}
fun("CET")
expect_identical(cur, Sys.timezone())
fun("US/Pacific")
fun("America/Los_Angeles")
expect_identical(cur, Sys.timezone())
})
})

0 comments on commit ba5beb5

Please sign in to comment.