quarter method

dynamic quarter([
  1. int? val
])

Implementation

dynamic quarter([int? val]) {
  final int month = this.month();
  final currentQuarter = (month / 3).ceil();

  if (val == null) {
    return currentQuarter;
  } else {
    final quarter = val > 4
        ? 4
        : val < 1
            ? 1
            : val;
    final rem = month % 3;

    return currentQuarter == quarter
        ? clone()
        : this.month((rem == 0 ? 3 : rem) + (quarter - 1) * 3);
  }
}