예제 #1
0
        public void TestCoverage()
        {
            IBM.ICU.Util.GregorianCalendar cal = new IBM.ICU.Util.GregorianCalendar(1958, IBM.ICU.Util.Calendar.AUGUST, 15);
            DateTime           then            = cal.GetTime();
            CalendarAstronomer myastro         = new CalendarAstronomer(then);

            // Latitude: 34 degrees 05' North
            // Longitude: 118 degrees 22' West
            double             laLat = 34 + 5d / 60, laLong = 360 - (118 + 22d / 60);
            CalendarAstronomer myastro2 = new CalendarAstronomer(laLong, laLat);

            double eclLat  = laLat * System.Math.PI / 360;
            double eclLong = laLong * System.Math.PI / 360;

            IBM.ICU.Impl.CalendarAstronomer.Ecliptic ecl = new IBM.ICU.Impl.CalendarAstronomer.Ecliptic(eclLat, eclLong);
            Logln("ecliptic: " + ecl);

            CalendarAstronomer myastro3 = new CalendarAstronomer();

            myastro3.SetJulianDay((4713 + 2000) * 365.25d);

            CalendarAstronomer[] astronomers = { myastro, myastro2, myastro3,
                                                 myastro2 // check cache
            };

            for (int i = 0; i < astronomers.Length; ++i)
            {
                CalendarAstronomer astro = astronomers[i];

                Logln("astro: " + astro);
                Logln("   time: " + astro.GetTime());
                Logln("   date: " + astro.GetDate());
                Logln("   cent: " + astro.GetJulianCentury());
                Logln("   gw sidereal: " + astro.GetGreenwichSidereal());
                Logln("   loc sidereal: " + astro.GetLocalSidereal());
                Logln("   equ ecl: " + astro.EclipticToEquatorial(ecl));
                Logln("   equ long: " + astro.EclipticToEquatorial(eclLong));
                Logln("   horiz: " + astro.EclipticToHorizon(eclLong));
                Logln("   sunrise: " + DateUtil.DateFromJavaMillis(astro.GetSunRiseSet(true)));
                Logln("   sunset: " + DateUtil.DateFromJavaMillis(astro.GetSunRiseSet(false)));
                Logln("   moon phase: " + astro.GetMoonPhase());
                Logln("   moonrise: " + DateUtil.DateFromJavaMillis(astro.GetMoonRiseSet(true)));
                Logln("   moonset: " + DateUtil.DateFromJavaMillis(astro.GetMoonRiseSet(false)));
                Logln("   prev summer solstice: "
                      + DateUtil.DateFromJavaMillis(astro.GetSunTime(
                                                        IBM.ICU.Impl.CalendarAstronomer.SUMMER_SOLSTICE, false)));
                Logln("   next summer solstice: "
                      + DateUtil.DateFromJavaMillis(astro.GetSunTime(
                                                        IBM.ICU.Impl.CalendarAstronomer.SUMMER_SOLSTICE, true)));
                Logln("   prev full moon: "
                      + DateUtil.DateFromJavaMillis(astro.GetMoonTime(IBM.ICU.Impl.CalendarAstronomer.FULL_MOON,
                                                                      false)));
                Logln("   next full moon: "
                      + DateUtil.DateFromJavaMillis(astro.GetMoonTime(IBM.ICU.Impl.CalendarAstronomer.FULL_MOON,
                                                                      true)));
            }
        }
예제 #2
0
        /// <summary>
        /// Return the closest new moon to the given date, searching either forward
        /// or backward in time.
        /// </summary>
        ///
        /// <param name="days">days after January 1, 1970 0:00 Asia/Shanghai</param>
        /// <param name="after">if true, search for a new moon on or after the given date;otherwise, search for a new moon before it</param>
        /// <returns>days after January 1, 1970 0:00 Asia/Shanghai of the nearest new
        /// moon after or before <c>days</c></returns>
        private int NewMoonNear(int days, bool after)
        {
            astro.SetTime(DaysToMillis(days));
            long newMoon = astro.GetMoonTime(IBM.ICU.Impl.CalendarAstronomer.NEW_MOON, after);

            return(MillisToDays(newMoon));
        }