Is the input in the past/future?

Description

Checks to see if the input is a time in the past/future, or before/after some time point.

Usage

 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
assert_all_are_after(x, y, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_after(x, y, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_before(x, y, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_before(x, y, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_in_future(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_in_future(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_in_past(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_in_past(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_after(x, y, .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y))

is_before(x, y, .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y))

is_in_future(x, .xname = get_name_in_parent(x))

is_in_past(x, .xname = get_name_in_parent(x))

Arguments

x

Date or POSIXt input to check.

y

Another date-time object to compare against.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

.yname

Not intended to be used directly.

Details

The current time is determined by Sys.time, and the input is coerced to POSIXct format if necessary.

Value

The is_* function return TRUE if the input is a time in the future/past. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

Note

Note that the print method for POSIXct objects means that the cause attribute (in the event of failures) is not shown. You can still access it via, e.g., cause(is_in_past(x)).

See Also

Sys.time.

Examples

1
2
3
4
5
6
7
x <- Sys.time() + c(-1, 100)
is_in_past(x)
is_in_future(x)

# more generally, compare against any date-time
is_before(x, as.POSIXct("9999-12-31"))
is_after(x, as.POSIXct("0001-01-01"))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.