getDaysInMonth<T> static method
Get days by month
Implementation
static List<T> getDaysInMonth<T>(int year, int month) {
const List<int> allMonthDays = <int>[31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
late final int daysInMonth;
if (month == DateTime.february) {
final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
daysInMonth = isLeapYear ? 29 : 28;
} else {
daysInMonth = allMonthDays[month - 1];
}
return List<T>.generate(daysInMonth, (index) {
if (T == DateTime) {
return DateTime(year, month, index + 1) as T;
} else {
return (index + 1) as T;
}
});
}