Esempio n. 1
0
        public void InstantComparer()
        {
            var localControl            = new LocalDateTime(2013, 4, 2, 19, 54);
            var control                 = new OffsetDateTime(localControl, Offset.Zero);
            var equalAndOppositeChanges = control.LocalDateTime.PlusHours(1).WithOffset(Offset.FromHours(1));
            var differentCalendar       = control.LocalDateTime.WithCalendar(CalendarSystem.GetCopticCalendar(4)).WithOffset(Offset.Zero);

            // Negative offset means later instant
            var negativeOffset = control.LocalDateTime.WithOffset(Offset.FromHours(-1));
            // Positive offset means earlier instant
            var positiveOffset = control.LocalDateTime.WithOffset(Offset.FromHours(1));

            // Later instant, earlier local
            var earlierLocal = control.LocalDateTime.PlusHours(-2).WithOffset(Offset.FromHours(-10));
            // Earlier instant, later local
            var laterLocal = control.LocalDateTime.PlusHours(2).WithOffset(Offset.FromHours(10));

            var comparer = OffsetDateTime.Comparer.Instant;

            Assert.AreEqual(0, comparer.Compare(control, differentCalendar));
            Assert.AreEqual(0, comparer.Compare(control, equalAndOppositeChanges));

            Assert.AreEqual(-1, Math.Sign(comparer.Compare(control, negativeOffset)));
            Assert.AreEqual(1, Math.Sign(comparer.Compare(negativeOffset, control)));
            Assert.AreEqual(1, comparer.Compare(control, positiveOffset));
            Assert.AreEqual(-1, Math.Sign(comparer.Compare(positiveOffset, control)));

            Assert.AreEqual(-1, Math.Sign(comparer.Compare(control, earlierLocal)));
            Assert.AreEqual(1, Math.Sign(comparer.Compare(earlierLocal, control)));
            Assert.AreEqual(1, Math.Sign(comparer.Compare(control, laterLocal)));
            Assert.AreEqual(-1, Math.Sign(comparer.Compare(laterLocal, control)));
        }
        public void SampleDate()
        {
            CalendarSystem copticCalendar = CalendarSystem.GetCopticCalendar(4);
            LocalDateTime  iso            = new LocalDateTime(2004, 6, 9, 0, 0, 0, 0);
            LocalDateTime  coptic         = new LocalDateTime(iso.LocalInstant, copticCalendar);

            Assert.AreEqual(Era.AnnoMartyrum, coptic.Era);
#pragma warning disable 0618
            // The misspelled version of the Era works too.
            Assert.AreEqual(Era.AnnoMartyrm, coptic.Era);
#pragma warning restore 0618
            Assert.AreEqual(18, coptic.CenturyOfEra);
            Assert.AreEqual(20, coptic.YearOfCentury);
            Assert.AreEqual(1720, coptic.YearOfEra);

            Assert.AreEqual(1720, coptic.Year);
            Assert.IsFalse(copticCalendar.IsLeapYear(1720));

            Assert.AreEqual(10, coptic.Month);
            Assert.AreEqual(2, coptic.Day);

            // TODO: Determine whether we should consider the Coptic calendar to use ISO days of the week.
            Assert.AreEqual(IsoDayOfWeek.Wednesday, coptic.IsoDayOfWeek);

            Assert.AreEqual(9 * 30 + 2, coptic.DayOfYear);

            Assert.AreEqual(0, coptic.Hour);
            Assert.AreEqual(0, coptic.Minute);
            Assert.AreEqual(0, coptic.Second);
            Assert.AreEqual(0, coptic.Millisecond);
        }
        public void LocalDateTimeConverter_SerializeNonIso_Throws()
        {
            var localDateTime = new LocalDateTime(2012, 1, 2, 3, 4, 5, CalendarSystem.GetCopticCalendar(4));

            Assert.Throws <ArgumentException>(
                () => NodaSerializerDefinitions.LocalDateTimeSerializer.Serialize(localDateTime));
        }
Esempio n. 4
0
        public void Constructor_WithYearOfEra_NonIsoCalendar()
        {
            var       calendar = CalendarSystem.GetCopticCalendar(4);
            LocalDate absolute = new LocalDate(50, 6, 19, calendar);
            LocalDate withEra  = new LocalDate(Era.AnnoMartyrum, 50, 6, 19, calendar);

            Assert.AreEqual(absolute, withEra);
        }
        public void UnixEpoch()
        {
            CalendarSystem coptic = CalendarSystem.GetCopticCalendar(4);
            LocalDateTime  unixEpochInCopticCalendar = new LocalDateTime(LocalInstant.LocalUnixEpoch, coptic);
            LocalDateTime  expected = new LocalDateTime(1686, 4, 23, 0, 0, coptic);

            Assert.AreEqual(expected, unixEpochInCopticCalendar);
        }
        public void CopticEpoch()
        {
            CalendarSystem coptic      = CalendarSystem.GetCopticCalendar(4);
            LocalDateTime  copticEpoch = new LocalDateTime(1, 1, 1, 0, 0, coptic);

            CalendarSystem julian    = CalendarSystem.GetJulianCalendar(4);
            LocalDateTime  converted = new LocalDateTime(copticEpoch.LocalInstant, julian);

            LocalDateTime expected = new LocalDateTime(284, 8, 29, 0, 0, julian);

            Assert.AreEqual(expected, converted);
        }
Esempio n. 7
0
        public void InZoneWithCalendar()
        {
            CalendarSystem copticCalendar = CalendarSystem.GetCopticCalendar(4);
            DateTimeZone   london         = DateTimeZoneProviders.Tzdb["Europe/London"];
            ZonedDateTime  viaInstant     = Instant.FromUtc(2004, 6, 9, 11, 10).InZone(london, copticCalendar);

            // Date taken from CopticCalendarSystemTest. Time will be 12:10 (London is UTC+1 in Summer)
            LocalDateTime local    = new LocalDateTime(1720, 10, 2, 12, 10, 0, copticCalendar);
            ZonedDateTime expected = london.AtStrictly(local);

            Assert.AreEqual(expected, viaInstant);
        }
Esempio n. 8
0
        public void LocalDateTimeConverter_SerializeNonIso_Throws()
        {
            var localDateTime = new LocalDateTime(2012, 1, 2, 3, 4, 5, CalendarSystem.GetCopticCalendar(4));

            Assert.Throws <ArgumentException>(() => JsonConvert.SerializeObject(localDateTime, Formatting.None, NodaConverters.LocalDateTimeConverter));
        }