// Am lich sang Duong lich public static int[] convertLunar2Solar(int lunarDay, int lunarMonth, int lunarYear, int lunarLeap, double timeZone) { int b11; int a11; if ((lunarMonth < 11)) { a11 = VietCalendar.getLunarMonth11((lunarYear - 1), timeZone); b11 = VietCalendar.getLunarMonth11(lunarYear, timeZone); } else { a11 = VietCalendar.getLunarMonth11(lunarYear, timeZone); b11 = VietCalendar.getLunarMonth11((lunarYear + 1), timeZone); } int k = VietCalendar.INT((0.5 + ((a11 - 2415021.0769986948) / 29.530588853))); int off = (lunarMonth - 11); if ((off < 0)) { off += 12; } if (((b11 - a11) > 365)) { int leapOff = VietCalendar.getLeapMonthOffset(a11, timeZone); int leapMonth = (leapOff - 2); if ((leapMonth < 0)) { leapMonth += 12; } if (((lunarLeap != 0) && (lunarMonth != leapMonth))) { // System.out.println("Invalid input!"); return(new int[] { 0, 0, 0 }); } else if (((lunarLeap != 0) || (off >= leapOff))) { off++; } } int monthStart = VietCalendar.getNewMoonDay((k + off), timeZone); return(VietCalendar.jdToDate((monthStart + (lunarDay - 1)))); }
public static int getLunarMonth11(int yy, double timeZone) { double off = (VietCalendar.jdFromDate(31, 12, yy) - 2415021.0769986948); int k = VietCalendar.INT((off / 29.530588853)); int nm = VietCalendar.getNewMoonDay(k, timeZone); int sunLong = VietCalendar.INT((VietCalendar.getSunLongitude(nm, timeZone) / 30)); if ((sunLong >= 9)) { nm = VietCalendar.getNewMoonDay((k - 1), timeZone); } return(nm); }
public static int getLeapMonthOffset(int a11, double timeZone) { int k = VietCalendar.INT((0.5 + ((a11 - 2415021.0769986948) / 29.530588853))); int last; // Month 11 contains point of sun longutide 3*PI/2 (December solstice) int i = 1; // We start with the month following lunar month 11 int arc = VietCalendar.INT((VietCalendar.getSunLongitude(VietCalendar.getNewMoonDay((k + i), timeZone), timeZone) / 30)); do { last = arc; i++; arc = VietCalendar.INT((VietCalendar.getSunLongitude(VietCalendar.getNewMoonDay((k + i), timeZone), timeZone) / 30)); } while (((arc != last) && (i < 14))); return(i - 1); }
// Duong lich sang Am lich public static int[] convertSolar2Lunar(int dd, int mm, int yy, double timeZone) { int lunarLeap; int lunarDay; int lunarMonth; int lunarYear; int dayNumber = VietCalendar.jdFromDate(dd, mm, yy); int k = VietCalendar.INT(((dayNumber - 2415021.0769986948) / 29.530588853)); int monthStart = VietCalendar.getNewMoonDay((k + 1), timeZone); if ((monthStart > dayNumber)) { monthStart = VietCalendar.getNewMoonDay(k, timeZone); } int a11 = VietCalendar.getLunarMonth11(yy, timeZone); int b11 = a11; if ((a11 >= monthStart)) { lunarYear = yy; a11 = VietCalendar.getLunarMonth11((yy - 1), timeZone); } else { lunarYear = (yy + 1); b11 = VietCalendar.getLunarMonth11((yy + 1), timeZone); } lunarDay = ((dayNumber - monthStart) + 1); int diff = VietCalendar.INT(((monthStart - a11) / 29)); lunarLeap = 0; lunarMonth = (diff + 11); if (((b11 - a11) > 365)) { int leapMonthDiff = VietCalendar.getLeapMonthOffset(a11, timeZone); if ((diff >= leapMonthDiff)) { lunarMonth = (diff + 10); if ((diff == leapMonthDiff)) { lunarLeap = 1; } } } if ((lunarMonth > 12)) { lunarMonth = (lunarMonth - 12); } if (((lunarMonth >= 11) && (diff < 4))) { lunarYear--; } return(new int[] { lunarDay, lunarMonth, lunarYear, lunarLeap }); }