public void PlusHours_CrossingDayBoundary() { LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8); LocalDateTime expected = new LocalDateTime(2011, 4, 3, 8, 15, 8); Assert.AreEqual(expected, start.PlusHours(20)); Assert.AreEqual(start, start.PlusHours(20).PlusHours(-20)); }
public void PlusHours_CrossingYearBoundary() { // Christmas day + 10 days and 1 hour LocalDateTime start = new LocalDateTime(2011, 12, 25, 12, 15, 8); LocalDateTime expected = new LocalDateTime(2012, 1, 4, 13, 15, 8); Assert.AreEqual(expected, start.PlusHours(241)); Assert.AreEqual(start, start.PlusHours(241).PlusHours(-241)); }
public void PlusHours_Simple() { LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8); LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 14, 15, 8); LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 10, 15, 8); Assert.AreEqual(expectedForward, start.PlusHours(2)); Assert.AreEqual(expectedBackward, start.PlusHours(-2)); }
public void GetSunrise_GetSunset_WithVariousParameters_ReturnsExpectedSunriseTime(int year, int month, int day, int expectedSunriseHour, int expectedSunriseMinutes, int expectedSunsetHour, int expectedSunsetMinutes, double latitude, double longitude, string timeZone) { var subject = this.GetEnvironment().Subject; var date = new LocalDateTime(year, month, day, 0, 0).InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull(timeZone)); var location = new Coordinates(latitude, longitude); var sunrise = subject.GetSunrise(date, location); var sunset = subject.GetSunset(date, location); var expectedSunrise = date.PlusHours(expectedSunriseHour).PlusMinutes(expectedSunriseMinutes); var expectedSunset = date.PlusHours(expectedSunsetHour).PlusMinutes(expectedSunsetMinutes); Assert.That(sunrise.ToInstant().ToUnixTimeSeconds(), Is.EqualTo(expectedSunrise.ToInstant().ToUnixTimeSeconds()).Within(60), "Expected sunrise {0}, received {1}", expectedSunrise, sunrise); Assert.That(sunset.ToInstant().ToUnixTimeSeconds(), Is.EqualTo(expectedSunset.ToInstant().ToUnixTimeSeconds()).Within(60), "Expected sunset {0}, received {1}", expectedSunset, sunset); }
public void Can_Write_And_Read_LocalDateTime_Stored_As_DateTime2() { var timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); LocalDateTime startLocalDateTime = TestClock.Now.InZone(timeZone).LocalDateTime; LocalDateTime finishLocalDateTime = startLocalDateTime.PlusHours(1); var testEvent = new LocalDateTimeTestEntity { Description = "Can_Write_And_Read_LocalDateTime_Stored_As_DateTime2", StartLocalDateTime = startLocalDateTime, FinishLocalDateTime = finishLocalDateTime }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(testEvent); transaction.Commit(); } LocalDateTimeTestEntity retrievedEvent; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { retrievedEvent = session.Get <LocalDateTimeTestEntity>(testEvent.Id); transaction.Commit(); } Assert.That(retrievedEvent.StartLocalDateTime, Is.EqualTo(testEvent.StartLocalDateTime)); Assert.That(retrievedEvent.FinishLocalDateTime, Is.EqualTo(testEvent.FinishLocalDateTime)); Assert.That(retrievedEvent, Is.EqualTo(testEvent)); }
public LocalDateTime?ComputeNextExecutionTime(LocalDateTime lastExecutionTime) { var currentHourExecutionTime = new LocalDateTime(lastExecutionTime.Year, lastExecutionTime.Month, lastExecutionTime.Day, lastExecutionTime.Hour, this._minuteOfHour); if (lastExecutionTime < currentHourExecutionTime) { return(currentHourExecutionTime); } return(currentHourExecutionTime.PlusHours(1)); }
public static IEnumerable <LocalDateTime> HourlyLocal(LocalDateTimeRange range) { LocalDateTime c = range.Start; while (c < range.End) { yield return(c); c = c.PlusHours(1); } }
public void Addition_Duration() { const int minutes = 23; const int hours = 3; const int milliseconds = 40000; const long seconds = 321; const long nanoseconds = 12345; const long ticks = 5432112345; // Test all three approaches... not bothering to check a different calendar, // but we'll use two different offsets. OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1)); Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9); OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1)); Assert.AreEqual(expected, start + duration); Assert.AreEqual(expected, start.Plus(duration)); Assert.AreEqual(expected, OffsetDateTime.Add(start, duration)); Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours)); Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours)); Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes)); Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes)); Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds)); Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds)); Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds)); Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds)); Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks)); Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks)); Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds)); Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds)); }
public void DayOfWeek_AroundEpoch() { // Test about couple of months around the Unix epoch. If that works, I'm confident the rest will. LocalDateTime dateTime = new LocalDateTime(1969, 12, 1, 0, 0); for (int i = 0; i < 60; i++) { // Check once per hour of the day, just in case something's messed up based on the time of day. for (int hour = 0; hour < 24; hour++) { Assert.AreEqual(BclConversions.ToIsoDayOfWeek(dateTime.ToDateTimeUnspecified().DayOfWeek), dateTime.DayOfWeek); dateTime = dateTime.PlusHours(1); } } }
public void Can_Query_By_GreaterThan_LocalDateTime_Stored_As_DateTime2() { var timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); LocalDateTime startLocalDateTime = TestClock.Now.InZone(timeZone).LocalDateTime.Plus(Period.FromHours(1)); LocalDateTime finishLocalDateTime = startLocalDateTime.PlusHours(3); var testEvent = new LocalDateTimeTestEntity { Description = "Can_Query_By_GreaterThan_LocalDateTime_Stored_As_DateTime2", StartLocalDateTime = startLocalDateTime, FinishLocalDateTime = finishLocalDateTime }; using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Save(testEvent); transaction.Commit(); } LocalDateTime beforeLocalDateTime = startLocalDateTime.Minus(Period.FromHours(1)); using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var query = session.Query <LocalDateTimeTestEntity>() .Where(x => x.Id == testEvent.Id && x.StartLocalDateTime > beforeLocalDateTime); var retrievedEvent = query.SingleOrDefault(); transaction.Commit(); Assert.That(testEvent, Is.Not.Null); Assert.That(testEvent, Is.EqualTo(retrievedEvent)); } using (ISession session = SessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { var query = session.Query <LocalDateTimeTestEntity>() .Where(x => x.Id == testEvent.Id && x.StartLocalDateTime > beforeLocalDateTime && x.FinishLocalDateTime >= finishLocalDateTime); var retrievedEvent = query.SingleOrDefault(); transaction.Commit(); Assert.That(testEvent, Is.Not.Null); Assert.That(testEvent, Is.EqualTo(retrievedEvent)); } }
public async Task SimpleWeights() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await TestUtilities.RemoveAllThingsAsync <Weight>(thingClient, record.Id); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; List <Weight> weightList = new List <Weight>(); weightList.Add(new Weight( new HealthServiceDateTime(nowLocal.PlusHours(-1)), new WeightValue(81, new DisplayValue(81, "KG", "kg")))); weightList.Add(new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(85, new DisplayValue(187, "LBS", "lb")))); await thingClient.CreateNewThingsAsync <Weight>(record.Id, weightList); IReadOnlyCollection <Weight> retrievedWeights = await thingClient.GetThingsAsync <Weight>(record.Id); Assert.AreEqual(2, retrievedWeights.Count); var retrievedWeightsList = retrievedWeights.ToList(); Weight firstWeight = retrievedWeightsList[1]; Weight secondWeight = retrievedWeightsList[0]; Assert.AreEqual(81, firstWeight.Value.Kilograms); Assert.AreEqual(81, firstWeight.Value.DisplayValue.Value); Assert.AreEqual("KG", firstWeight.Value.DisplayValue.Units); Assert.AreEqual("kg", firstWeight.Value.DisplayValue.UnitsCode); Assert.AreEqual(85, secondWeight.Value.Kilograms); Assert.AreEqual(187, secondWeight.Value.DisplayValue.Value); Assert.AreEqual("LBS", secondWeight.Value.DisplayValue.Units); Assert.AreEqual("lb", secondWeight.Value.DisplayValue.UnitsCode); }
public static DateTime AdjustTzTimeToLocalTime(LocalDateTime theirDateTime, DateTimeZone?theirTimeZone) { try { return(theirTimeZone is null ? theirDateTime.ToDateTimeUnspecified() : theirDateTime.InZoneLeniently(theirTimeZone).ToDateTimeUtc().ToLocalTime()); } catch (ArgumentException) { try { Debug.Assert(theirTimeZone != null, nameof(theirTimeZone) + " != null"); DateTime returnValue = theirDateTime.PlusHours(1).InZoneLeniently(theirTimeZone).ToDateTimeUtc().ToLocalTime(); Logger.Warn($"Could not convert {theirDateTime} in {theirTimeZone.Id} into {TimeZoneInfo.Local.StandardName} in TimeZoneHelper.AdjustTzTimeToLocalTime (added one hour and it worked ok to account for daylight savings)"); return(returnValue); } catch (ArgumentException ae) { Logger.Error($"Could not convert {theirDateTime} in {theirTimeZone?.Id} into {TimeZoneInfo.Local.StandardName} in TimeZoneHelper.AdjustTzTimeToLocalTime (tried adding one hour too so that we account for daylight saving): {ae.Message}"); return(theirDateTime.ToDateTimeUnspecified()); } } }
public static LocalDateTime[] pretty_minute(LocalDateTime min, LocalDateTime max, ulong diff, int n) { var span = diff / 60.0; var length = 60; { var minfit = double.MaxValue; foreach (var l in length_minutes) { var fit = Abs(span - l * n); if (fit < minfit) { length = l; minfit = fit; } } } var start = min; { var lower = min.With(TimeAdjusters.TruncateToHour); var minfit = double.MaxValue; var current = lower; while (current <= min) { var fit = _diff(min, current); if (fit < minfit) { start = current; minfit = fit; } current = current.PlusMinutes(length); } } var end = max; { var lower = max.With(TimeAdjusters.TruncateToHour); var upper = max.PlusHours(1).With(TimeAdjusters.TruncateToHour); var minfit = double.MaxValue; var current = lower; while (current <= upper) { if (current >= max) { var fit = _diff(max, current); if (fit < minfit) { end = current; minfit = fit; } } current = current.PlusMinutes(length); } } var period = end - start; var results = new LocalDateTime[(int)((period.Hours * 60 + period.Minutes) / (double)length + 1)]; { var i = 0; var current = start; while (current <= end) { results[i++] = current; current = current.PlusMinutes(length); } } return(results); }
public LocalDateTime PlusHours() => Sample.PlusHours(3);
public async Task MultipleThingTypes() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); var bloodPressure1 = new BloodPressure { EffectiveDate = nowLocal, Systolic = 110, Diastolic = 90, }; var bloodPressure2 = new BloodPressure { EffectiveDate = nowLocal.PlusHours(-1), Systolic = 111, Diastolic = 91, }; var cholesterolProfile = new CholesterolProfileV2 { When = new HealthServiceDateTime(nowLocal), LDL = new ConcentrationMeasurement(110), HDL = new ConcentrationMeasurement(65), Triglyceride = new ConcentrationMeasurement(140) }; var labTestResult = new LabTestResults(new LabTestResultGroup[] { new LabTestResultGroup(new CodableValue("test")) }); var immunization = new Immunization(new CodableValue("diphtheria, tetanus toxoids and acellular pertussis vaccine", "DTaP", new VocabularyKey("immunizations", "wc", "1"))); var procedure = new Procedure(new CodableValue("A surgery")); var allergy = new Allergy(new CodableValue("Pollen")); var condition = new Condition(new CodableValue("Diseased")); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, bloodPressure1, bloodPressure2, cholesterolProfile, labTestResult, immunization, procedure, allergy, condition }); var query = CreateMultiThingQuery(); ThingCollection thingCollection = await thingClient.GetThingsAsync(record.Id, query); Assert.AreEqual(10, thingCollection.Count); var returnedBloodGlucose = (BloodGlucose)thingCollection.First(t => t.TypeId == BloodGlucose.TypeId); Assert.AreEqual(bloodGlucose.Value.Value, returnedBloodGlucose.Value.Value); var returnedWeight = (Weight)thingCollection.First(t => t.TypeId == Weight.TypeId); Assert.AreEqual(weight.Value.Kilograms, returnedWeight.Value.Kilograms); var returnedBloodPressures = thingCollection.Where(t => t.TypeId == BloodPressure.TypeId).Cast <BloodPressure>().ToList(); Assert.AreEqual(2, returnedBloodPressures.Count); Assert.AreEqual(bloodPressure1.Systolic, returnedBloodPressures[0].Systolic); }
public void IsoDayOfWeek_AroundEpoch() { // Test about couple of months around the Unix epoch. If that works, I'm confident the rest will. LocalDateTime dateTime = new LocalDateTime(1969, 12, 1, 0, 0); for (int i = 0; i < 60; i++) { // Check once per hour of the day, just in case something's messed up based on the time of day. for (int hour = 0; hour < 24; hour++) { Assert.AreEqual(BclConversions.ToIsoDayOfWeek(dateTime.ToDateTimeUnspecified().DayOfWeek), dateTime.IsoDayOfWeek); dateTime = dateTime.PlusHours(1); } } }
public void SplitByHour() { var time = new LocalDateTime(1970, 1, 1, 10, 0, 0); TimeSeries series = GenerateTimeSeries.From(time, time.PlusMinutes(1), time.PlusMinutes(2), time.PlusMinutes(10), time.PlusMinutes(15), time.PlusMinutes(25), time.PlusHours(1), time.PlusHours(5), time.PlusHours(10).PlusMinutes(10), time.PlusHours(10).PlusMinutes(20), time.PlusHours(10).PlusMinutes(30)); var subseries = series.Split(Period.FromHours(1)); Assert.Multiple(() => { Assert.AreEqual(4, subseries.Count); Assert.AreEqual(0, subseries[0].Begin); Assert.AreEqual(5, subseries[0].End); Assert.AreEqual(6, subseries[1].Begin); Assert.AreEqual(6, subseries[1].End); Assert.AreEqual(7, subseries[2].Begin); Assert.AreEqual(7, subseries[2].End); Assert.AreEqual(8, subseries[3].Begin); Assert.AreEqual(10, subseries[3].End); }); }
public void PlusHours() { Sample.PlusHours(3).Consume(); }
public IDateTime PlusHours(int hours) { return(new DateTime(_localDateTime.PlusHours(hours))); }
public LocalDateTime PlusHours() { return(Sample.PlusHours(3)); }
public void PlusHours() { SampleStartDateTime.PlusHours(3); }
/// <summary> /// Add hours /// </summary> /// <param name="lt"></param> /// <param name="hours"></param> /// <returns></returns> public static LocalDateTime AddHours(this LocalDateTime lt, long hours) => lt.PlusHours(hours);