private ZonedDateTime CalculateSunrise(bool isSunrise, ZonedDateTime date, Coordinates location, DateTimeZone timeZone) { double julianDate = date.Date.AtMidnight().InUtc().ToInstant().ToJulianDate(); double days = julianDate - 2451545.0d + 0.0008d; double meanSolarNoon = this.CalculateMeanSolarNoon(days, location.Longitude); double solarMeanAnomaly = this.CalculateSolarMeanAnomaly(meanSolarNoon); double center = this.CalculateEquationOfTheCenter(solarMeanAnomaly); double eclipticLongitude = this.CalculateEclipticLongitude(solarMeanAnomaly, center); double solarTransit = this.CalculateSolarTransit(meanSolarNoon, solarMeanAnomaly, eclipticLongitude); double sunDeclination = this.CalculateDeclinationOfSun(eclipticLongitude); double hourAngle = this.CalculateHourAngle(location.Latitude, sunDeclination); double adjustment = hourAngle / 360d; double julianSunDate = (isSunrise ? -1 : 1) * adjustment + solarTransit; Instant gregorianInstant = Instant.FromJulianDate(julianSunDate); return(new ZonedDateTime(gregorianInstant, timeZone)); }
public void NullableIntervalRoundTripTest() { var interval = new Interval(start: Instant.FromJulianDate(0), end: Instant.FromUnixTimeMilliseconds(0)); Assert.That(interval.HasStart); Assert.That(interval.HasEnd); RoundTripTest((Interval?)interval); }
public void IntervalWithStartAndEndRoundTripTest() { var interval = new Interval(start: Instant.FromJulianDate(0), end: Instant.FromUnixTimeMilliseconds(0)); Assert.That(interval.HasStart); Assert.That(interval.HasEnd); RoundTripTest(interval); }
public static Instant GetDateTime(this Quote self) { if (string.IsNullOrEmpty(self.DateTime)) { return(Instant.FromJulianDate(0)); } return(InstantPattern.ExtendedIso.Parse(self.DateTime).Value); }
public void JulianDateConversions(double julianDate, int year, int month, int day, int hour, int minute, int second) { // When dealing with floating point binary data, if we're accurate to 50 milliseconds, that's fine... // (0.000001 days = ~86ms, as a guide to the scale involved...) Instant actual = Instant.FromJulianDate(julianDate); Instant expected = new LocalDateTime(year, month, day, hour, minute, second, CalendarSystem.Julian).InUtc().ToInstant(); Assert.AreEqual(expected.ToUnixTimeMilliseconds(), actual.ToUnixTimeMilliseconds(), 50, "Expected {0}, was {1}", expected, actual); Assert.AreEqual(julianDate, expected.ToJulianDate(), 0.000001); }
public virtual void SupportsFromJulianDate(TestEntity <double> testEntity) { AddToDatabase(testEntity); var minimum = Instant.FromJulianDate(testEntity.TestProperty); ExecuteWithQueryable <TestEntity <double> >(q => { var foundEntities = q.Where(x => Instant.FromJulianDate(x.TestProperty) == minimum).ToList(); }); }
public static void LoggingExamples(bool withNodaTimeDeconstruction) { var lc = new LoggerConfiguration(); if (withNodaTimeDeconstruction) { lc = lc.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); } var logger = lc .WriteTo.Console(outputTemplate: "{Instant} {Message:lj}{NewLine}") .CreateLogger(); var localDateTime = LocalDateTime.FromDateTime(DateTime.Now); logger.WithCurrentInstant().Information("DateTimeZone {@DateTimeZone}", DateTimeZoneProviders.Tzdb["Europe/London"]); logger.WithCurrentInstant().Information("Duration {@Duration}", Duration.FromMinutes(69)); logger.WithCurrentInstant().Information("Interval {@Interval}", new Interval(start: Instant.FromJulianDate(0), end: Instant.FromUnixTimeMilliseconds(0))); logger.WithCurrentInstant().Information("LocalDate {@LocalDate}", localDateTime.Date); logger.WithCurrentInstant().Information("LocalDateTime {@LocalDateTime}", localDateTime); logger.WithCurrentInstant().Information("LocalTime {@LocalTime}", localDateTime.TimeOfDay); logger.WithCurrentInstant().Information("OffsetDate {@OffsetDate}", new OffsetDate(localDateTime.Date, Offset.FromHours(10))); logger.WithCurrentInstant().Information("OffsetDateTime {@OffsetDateTime}", new OffsetDateTime(localDateTime, Offset.FromHours(10))); logger.WithCurrentInstant().Information("OffsetTime {@OffsetTime}", new OffsetTime(localDateTime.TimeOfDay, Offset.FromHours(10))); logger.WithCurrentInstant().Information("Period {@Period}", Period.FromNanoseconds(1234567890)); logger.WithCurrentInstant().Information("ZonedDateTime {@ZonedDateTime}", localDateTime.InZoneLeniently(DateTimeZoneProviders.Tzdb["Australia/Canberra"])); if (withNodaTimeDeconstruction) { Console.WriteLine(); } // Note that for the following types Serilog.NodaTime overrides the deconstruction setting by declaring that the type should always be considered a Scalar, as the extra information within these structures is not useful in a log nor necessary to round-trip back to a NodaTime type: logger.WithCurrentInstant().Information("CalendarSystem {@CalendarSystem}", CalendarSystem.Julian); logger.WithCurrentInstant().Information("Offset {@Offset}", Offset.FromHoursAndMinutes(1, 2)); logger.Dispose(); }