public void FromDateTimeOffset() { DateTimeOffset dateTimeOffset = new DateTimeOffset(2011, 3, 5, 1, 0, 0, TimeSpan.FromHours(3)); DateTimeZone fixedZone = new FixedDateTimeZone(Offset.FromHours(3)); ZonedDateTime expected = fixedZone.AtStrictly(new LocalDateTime(2011, 3, 5, 1, 0, 0)); ZonedDateTime actual = ZonedDateTime.FromDateTimeOffset(dateTimeOffset); Assert.AreEqual(expected, actual); }
public void CompareTo_DifferentZones_OnlyInstantMatters() { var otherZone = new FixedDateTimeZone(Offset.FromHours(-20)); ZonedDateTime value1 = SampleZone.AtStrictly(new LocalDateTime(2011, 1, 2, 10, 30)); // Earlier local time, but later instant ZonedDateTime value2 = otherZone.AtStrictly(new LocalDateTime(2011, 1, 2, 5, 30)); ZonedDateTime value3 = value1.WithZone(otherZone); Assert.That(value1.CompareTo(value2), Is.LessThan(0)); Assert.That(value2.CompareTo(value1), Is.GreaterThan(0)); Assert.That(value1.CompareTo(value3), Is.EqualTo(0)); }
public void ComparisonOperators_DifferentZones_AlwaysReturnsFalse() { // Note that the offsets will be the same as for SampleZone in the values we're using var otherZone = new FixedDateTimeZone(SampleZone.EarlyInterval.WallOffset); ZonedDateTime value1 = SampleZone.AtStrictly(new LocalDateTime(2011, 1, 2, 10, 30)); ZonedDateTime value2 = otherZone.AtStrictly(new LocalDateTime(2011, 1, 3, 10, 30)); // All inequality comparisons return false Assert.IsFalse(value1 < value2); Assert.IsFalse(value1 <= value2); Assert.IsFalse(value1 > value2); Assert.IsFalse(value1 >= value2); }