public void TestAddDaysDSTSummer() // could be winter as well ;) { DateTime utcDt = new DateTime(2018, 7, 27, 22, 0, 0, DateTimeKind.Utc); DateTime localDt = DateTime.SpecifyKind(TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2018, 7, 27, 22, 0, 0, DateTimeKind.Utc), Verbrauch.CENTRAL_EUROPE_STANDARD_TIME), DateTimeKind.Unspecified); DateTime resultUtc = utcDt.AddDaysDST(1); DateTime resultLocal = localDt.AddDaysDST(1); Assert.AreEqual(DateTimeKind.Utc, resultUtc.Kind); Assert.AreEqual(DateTimeKind.Unspecified, resultLocal.Kind); Assert.AreEqual(24, (new TimeRange(utcDt, resultUtc)).Duration.TotalHours); Assert.AreEqual(24, (new TimeRange() { Start = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(localDt, DateTimeKind.Unspecified), Verbrauch.CENTRAL_EUROPE_STANDARD_TIME), End = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(resultLocal, DateTimeKind.Unspecified), Verbrauch.CENTRAL_EUROPE_STANDARD_TIME) }).Duration.TotalHours); }
public void TestAddDaysDSTAutumn() { DateTime utcDt = new DateTimeOffset(2018, 10, 27, 22, 0, 0, TimeSpan.Zero).UtcDateTime; DateTime localDt = DateTime.SpecifyKind(TimeZoneInfo.ConvertTimeFromUtc(new DateTimeOffset(2018, 10, 27, 22, 0, 0, TimeSpan.Zero).UtcDateTime, CentralEuropeStandardTime.CENTRAL_EUROPE_STANDARD_TIME), DateTimeKind.Unspecified); DateTime resultUtc = utcDt.AddDaysDST(1); DateTime resultLocal = localDt.AddDaysDST(1); Assert.AreEqual(DateTimeKind.Utc, resultUtc.Kind); Assert.AreEqual(DateTimeKind.Unspecified, resultLocal.Kind); Assert.AreEqual(25, (new TimeRange(utcDt, resultUtc)).Duration.TotalHours); Assert.AreEqual(25, (new TimeRange() { Start = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(localDt, DateTimeKind.Unspecified), CentralEuropeStandardTime.CENTRAL_EUROPE_STANDARD_TIME), End = TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(resultLocal, DateTimeKind.Unspecified), CentralEuropeStandardTime.CENTRAL_EUROPE_STANDARD_TIME) }).Duration.TotalHours); }