time_fuzz: time_fuzz

Description Details Value Examples

Description

time_fuzz

Details

Methods

freeze(...)

Freeze time

Value

an time_fuzz object

Examples

 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
## Not run: 
x <- time_fuzz$new()
x
x$date

x <- time_fuzz$new()
x
x$freeze
x$freeze("2019-01-29", {
  5 + 5
})

x$scale
x$scale({
  5 + 5
})

library(timefuzz)
library(clock)
library(testthat)
# clock::clock_mock()
clock:::clock_opts$mock
(cl <- clock())
book_due <- function(due_date = "2020-08-25") {
  as.POSIXct(clock::clock()$date()) > as.POSIXct(due_date)
}
expect_false(book_due()) # FALSE
x <- time_fuzz$new()
x
x$freeze(Sys.Date() + 60, {
  # clock::clock_mock()
  # cat(clock:::clock_opts$mock, sep = "\n")
  # cat(as.character(clock::clock()$date()), sep = "\n")
  # cat(clock:::clock_opts$mock, sep = "\n")
  expect_true(book_due())
})

# no block passed
clock_mock()
clock()$now()
Sys.time()
x <- time_fuzz$new()
## set to today + 435 days
x$freeze(Sys.Date() + 435)
clock:::clock_opts$mock
clock()$now()
x$unfreeze()
clock:::clock_opts$mock
clock()$now()

## End(Not run)

ropenscilabs/timefuzz documentation built on Sept. 23, 2020, 9:47 p.m.