public void EraProperty() { CalendarSystem calendar = CalendarSystem.GetGregorianCalendar(4); LocalDateTime startOfEra = new LocalDateTime(1, 1, 1, 0, 0, 0, calendar); Assert.AreEqual(Era.Common, startOfEra.Era); Assert.AreEqual(Era.BeforeCommon, startOfEra.PlusTicks(-1).Era); }
public void LeapYears() { var calendar = CalendarSystem.GetGregorianCalendar(4); Assert.IsFalse(calendar.IsLeapYear(1900)); Assert.IsFalse(calendar.IsLeapYear(1901)); Assert.IsTrue(calendar.IsLeapYear(1904)); Assert.IsTrue(calendar.IsLeapYear(1996)); Assert.IsTrue(calendar.IsLeapYear(2000)); Assert.IsFalse(calendar.IsLeapYear(2100)); Assert.IsTrue(calendar.IsLeapYear(2400)); }
public void GetInstance_MinDaysInFirstWeekIsRespected() { // Seems the simplest way to test this... yes, it seems somewhat wasteful, but hey... for (int i = 1; i < 7; i++) { CalendarSystem calendar = CalendarSystem.GetGregorianCalendar(i); int actualMin = Enumerable.Range(1900, 400) .Select(year => GetDaysInFirstWeek(year, calendar)) .Min(); Assert.AreEqual(i, actualMin); } }
public void Equals_DifferentCalendars() { LocalDate start1 = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); // This is a really, really similar calendar to ISO - the dates could differ by week of year, // but that's all. LocalDate start2 = start1.WithCalendar(CalendarSystem.GetGregorianCalendar(1)); LocalDate end2 = end1.WithCalendar(CalendarSystem.GetGregorianCalendar(1)); var interval1 = new DateInterval(start1, end1, false); var interval2 = new DateInterval(start2, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void GetInstance_InvalidMinDaysInFirstWeek() { Assert.Throws <ArgumentOutOfRangeException>(() => CalendarSystem.GetGregorianCalendar(0)); Assert.Throws <ArgumentOutOfRangeException>(() => CalendarSystem.GetGregorianCalendar(8)); }
public void GetInstance_UniqueIds() { Assert.AreEqual(7, Enumerable.Range(1, 7).Select(x => CalendarSystem.GetGregorianCalendar(x).Id).Distinct().Count()); }
public void Equality() { // Goes back from 2am to 1am on June 13th SingleTransitionDateTimeZone zone = new SingleTransitionDateTimeZone(Instant.FromUtc(2011, 6, 12, 22, 0), 4, 3); var sample = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30)).First(); var fromUtc = Instant.FromUtc(2011, 6, 12, 21, 30).InZone(zone); // Checks all the overloads etc: first check is that the zone matters TestHelper.TestEqualsStruct(sample, fromUtc, Instant.FromUtc(2011, 6, 12, 21, 30).InUtc()); TestHelper.TestOperatorEquality(sample, fromUtc, Instant.FromUtc(2011, 6, 12, 21, 30).InUtc()); // Now just use a simple inequality check for other aspects... // Different offset var later = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30)).Last(); Assert.AreEqual(sample.LocalDateTime, later.LocalDateTime); Assert.AreNotEqual(sample.Offset, later.Offset); Assert.AreNotEqual(sample, later); // Different local time Assert.AreNotEqual(sample, zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 29)).First()); // Different calendar var withOtherCalendar = zone.MapLocal(new LocalDateTime(2011, 6, 13, 1, 30, CalendarSystem.GetGregorianCalendar(4))).First(); Assert.AreNotEqual(sample, withOtherCalendar); }