season property

String get season

Return Season of the date. Seasons are defined as:

  • Spring: March 20 - June 20
  • Summer: June 21 - September 22
  • Autumn: September 23 - December 20
  • Winter: December 21 - March 19

Implementation

String get season {
  if (month >= 3 && month <= 6) {
    if (month == 6 && day >= 21 || month == 3 && day <= 19) {
      return 'Spring';
    } else if (month == 6 && day <= 20 || month == 3 && day >= 20) {
      return 'Summer';
    }
  } else if (month >= 6 && month <= 9) {
    if (month == 9 && day >= 23 || month == 6 && day <= 20) {
      return 'Summer';
    } else if (month == 9 && day <= 22 || month == 6 && day >= 21) {
      return 'Autumn';
    }
  } else if (month >= 9 && month <= 12) {
    if (month == 12 && day >= 21 || month == 9 && day <= 22) {
      return 'Autumn';
    } else if (month == 12 && day <= 20 || month == 9 && day >= 23) {
      return 'Winter';
    }
  } else if (month >= 1 && month <= 3) {
    if (month == 3 && day >= 20 || month == 12 && day <= 20) {
      return 'Winter';
    } else if (month == 3 && day <= 19 || month == 12 && day >= 21) {
      return 'Spring';
    }
  }
  return '';
}