Learn R Programming

assertive.datetimes (version 0.0-3)

assert_all_are_after: 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

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.

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.

Details

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

See Also

Sys.time.

Examples

Run this code
# NOT RUN {
datetime <- Sys.time() + c(-1, 100)
is_in_past(datetime)
is_in_future(datetime)
date <- Sys.Date() + c(-1, 100)

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

Run the code above in your browser using DataLab