isToday method

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

Checks if the current DateTime matches the current date (today).

Args: now (DateTime?): The current date and time. Defaults to null (uses the actual current date and time). ignoreYear (bool): If true, the year is ignored in the comparison. Defaults to false.

Returns: bool: True if the DateTime matches the current date, false otherwise.

Implementation

bool isToday({DateTime? now, bool ignoreYear = false}) {
  now ??= DateTime.now();

  // https://stackoverflow.com/questions/54391477/check-if-datetime-variable-is-today-tomorrow-or-yesterday
  return now.day == day && now.month == month && (ignoreYear || now.year == year);
}