# logical_tests: Logical tests on messy dates In messydates: A Flexible Class for Messy Dates

 logical_tests R Documentation

## Logical tests on messy dates

### Description

These functions provide various logical tests for messy date objects.

### Usage

``````is_messydate(x)

is_intersecting(x, y)

is_subset(x, y)

is_similar(x, y)

is_precise(x)

is_uncertain(x)

is_approximate(x)

## S3 method for class 'mdate'
e1 < e2

## S3 method for class 'mdate'
e1 > e2

## S3 method for class 'mdate'
e1 <= e2

## S3 method for class 'mdate'
e1 >= e2
``````

### Arguments

 `x`, `y`, `e1`, `e2` `mdate` or other class objects

### Value

A logical vector the same length as the `mdate` passed.

### Functions

• `is_messydate()`: tests whether the object inherits the `mdate` class. If more rigorous validation is required, see `validate_messydate()`.

• `is_intersecting()`: tests whether there is any intersection between two messy dates, leveraging `intersect()`.

• `is_subset()`: tests whether one or more messy date can be found within a messy date range or set.

• `is_similar()`: tests whether two dates contain similar components. This can be useful for identifying dates that may be typos of one another.

• `is_precise()`: tests whether a date is precise (i.e. an 8 digit date). Non-precise dates contain markers that they are approximate (i.e. ~), unreliable (i.e. ?), are incomplete dates (i.e. year only), or date ranges and sets.

• `is_uncertain()`: tests whether a date is uncertain (i.e. contains ?).

• `is_approximate()`: tests whether a date is approximate (i.e. contains ~).

• ` < `: tests whether the dates in the first vector precede the dates in the second vector. Returns `NA` when the date order can't be determined.

• ` > `: tests whether the dates in the first vector succeed the dates in the second vector. Returns `NA` when the date order can't be determined.

• ` <= `: tests whether the dates in the first vector are equal to or precede the dates in the second vector. Returns `NA` when the date order can't be determined.

• ` >= `: tests whether the dates in the first vector are equal to or succeed the dates in the second vector. Returns `NA` when the date order can't be determined.

### Examples

``````is_messydate(as_messydate("2012-01-01"))
is_messydate(as.Date("2012-01-01"))
is_intersecting(as_messydate("2012-01"),
as_messydate("2012-01-01..2012-02-22"))
is_intersecting(as_messydate("2012-01"),
as_messydate("2012-02-01..2012-02-22"))
is_subset(as_messydate("2012-01-01"), as_messydate("2012-01"))
is_subset(as_messydate("2012-01-01..2012-01-03"), as_messydate("2012-01"))
is_subset(as_messydate("2012-01-01"), as_messydate("2012-02"))
is_similar(as_messydate("2012-06-02"), as_messydate("2012-02-06"))
is_similar(as_messydate("2012-06-22"), as_messydate("2012-02-06"))
is_precise(as_messydate(c("2012-06-02", "2012-06")))
is_uncertain(as_messydate(c("2012-06-02", "2012-06-02?")))
is_approximate(as_messydate(c("2012-06-02~", "2012-06-02")))
as_messydate("2012-06-02") > as.Date("2012-06-01") # TRUE
# 2012-06-XX could mean 2012-06-03, so unknown if it comes before 2012-06-02
as_messydate("2012-06-XX") < as.Date("2012-06-02") # NA
# But 2012-06-XX cannot be before 2012-06-01
as_messydate("2012-06-XX") >= as.Date("2012-06-01") # TRUE
``````

messydates documentation built on May 29, 2024, 2:16 a.m.