示例#1
0
        public void Resolver_DefaultDateInterval()
        {
            var configuredResolver = CompositeResolver.Create(new NodaTimeResolver(DateTimeZoneProviders.Tzdb),
                                                              StandardResolver.Default);
            var explicitResolver =
                CompositeResolver.Create(NodaFormatters.CreateDateIntervalFormatter(NameHandling.Ordinal), NodaFormatters.LocalDateFormatter);
            var interval = new DateInterval(new LocalDate(2001, 2, 3), new LocalDate(2004, 5, 6));

            Assert.Equal(Serialize(interval, explicitResolver),
                         Serialize(interval, configuredResolver));
        }
示例#2
0
        public void Resolver_DefaultInterval()
        {
            var configuredResolver = CompositeResolver.Create(new NodaTimeResolver(DateTimeZoneProviders.Tzdb),
                                                              StandardResolver.Default);
            var explicitResolver =
                CompositeResolver.Create(NodaFormatters.CreateIntervalFormatter(NameHandling.Ordinal), NodaFormatters.InstantFormatter);

            var interval = new Interval(Instant.FromUnixTimeTicks(1000L), Instant.FromUnixTimeTicks(20000L));

            Assert.Equal(Serialize(interval, explicitResolver),
                         Serialize(interval, configuredResolver));
        }
        public void ZonedDateTimeFormatter()
        {
            // Deliberately give it an ambiguous local time, in both ways.
            var zone         = DateTimeZoneProviders.Tzdb["Europe/London"];
            var earlierValue = new ZonedDateTime(new LocalDateTime(2012, 10, 28, 1, 30), zone, Offset.FromHours(1));
            var laterValue   = new ZonedDateTime(new LocalDateTime(2012, 10, 28, 1, 30), zone, Offset.FromHours(0));
            var earlierJson  = "\"2012-10-28T01:30:00+01 Europe/London\"";
            var laterJson    = "\"2012-10-28T01:30:00Z Europe/London\"";
            var converter    = NodaFormatters.CreateZonedDateTimeFormatter(DateTimeZoneProviders.Tzdb);

            AssertConversions(earlierValue, earlierJson, converter);
            AssertConversions(laterValue, laterJson, converter);
        }