RelativeTimeUtils extension

Calendar-day predicates and a descriptive relative-time formatter on DateTime.

The four predicates (isTomorrow, isYesterday, isOlderThanToday, isOlderThanYesterday) and relativeTime each accept an optional now reference (defaulting to DateTime.now) so callers can pin a deterministic clock in tests instead of mutating global time.

Note the two predicate families treat time zones differently and this is intentional: isTomorrow / isYesterday compare on calendar fields via DateTimeComparisonExtensions.isSameDateOnly (so a UTC receiver and a local now are compared by their displayed year/month/day, ignoring the offset), while isOlderThanToday / isOlderThanYesterday use the instant comparison DateTime.isBefore (which is offset-aware). Mixing UTC and local across the two families therefore yields different answers — pass a now in the same zone as the receiver to keep results unambiguous.

on

Methods

isOlderThanToday({DateTime? now}) bool

Available on DateTime, provided by the RelativeTimeUtils extension

Returns true if this DateTime is strictly before the start of today (midnight at the beginning of now's calendar day).
isOlderThanYesterday({DateTime? now}) bool

Available on DateTime, provided by the RelativeTimeUtils extension

Returns true if this DateTime is strictly before the start of yesterday (midnight at the beginning of the day before now).
isTomorrow({DateTime? now}) bool

Available on DateTime, provided by the RelativeTimeUtils extension

Returns true if this DateTime is the calendar day after now.
isYesterday({DateTime? now}) bool

Available on DateTime, provided by the RelativeTimeUtils extension

Returns true if this DateTime is the calendar day before now.