HDateTimeRange.lastMonth constructor

HDateTimeRange.lastMonth(
  1. HTimeZone tz
)

Make a range which encompasses the previous month.

Implementation

factory HDateTimeRange.lastMonth(HTimeZone tz) {
  HDate today = HDate.today(tz);
  int year = today.year;
  int month = today.month;

  if (month == 1) {
    year--;
    month = 12;
  } else {
    month--;
  }

  HDate first = HDate(year, month, 1);
  HDate last = HDate(year, month, HDate.daysInMonth(year, month));
  return HDateTimeRange.datesAndTZ(first, last, tz);
}