public void TestNoSunrise() { var TestDate = new DateTime(2018, 6, 21); var Sunrise = SunSetRiseLib.SunriseAt(MurmanskLat, MurmanskLong, TestDate, 3); Assert.IsNull(Sunrise); }
public void TestPrevDaySunrise() { var TestDate = new DateTime(2018, 5, 21); var Expected = TestDate.DayOfYear - 1; var Sunrise = SunSetRiseLib.SunriseAt(MurmanskLat, MurmanskLong, TestDate, 0); //Using UTC Assert.AreEqual(Expected, NotNullable(Sunrise).DayOfYear); }
public void TestAccuracy() { var TestDate = new DateTime(2018, 12, 25); var Expected = 24; var Sunrise = SunSetRiseLib.SunriseAt(NewYorkLat, NewYorkLong, TestDate); Assert.AreEqual(Expected, NotNullable(Sunrise).Second); }
public void TestRounding() { var TestDate = new DateTime(2018, 12, 26); var Expected = TestDate.AddHours(12).AddMinutes(18).AddSeconds(46); //7:18:46 local, 12:18:46 UTC var Sunrise = SunSetRiseLib.SunriseAt(NewYorkLat, NewYorkLong, TestDate, 0); Assert.IsTrue(Math.Abs((Expected - NotNullable(Sunrise)).TotalSeconds) < 30, string.Format("Expected: 12:18:46 or 12:19:00 (UTC), Actual: {0:h:mm:ss}", Sunrise)); }
public void TestWinter() { var TestDate = new DateTime(2018, 12, 21); var Expected = 12; //7am local, 12pm UTC var Sunrise = SunSetRiseLib.SunriseAt(NewYorkLat, NewYorkLong, TestDate); Assert.AreEqual(Expected, NotNullable(Sunrise).ToUniversalTime().Hour); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); var services = new ServiceCollection(); services.AddDbContext <ChronicityContext>(options => options.UseSqlServer(configuration["Connection"])); services.AddTransient <TimeLineService>(); var service = services.BuildServiceProvider().GetService <TimeLineService>(); if (args[0] == "reprocess") { service.RegisterReaction(new FeederRefill()); } if (args[0] == "sunset") { var latitude = 43.038902; var longitude = -87.906471; var utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours; var endDate = new DateTime(2025, 1, 1); var startDate = new DateTime(2018, 1, 1); var currentDate = startDate; while (currentDate < endDate) { Console.WriteLine("Sunrise: " + SunSetRiseLib.SunriseAt(latitude, longitude, currentDate, utcOffset)); Console.WriteLine("SunSet: " + SunSetRiseLib.SunsetAt(latitude, longitude, currentDate, utcOffset)); service.RegisterEvent(new Chronicity.Core.Timeline.NewEvent() { Entities = new string[] { "Milwaukee" }, On = SunSetRiseLib.SunriseAt(latitude, longitude, currentDate, utcOffset).ToString(), Type = "Sunrise" }); service.RegisterEvent(new Chronicity.Core.Timeline.NewEvent() { Entities = new string[] { "Milwaukee" }, On = SunSetRiseLib.SunsetAt(latitude, longitude, currentDate, utcOffset).ToString(), Type = "Sunset" }); currentDate = currentDate.AddDays(1); } } }