endOfQuarter property

DateTime get endOfQuarter

Return the end of quarter for this date. The result will be in the local timezone.

Implementation

DateTime get endOfQuarter {
  // Calculate quarter (1-4)
  final quarter = (month - 1) ~/ 3 + 1;
  // Last month of the quarter
  final lastMonthOfQuarter = quarter * 3;
  // First day of the next month after the quarter
  final firstDayAfterQuarter = DateTime(year, lastMonthOfQuarter + 1, 1);
  // Subtract 1 microsecond to get end of the last day of the quarter
  return firstDayAfterQuarter.subMicroseconds(1);
}