Description Usage Arguments Details Value Examples
View source: R/pretend_now_is.R
This method stubs the built-in Sys.time
,
Sys.Date
, and date
methods with an overwritten
value for use in unit tests.
1 | pretend_now_is(time, expr)
|
time |
Date or POSIXct or character. For example,
|
expr |
expression. The expression to evaluate while pretending
the current time is |
Either a Date
or POSIXct
object can be
provided, or an English string in the form "<number> <unit>s <from now/ago>"
such as:
1 hour ago
2 months from now
10 seconds ago
These are translated into Sys.time() + as.difftime(number, units = unit)
(or -
in the case of "ago").
the value of expr
.
1 2 3 4 5 6 7 8 9 10 | pretend_now_is(Sys.time() + as.difftime(1, units = "days"), {
cat("It's UNIX time ", Sys.time(), ", tomorrow!\n", sep = "")
})
now <- Sys.time()
pretend_now_is("10 minutes from now", {
stopifnot(all.equal(
as.integer(as.difftime(Sys.time() - now, units = "minutes")),
10))
})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.