/// <summary> /// Calculate MoonRise/Set for a given date /// If no at this day, return [nextday 0:00] /// </summary> /// <param name="CurDate"></param> /// <param name="lat"></param> /// <param name="lon"></param> /// <param name="timezoneoffset"></param> /// <param name="outMoonRise"></param> /// <param name="outMoonSet"></param> public static void getMoonTimesForDate(DateTime CurDate, double lat, double lon, double timezoneoffset, out DateTime outMoonRise, out DateTime outMoonSet) { DateTime CurSession = CurDate.AddHours(-12); //int Date = ; DateTime MoonRiseDT0, MoonSetDT0; DateTime MoonRiseDT1, MoonSetDT1; DateTime MoonRiseDT_1, MoonSetDT_1; MoonClass.calculateMoonTimes(CurSession.Year, CurSession.Month, CurSession.Day, lat, lon, timezoneoffset, out MoonRiseDT0, out MoonSetDT0); MoonClass.calculateMoonTimes(CurSession.AddDays(1).Year, CurSession.AddDays(1).Month, CurSession.AddDays(1).Day, lat, lon, timezoneoffset, out MoonRiseDT1, out MoonSetDT1); MoonClass.calculateMoonTimes(CurSession.AddDays(-1).Year, CurSession.AddDays(-1).Month, CurSession.AddDays(-1).Day, lat, lon, timezoneoffset, out MoonRiseDT_1, out MoonSetDT_1); DateTime MoonRise = DateTime.MinValue; DateTime MoonSet = DateTime.MinValue; if (MoonSetDT0.Hour < MoonRiseDT0.Hour && (MoonSetDT0.Day == CurSession.Day) && (MoonRiseDT0.Day == CurSession.Day)) { //Console.Write(" ..." + MoonSetDT0.ToString("MM-dd H:m")); //Console.Write(" " + MoonRiseDT0.ToString("MM-dd H:m") + "..."); MoonSet = MoonSetDT0; MoonRise = MoonRiseDT0; } else if ((MoonSetDT0.Day != CurSession.Day) || (MoonRiseDT0.Day != CurSession.Day)) { if (MoonSetDT0.Hour == 0) { //Console.Write("" + MoonRiseDT0.ToString("MM-dd H:m")); //Console.Write("..." + MoonSetDT1.ToString("MM-dd H:m") + ""); MoonSet = MoonSetDT1; MoonRise = MoonRiseDT0; } else if (MoonRiseDT0.Hour == 0) { //Console.Write("" + MoonRiseDT_1.ToString("MM-dd H:m")); //Console.Write("..." + MoonSetDT0.ToString("MM-dd H:m") + ""); MoonSet = MoonSetDT0; MoonRise = MoonRiseDT_1; } } else { //Console.Write("" + MoonRiseDT0.ToString("MM-dd H:m")); //Console.Write("..." + MoonSetDT0.ToString("MM-dd H:m") + ""); MoonSet = MoonSetDT0; MoonRise = MoonRiseDT0; } outMoonRise = MoonRise; outMoonSet = MoonSet; }
/// <summary> /// Return MoonRise/Set events durins current session ([thisday 12:00:01] - [nextday 11:59:59] /// If no found, return nearest NEXT event /// </summary> /// <param name="CurDate"></param> /// <param name="lat"></param> /// <param name="lon"></param> /// <param name="timezoneoffset"></param> /// <param name="outMoonRise"></param> /// <param name="outMoonSet"></param> public static void getMoonTimesForSession(DateTime CurDate, double lat, double lon, double timezoneoffset, out DateTime outMoonRise, out DateTime outMoonSet) { DateTime CurSession = CurDate.AddHours(-12); DateTime CurSessionStart = new DateTime(CurSession.Year, CurSession.Month, CurSession.Day, 12, 00, 01); DateTime CurSessionEnd = new DateTime(CurSession.AddDays(1).Year, CurSession.AddDays(1).Month, CurSession.AddDays(1).Day, 11, 59, 59); //int Date = ; DateTime MoonRiseDT0, MoonSetDT0; DateTime MoonRiseDT1, MoonSetDT1; DateTime MoonRiseDT2, MoonSetDT2; DateTime MoonRiseDT_1, MoonSetDT_1; MoonClass.calculateMoonTimes(CurSession.Year, CurSession.Month, CurSession.Day, lat, lon, timezoneoffset, out MoonRiseDT0, out MoonSetDT0); MoonClass.calculateMoonTimes(CurSession.AddDays(1).Year, CurSession.AddDays(1).Month, CurSession.AddDays(1).Day, lat, lon, timezoneoffset, out MoonRiseDT1, out MoonSetDT1); MoonClass.calculateMoonTimes(CurSession.AddDays(2).Year, CurSession.AddDays(2).Month, CurSession.AddDays(2).Day, lat, lon, timezoneoffset, out MoonRiseDT2, out MoonSetDT2); MoonClass.calculateMoonTimes(CurSession.AddDays(-1).Year, CurSession.AddDays(-1).Month, CurSession.AddDays(-1).Day, lat, lon, timezoneoffset, out MoonRiseDT_1, out MoonSetDT_1); DateTime MoonRise = new DateTime(); DateTime MoonSet = new DateTime(); //is there is MoonRise during session if (MoonRiseDT0 >= CurSessionStart && (MoonRiseDT0.Hour != 0 || MoonRiseDT0.Minute != 0)) { MoonRise = MoonRiseDT0; } else if (MoonRiseDT1.Hour != 0 || MoonRiseDT1.Minute != 0) { MoonRise = MoonRiseDT1; } else { MoonRise = MoonRiseDT2; } //is there is MoonSet during session if (MoonSetDT0 >= CurSessionStart && (MoonSetDT0.Hour != 0 || MoonSetDT0.Minute != 0)) { MoonSet = MoonSetDT0; } else if (MoonSetDT1.Hour != 0 || MoonSetDT1.Minute != 0) { MoonSet = MoonSetDT1; } else { MoonSet = MoonSetDT2; } outMoonRise = MoonRise; outMoonSet = MoonSet; }
/************************************************************************************************************ * * Moon Calcs * ************************************************************************************************************/ /* * ORDINARY FORM (for a given date) */ public static void getMoonTimesForDate(out DateTime outMoonRise, out DateTime outMoonSet) { MoonClass.calculateMoonTimes(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Latitude, Longitude, SiteTimeZone, out outMoonRise, out outMoonSet); }