convertLunarDateToSolarDate static method

DateTime? convertLunarDateToSolarDate(
  1. LunarDateTime lunarDateTime, [
  2. int timeZone = 7
])

Convert lunar date to the corresponding solar date.

Implementation

static DateTime? convertLunarDateToSolarDate(
  LunarDateTime lunarDateTime, [
  int timeZone = 7,
]) {
  const double juliusDaysIn1900 = 2415021.076998695;
  const double newMoonCycle = 29.530588853;
  const int daysInYear = 365;
  int k, a11, b11, off, leapOff, leapMonth, monthStart;
  if (lunarDateTime.month < 11) {
    a11 = _temp.getLunarMonth11(lunarDateTime.year - 1, timeZone);
    b11 = _temp.getLunarMonth11(lunarDateTime.year, timeZone);
  } else {
    a11 = _temp.getLunarMonth11(lunarDateTime.year, timeZone);
    b11 = _temp.getLunarMonth11(lunarDateTime.year + 1, timeZone);
  }
  k = (0.5 + (a11 - juliusDaysIn1900) / newMoonCycle).floor();
  off = lunarDateTime.month - 11;
  if (off < 0) {
    off += 12;
  }
  if (b11 - a11 > daysInYear) {
    leapOff = _temp.getLeapMonthOffset(a11, timeZone);
    leapMonth = leapOff - 2;
    if (leapMonth < 0) {
      leapMonth += 12;
    }
    if (lunarDateTime.isLeap && (lunarDateTime.month != leapMonth)) {
      return null;
    } else if (lunarDateTime.isLeap || (off >= leapOff)) {
      off += 1;
    }
  }
  monthStart = _temp.getNewMoonDay(k + off, timeZone);
  return convertJulianDayToSolarDate(monthStart + lunarDateTime.day - 1);
}