File: with_timezone.Rd

package info (click to toggle)
r-cran-withr 3.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 620 kB
  • sloc: sh: 13; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/timezone.R
\name{with_timezone}
\alias{with_timezone}
\alias{local_timezone}
\title{Time zone}
\usage{
with_timezone(tz, code)

local_timezone(tz, .local_envir = parent.frame())
}
\arguments{
\item{tz}{\verb{[character(1)]} a valid time zone specification, note that
time zone names might be platform dependent.}

\item{code}{\code{[any]}\cr Code to execute in the temporary environment}

\item{.local_envir}{The environment to apply the change to.}
}
\value{
\code{[any]}\cr The results of the evaluation of the \code{code}
argument.
}
\description{
Change the time zone, and restore it afterwards.
}
\details{
\code{with_timezone()} runs the code with the specified time zone and
resets it afterwards.

\code{local_timezone()} changes the time zone for the caller
execution environment.
}
\examples{
Sys.time()
with_timezone("Europe/Paris", print(Sys.time()))
with_timezone("America/Los_Angeles", print(Sys.time()))

fun1 <- function() {
  local_timezone("CET")
  print(Sys.time())
}

fun2 <- function() {
  local_timezone("America/Los_Angeles")
  print(Sys.time())
}
Sys.time()
fun1()
fun2()
Sys.time()
}
\seealso{
\code{\link{withr}} for examples

\code{\link[=Sys.timezone]{Sys.timezone()}}.
}