Covert windows
to and from case_lengths
and recurrence_lengths
.
epid_windows(date, lengths, episode_unit = "days")
epid_lengths(date, windows, episode_unit = "days")
index_window(date, from_last = FALSE)
As used in episodes
.
The duration (lengths
) between a date
and window
.
Time unit of lengths
. Options are "seconds", "minutes", "hours", "days", "weeks", "months" or "years". See diyar::episode_unit
The range (windows
) relative to a date
for a given duration (length
).
As used in episodes
.
epid_windows
- returns the corresponding window
for a given a date
, and case_length
or recurrence_length
.
epid_lengths
- returns the corresponding case_length
or recurrence_length
for a given date
and window
.
index_window
- returns the corresponding case_length
or recurrence_length
for the date
only.
index_window(date = x)
is a convenience function for epid_lengths(date = x, window = x)
.
# Which `window` will a given `length` cover?
date <- Sys.Date()
epid_windows(date, 10)
#> [1] "2023-11-12 -> 2023-11-22"
epid_windows(date, number_line(5, 10))
#> [1] "2023-11-17 -> 2023-11-22"
epid_windows(date, number_line(-5, 10))
#> [1] "2023-11-07 -> 2023-11-22"
epid_windows(date, -5)
#> [1] "2023-11-12 <- 2023-11-07"
# Which `length` is required to cover a given `window`?
date <- number_line(Sys.Date(), Sys.Date() + 20)
epid_lengths(date, Sys.Date() + 30)
#> [1] "10 == 10"
epid_lengths(date, number_line(Sys.Date() + 25, Sys.Date() + 30))
#> [1] "5 -> 10"
epid_lengths(date, number_line(Sys.Date() - 10, Sys.Date() + 30))
#> [1] "-30 -> 10"
epid_lengths(date, Sys.Date() - 10)
#> [1] "-30 == -30"
# Which `length` is required to cover the `date`?
index_window(20)
#> [1] "0 == 0"
index_window(number_line(15, 20))
#> [1] "-5 -> 0"