예제 #1
0
        /// <summary>
        /// Return the major solar term on or before a given date. This will be an
        /// integer from 1..12, with 1 corresponding to 330 degrees, 2 to 0 degrees,
        /// 3 to 30 degrees,..., and 12 to 300 degrees.
        /// </summary>
        ///
        /// <param name="days">days after January 1, 1970 0:00 Asia/Shanghai</param>
        private int MajorSolarTerm(int days)
        {
            astro.SetTime(DaysToMillis(days));

            // Compute (floor(solarLongitude / (pi/6)) + 2) % 12
            int term = ((int)Math.Floor(6 * astro.GetSunLongitude() / System.Math.PI) + 2) % 12;

            if (term < 1)
            {
                term += 12;
            }
            return(term);
        }
예제 #2
0
        public void TestSolarLongitude()
        {
            IBM.ICU.Util.GregorianCalendar gc = new IBM.ICU.Util.GregorianCalendar(new SimpleTimeZone(0,
                                                                                                      "UTC"));
            CalendarAstronomer astro = new CalendarAstronomer();

            double[][] tests =
            {
                new double[] { 1980, 7, 27, 0x0, 0x0, 2.166442986535465d,
                               2.2070499713207730d, 0.3355704075759270d },
                new double[] { 1988, 7, 27, 0x0, 0x0, 2.167484927693959d,
                               2.2081183335606176d, 0.3353093444275315d }
            };
            Logln("");
            for (int i = 0; i < tests.Length; i++)
            {
                gc.Clear();
                gc.Set((int)tests[i][0], (int)tests[i][1] - 1, (int)tests[i][2],
                       (int)tests[i][3], (int)tests[i][4]);

                astro.SetDate(gc.GetTime());

                double longitude = astro.GetSunLongitude();
                if (longitude != tests[i][5])
                {
                    if ((float)longitude == (float)tests[i][5])
                    {
                        Logln("longitude(" + longitude + ") !=  tests[i][5]("
                              + tests[i][5] + ") in double for test " + i);
                    }
                    else
                    {
                        Errln("FAIL: longitude(" + longitude + ") !=  tests[i][5]("
                              + tests[i][5] + ") for test " + i);
                    }
                }
                IBM.ICU.Impl.CalendarAstronomer.Equatorial result = astro.GetSunPosition();
                if (result.ascension != tests[i][6])
                {
                    if ((float)result.ascension == (float)tests[i][6])
                    {
                        Logln("result.ascension(" + result.ascension
                              + ") !=  tests[i][6](" + tests[i][6]
                              + ") in double for test " + i);
                    }
                    else
                    {
                        Errln("FAIL: result.ascension(" + result.ascension
                              + ") !=  tests[i][6](" + tests[i][6]
                              + ") for test " + i);
                    }
                }
                if (result.declination != tests[i][7])
                {
                    if ((float)result.declination == (float)tests[i][7])
                    {
                        Logln("result.declination(" + result.declination
                              + ") !=  tests[i][7](" + tests[i][7]
                              + ") in double for test " + i);
                    }
                    else
                    {
                        Errln("FAIL: result.declination(" + result.declination
                              + ") !=  tests[i][7](" + tests[i][7]
                              + ") for test " + i);
                    }
                }
            }
        }