Time travel to test time dependent code - a port of Ruby’s timecop
BEWARE: VERY ALPHA
Hope to support soon:
book_due() is a toy function that tells us if a book is due
Given the due date of 2020-07-31 the book is not due
expect_false(book_due()) # FALSE
x <- time_fuzz$new() x #> <time_fuzz> #> date:
freez(), passing the date you want to freeze time to, and then a code block to run in the context of that frozen time. Here we’ll freeze time to today + 450 days
book_due() results in
TRUE now, whereas it was
FALSE above in real time
x <- time_fuzz$new() ## set to today + 450 days x$freeze(Sys.Date() + 450)
We’re in the freezed date. So any time based actions using the [clock] package are now using your frozen time context.
sys_time() #>  "2021-10-13 17:00:00 PDT"
$unfreeze() to unfreeze
now we’re back in current time
sys_time() #>  "2020-07-21 17:18:32 PDT"