Debian Codegraph @

man/with_timezone.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/timezone.R
3 \name{with_timezone}
4 \alias{with_timezone}
5 \alias{local_timezone}
6 \title{Time zone}
7 \usage{
8 with_timezone(tz, code)
9
10 local_timezone(tz, .local_envir = parent.frame())
11 }
12 \arguments{
13 \item{tz}{\verb{[character(1)]} a valid time zone specification, note that
14 time zone names might be platform dependent.}
15
16 \item{code}{\code{[any]}\cr Code to execute in the temporary environment}
17
18 \item{.local_envir}{The environment to apply the change to.}
19 }
20 \value{
21 \code{[any]}\cr The results of the evaluation of the \code{code}
22 argument.
23 }
24 \description{
25 Change the time zone, and restore it afterwards.
26 }
27 \details{
28 \code{with_timezone()} runs the code with the specified time zone and
29 resets it afterwards.
30
31 \code{local_timezone()} changes the time zone for the caller
32 execution environment.
33 }
34 \examples{
35 Sys.time()
36 with_timezone("Europe/Paris", print(Sys.time()))
37 with_timezone("America/Los_Angeles", print(Sys.time()))
38
39 fun1 <- function() {
40 local_timezone("CET")
41 print(Sys.time())
42 }
43
44 fun2 <- function() {
45 local_timezone("America/Los_Angeles")
46 print(Sys.time())
47 }
48 Sys.time()
49 fun1()
50 fun2()
51 Sys.time()
52 }
53 \seealso{
54 \code{\link{withr}} for examples
55
56 \code{\link[=Sys.timezone]{Sys.timezone()}}.
57 }