/// <summary> /// Private constructor only present for serialization. /// </summary> /// <param name="info">The <see cref="SerializationInfo"/> to fetch data from.</param> /// <param name="context">The source for this deserialization.</param> private Interval([NotNull] SerializationInfo info, StreamingContext context) { var presence = info.GetByte(PresenceName); start = (presence & 1) == 0 ? Instant.BeforeMinValue : Instant.FromUntrustedDuration(new Duration(info, StartDaysSerializationName, StartNanosecondOfDaySerializationName)); end = (presence & 2) == 0 ? Instant.AfterMaxValue : Instant.FromUntrustedDuration(new Duration(info, EndDaysSerializationName, EndNanosecondOfDaySerializationName)); }
/// <summary> /// Private constructor only present for serialization. /// </summary> /// <param name="info">The <see cref="SerializationInfo"/> to fetch data from.</param> /// <param name="context">The source for this deserialization.</param> private Interval([NotNull] SerializationInfo info, StreamingContext context) { var presence = info.GetByte(BinaryFormattingConstants.PresenceName); start = (presence & 1) == 0 ? Instant.BeforeMinValue : Instant.FromUntrustedDuration( new Duration(info, BinaryFormattingConstants.StartDaysSerializationName, BinaryFormattingConstants.StartNanosecondOfDaySerializationName)); end = (presence & 2) == 0 ? Instant.AfterMaxValue : Instant.FromUntrustedDuration( new Duration(info, BinaryFormattingConstants.EndDaysSerializationName, BinaryFormattingConstants.EndNanosecondOfDaySerializationName)); if (end < start) { throw new ArgumentException("Serialization data contains end before start"); } }
public Instant ToInstant() => Instant.FromUntrustedDuration(ToElapsedTimeSinceEpoch());
/// <summary> /// Subtracts the given time zone offset from this local instant, to give an <see cref="Instant" />. /// </summary> /// <remarks> /// This would normally be implemented as an operator, but as the corresponding "plus" operation /// on Instant cannot be written (as Instant is a public type and LocalInstant is an internal type) /// it makes sense to keep them both as methods for consistency. /// </remarks> /// <param name="offset">The offset between UTC and a time zone for this local instant</param> /// <returns>A new <see cref="Instant"/> representing the difference of the given values.</returns> public Instant Minus(Offset offset) => Instant.FromUntrustedDuration(duration.MinusSmallNanoseconds(offset.Nanoseconds));