Beispiel #1
0
        XmlSchema IXmlSerializable.GetSchema() => null !; // TODO(nullable): Return XmlSchema? when docfx works with that

        /// <inheritdoc />
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            Preconditions.CheckNotNull(reader, nameof(reader));
            var pattern = OffsetDateTimePattern.ExtendedIso;

            if (!reader.MoveToAttribute("zone"))
            {
                throw new ArgumentException("No zone specified in XML for ZonedDateTime");
            }
            DateTimeZone newZone = DateTimeZoneProviders.Serialization[reader.Value];

            if (reader.MoveToAttribute("calendar"))
            {
                string         newCalendarId    = reader.Value;
                CalendarSystem newCalendar      = CalendarSystem.ForId(newCalendarId);
                var            newTemplateValue = pattern.TemplateValue.WithCalendar(newCalendar);
                pattern = pattern.WithTemplateValue(newTemplateValue);
            }
            reader.MoveToElement();
            string         text           = reader.ReadElementContentAsString();
            OffsetDateTime offsetDateTime = pattern.Parse(text).Value;

            if (newZone.GetUtcOffset(offsetDateTime.ToInstant()) != offsetDateTime.Offset)
            {
                // Might as well use the exception we've already got...
                ParseResult <ZonedDateTime> .InvalidOffset(text).GetValueOrThrow();
            }
            // Use the constructor which doesn't validate the offset, as we've already done that.
            Unsafe.AsRef(this) = new ZonedDateTime(offsetDateTime, newZone);
        }
Beispiel #2
0
 public Instant ToInstant() => offsetDateTime.ToInstant();
Beispiel #3
0
 /// <inheritdoc />
 public override int Compare(OffsetDateTime x, OffsetDateTime y)
 {
     return(x.ToInstant().CompareTo(y.ToInstant()));
 }