getSpecialFestivals method

List<String> getSpecialFestivals(
  1. int year
)

获取每年的母亲节和父亲节和感恩节 特殊计算方式的节日

@param year 年 @return 获取每年的母亲节和父亲节、感恩节

Implementation

static List<String> getSpecialFestivals(int year) {
  List<String> festivals = new List(3);
  DateTime dateTime = new DateTime(year, 5, 1);

  //母亲节
  int week = (dateTime.weekday + 1) % 8;
  int startDiff = 7 - week + 1;
  if (startDiff == 7) {
    festivals[0] =
        dateToString(year, 5, startDiff + 1) + SPECIAL_FESTIVAL_STR[0];
  } else {
    festivals[0] =
        dateToString(year, 5, startDiff + 7 + 1) + SPECIAL_FESTIVAL_STR[0];
  }

  //父亲节
  dateTime = new DateTime(year, 6, 1);

  week = (dateTime.weekday + 1) % 8;
  startDiff = 7 - week + 1;
  if (startDiff == 7) {
    festivals[1] =
        dateToString(year, 6, startDiff + 7 + 1) + SPECIAL_FESTIVAL_STR[1];
  } else {
    festivals[1] = dateToString(year, 6, startDiff + 7 + 7 + 1) +
        SPECIAL_FESTIVAL_STR[1];
  }

  //感恩节
  dateTime = new DateTime(year, 11, 1);
  week = (dateTime.weekday + 1) % 8;

  startDiff = 7 - week + 1;
  if (startDiff <= 2) {
    festivals[2] =
        dateToString(year, 11, startDiff + 21 + 5) + SPECIAL_FESTIVAL_STR[2];
  } else {
    festivals[2] =
        dateToString(year, 11, startDiff + 14 + 5) + SPECIAL_FESTIVAL_STR[2];
  }
  return festivals;
}