getDateTimeLastMonth function

Pair<DateTime> getDateTimeLastMonth([
  1. DateTime? time
])

Returns start and end of last month, before current month, using time as reference.

time if null uses DateTime.now .

Implementation

Pair<DateTime> getDateTimeLastMonth([DateTime? time]) {
  time ??= DateTime.now();

  var prevMonth = getDateTimePreviousMonth(time.month, year: time.year);

  var y = prevMonth.year;
  var m = prevMonth.month;

  return Pair(
      getDateTimeDayStart(DateTime(y, m, 1, 0, 0, 0, 0, 0)),
      getDateTimeDayEnd(
          DateTime(y, m, getLastDayOfMonth(m, year: y), 23, 59, 59, 9, 0)));
}