computeStart method

void computeStart(
  1. int sect
)

Implementation

void computeStart(int sect) {
  // 上节
  JieQi prev = _lunar!.getPrevJie();
  // 下节
  JieQi next = _lunar!.getNextJie();
  // 出生日期
  Solar current = _lunar!.getSolar();
  // 阳男阴女顺推,阴男阳女逆推
  Solar start = _forward ? current : prev.getSolar();
  Solar end = _forward ? next.getSolar() : current;

  int year;
  int month;
  int day;
  int hour = 0;

  if (2 == sect) {
    int minutes = end.subtractMinute(start);
    year = (minutes / 4320).floor();
    minutes -= year * 4320;
    month = (minutes / 360).floor();
    minutes -= month * 360;
    day = (minutes / 12).floor();
    minutes -= day * 12;
    hour = minutes * 2;
  } else {
    int endTimeZhiIndex = (end.getHour() == 23)
        ? 11
        : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
    int startTimeZhiIndex = (start.getHour() == 23)
        ? 11
        : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
    // 时辰差
    int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
    // 天数差
    int dayDiff = end.subtract(start);
    if (hourDiff < 0) {
      hourDiff += 12;
      dayDiff--;
    }
    int monthDiff = (hourDiff * 10 / 30).floor();
    month = dayDiff * 4 + monthDiff;
    day = hourDiff * 10 - monthDiff * 30;
    year = (month / 12).floor();
    month = month - year * 12;
  }
  _startYear = year;
  _startMonth = month;
  _startDay = day;
  _startHour = hour;
}