isDateAfterToday method

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

Returns true if this date is strictly after today (i.e., tomorrow or later).

"Today" is now's calendar day in now's own kind: a UTC now ends the day at UTC midnight, a local one at local midnight. This value is compared against that boundary as an instant, whatever its own kind.

Pass now to override the current time (useful for testing).

Example:

final now = DateTime.utc(2026, 6, 15, 12);
DateTime.utc(2026, 6, 16).isDateAfterToday(now: now); // true
DateTime.utc(2026, 6, 15, 23).isDateAfterToday(now: now); // false

Audited: 2026-06-12 11:26 EDT

Implementation

@useResult
bool isDateAfterToday({DateTime? now}) {
  final DateTime currentNow = now ?? DateTime.now();

  // Bug fix: truncating with the plain `DateTime(...)` constructor turned a
  // UTC `now` into LOCAL midnight of its UTC date, moving the end of today by
  // the host offset. Truncate in `now`'s kind instead.
  final DateTime startOfToday = currentNow.startOfDayInKind;
  // Bug fix: `startOfToday.add(Duration(days: 1))` is 24 elapsed hours, which
  // is 23:00 today on a 25-hour fall-back day (so 23:30 today counted as
  // "after today") and 01:00 tomorrow after a 23-hour day (so 00:30 tomorrow
  // did not). Tomorrow's local midnight comes from calendar fields instead.
  // Re-truncated after the step: where a zone skips today's midnight,
  // startOfToday is 01:00 and that hour would otherwise move the boundary to
  // 01:00 tomorrow.
  final DateTime startOfTomorrow = startOfToday.addCalendarDays(1).startOfDayInKind;
  final DateTime endOfToday = startOfTomorrow.subtract(_oneMicrosecond);

  return isAfter(endOfToday);
}