getNineStar method

NineStar getNineStar()

Implementation

NineStar getNineStar() {
  //顺逆
  String solarYmd = _lunar!.getSolar().toYmd();
  Map<String, Solar> jieQi = _lunar!.getJieQiTable();
  bool asc = false;
  if (solarYmd.compareTo(jieQi['冬至']!.toYmd()) >= 0 &&
      solarYmd.compareTo(jieQi['夏至']!.toYmd()) < 0) {
    asc = true;
  }
  int start = asc ? 7 : 3;
  String dayZhi = _lunar!.getDayZhi();
  if ('子午卯酉'.contains(dayZhi)) {
    start = asc ? 1 : 9;
  } else if ('辰戌丑未'.contains(dayZhi)) {
    start = asc ? 4 : 6;
  }
  int index = asc ? start + _zhiIndex - 1 : start - _zhiIndex - 1;
  if (index > 8) {
    index -= 9;
  }
  if (index < 0) {
    index += 9;
  }
  return NineStar(index);
}