all.equal.mixtime-mt_time: Tolerant comparison of mixtime time values

all.equal.mixtime::mt_timeR Documentation

Tolerant comparison of mixtime time values

Description

vecvec::class_vecvec's all.equal() method (which mixtime inherits, since a mixtime vector is a vecvec) handles length/NA mismatches and groups elements by their underlying storage slot, then compares each group's raw values with all.equal(). That raw comparison has no notion of chronon: two elements that are == (e.g. days(1) and hours(24), or a yearmonth and an equivalent-instant yearweek) can end up stored with different chronons or magnitudes, and so are wrongly reported as unequal.

This method fixes that at the per-slot level: elements already == (which is chronon-aware, see mt_linear-compare/mt_duration-compare) count as equal outright; for the rest, the discrepancy is measured as the duration between them in their common chronon. A time point has no "typical magnitude" to scale a relative tolerance against the way a plain number does, so - unlike base::all.equal.numeric() - tolerance is always absolute, in (possibly fractional) chronon units.

Usage

## S3 method for class ''mixtime::mt_time''
all.equal(target, current, tolerance = sqrt(.Machine$double.eps), ...)

Arguments

target, current

mt_time vectors of the same length to compare (as passed down by vecvec::class_vecvec's all.equal()).

tolerance

Numeric tolerance, as an absolute number of target's chronon units. Defaults to sqrt(.Machine$double.eps), as for base::all.equal().

...

Ignored.

Value

TRUE if target and current are equal within tolerance, otherwise a string describing the discrepancy.

Examples

all.equal(yearmonth(0), yearmonth(0))
all.equal(yearmonth(0), yearmonth(1))
all.equal(days(1), hours(24))


mixtime documentation built on Nov. 18, 2026, 5:08 p.m.