isToday method

  1. @useResult
bool isToday({
  1. DateTime? now,
  2. bool ignoreYear = false,
})

Returns true if this DateTime matches the current date (today).

Pass now to override the current time (useful for testing). If ignoreYear is true, the year is excluded from the comparison.

Implementation

@useResult
bool isToday({DateTime? now, bool ignoreYear = false}) {
  final DateTime resolvedNow = now ?? DateTime.now();
  final bool isSameDayAndMonth = resolvedNow.day == day && resolvedNow.month == month;

  return isSameDayAndMonth && (ignoreYear || resolvedNow.year == year);
}