示例#1
0
        // 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))));
        }
示例#2
0
        // 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
            });
        }