isYesterday method

  1. @useResult
bool isYesterday({
  1. DateTime? now,
})

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

Compares date-only (year/month/day), so the time component is irrelevant: 00:01 on the prior day still counts as yesterday. Pass now to pin the clock for deterministic tests.

Not DST-safe across a transition (see isTomorrow): the fixed 24h shift can land on the wrong calendar day on a "spring forward" / "fall back" local day.

Example:

final now = DateTime(2024, 3, 1);
DateTime(2024, 2, 29).isYesterday(now: now); // true (leap day)

Audited: 2026-06-12 11:26 EDT

Implementation

@useResult
bool isYesterday({DateTime? now}) {
  final DateTime yesterday = (now ?? DateTime.now()).subtract(const Duration(days: 1));

  return isSameDateOnly(yesterday);
}