firstDayInMonth method

DateTime firstDayInMonth([
  1. int firstDay = 1
])

当月第一天

firstDay - 每月起算日期,assert(firstDay > 0 && firstDay < 29)

Implementation

DateTime firstDayInMonth([int firstDay = 1]) {
  assert(firstDay > 0 && firstDay < 29);
  if (firstDay <= day) {
    return DateTime(year, month, firstDay);
  } else {
    return DateTime(year, month - 1,
        min(firstDay, DateTime(year, month).subtract(Duration(days: 1)).day));
  }
}