コード例 #1
0
        public static int getNewMoonDay(int k, double timeZone)
        {
            double jd = VietCalendar.NewMoon(k);

            return(VietCalendar.INT((jd + (0.5
                                           + (timeZone / 24)))));
        }
コード例 #2
0
        public static double SunLongitudeAA98(double jdn)
        {
            double T = ((jdn - 2451545)
                        / 36525);
            //  Time in Julian centuries from 2000-01-01 12:00:00 GMT
            double T2 = (T * T);
            double dr = (PI / 180);
            //  degree to radian
            double M = (357.5291
                        + ((35999.0503 * T)
                           - ((0.0001559 * T2) - (4.8E-07
                                                  * (T * T2)))));
            //  mean anomaly, degree
            double L0 = (280.46645
                         + ((36000.76983 * T) + (0.0003032 * T2)));
            //  mean longitude, degree
            double DL = ((1.9146
                          - ((0.004817 * T) - (1.4E-05 * T2)))
                         * Math.Sin((dr * M)));

            DL = (DL
                  + (((0.019993 - (0.000101 * T))
                      * Math.Sin((dr * (2 * M)))) + (0.00029 * Math.Sin((dr * (3 * M))))));
            double L = (L0 + DL);

            //  true longitude, degree
            L = (L - (360 * VietCalendar.INT((L / 360))));
            //  Normalize to (0, 360)
            return(L);
        }
コード例 #3
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))));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
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
            });
        }