knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Time classes for R, w/ time mocking capability via timefuzz
library(pendulum)
clock(2009)$time clock(2009, 3, 13)$time clock(2009, 3, 13, 1, 4, 53)$time
x <- clock(2009, 3, 13) x$utc x$date
now()$now() now("UTC")$now()
Mockable [Sys.Date()] drop in replacement. Uses now()
internally so can be mocked as shown below.
Sys.Date() sys_date()
Mockable [Sys.time()] drop in replacement. Uses now()
internally so can be mocked as shown below.
Sys.time() sys_time()
todays_date <- function() sys_time() todays_date()
now let's mock time
library(timefuzz) x <- time_fuzz$new() ## set to today + 5 days x$freeze(Sys.Date() + 5) todays_date() # if you run it again, you get the same EXACT time todays_date()
"unfreeze" and you're back to real time
x$unfreeze() todays_date() Sys.sleep(1) todays_date() Sys.sleep(1) todays_date()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.