of method
- DateTime date
override
Returns the period of the given date
considering the generator type.
Implementation
@override
TrimesterPeriod of(DateTime date) {
final octoberFirst = date.copyWith(month: DateTime.october, day: 1).date;
if (date.isBefore(octoberFirst)) {
final julyFirst = date.copyWith(month: DateTime.july, day: 1).date;
if (date.isBefore(julyFirst)) {
final aprilFirst = date.copyWith(month: DateTime.april, day: 1).date;
if (date.isBefore(aprilFirst)) {
return TrimesterPeriod(
start: date.firstDayOfYear.date,
end: aprilFirst.subtract(const Duration(microseconds: 1)),
);
}
return TrimesterPeriod(
start: aprilFirst,
end: julyFirst.subtract(const Duration(microseconds: 1)),
);
}
return TrimesterPeriod(
start: julyFirst,
end: octoberFirst.subtract(const Duration(microseconds: 1)),
);
}
return TrimesterPeriod(
start: octoberFirst,
end: date.lastDayOfYear.endOfDay,
);
}