prevDay method

DateTime prevDay({
  1. bool startOfDay = true,
})

Returns the previous day.

This method calculates the day before the current DateTime object. It handles month and year changes correctly. startOfDay if true, returns the previous day at 00:00:00.

Implementation

DateTime prevDay({bool startOfDay = true}) {
  DateTime result = add(const Duration(days: -1));
  if (startOfDay) {
    result = DateTime(result.year, result.month, result.day);
  }
  return result;
}