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))); } }
// ------------------------------------------------------------------ // Astronomical computations // ------------------------------------------------------------------ /// <summary> /// Return the major solar term on or after December 15 of the given /// Gregorian year, that is, the winter solstice of the given year. /// Computations are relative to Asia/Shanghai time zone. /// </summary> /// /// <param name="gyear">a Gregorian year</param> /// <returns>days after January 1, 1970 0:00 Asia/Shanghai of the winter /// solstice of the given year</returns> private int WinterSolstice(int gyear) { long cacheValue = winterSolsticeCache.Get(gyear); if (cacheValue == IBM.ICU.Impl.CalendarCache.EMPTY) { // In books December 15 is used, but it fails for some years // using our algorithms, e.g.: 1298 1391 1492 1553 1560. That // is, winterSolstice(1298) starts search at Dec 14 08:00:00 // PST 1298 with a final result of Dec 14 10:31:59 PST 1299. long ms = DaysToMillis(ComputeGregorianMonthStart(gyear, IBM.ICU.Util.Calendar.DECEMBER) + 1 - IBM.ICU.Util.Calendar.EPOCH_JULIAN_DAY); astro.SetTime(ms); // Winter solstice is 270 degrees solar longitude aka Dongzhi long solarLong = astro.GetSunTime( IBM.ICU.Impl.CalendarAstronomer.WINTER_SOLSTICE, true); cacheValue = MillisToDays(solarLong); winterSolsticeCache.Put(gyear, cacheValue); } return((int)cacheValue); }