/// <summary> /// Converts a <see cref="DateTime"/> into a new Instant representing the same instant in time. /// </summary> /// <returns>An <see cref="Instant"/> value representing the same instant in time as the given universal <see cref="DateTime"/>.</returns> /// <param name="dateTime">Date and time value which must have a <see cref="DateTime.Kind"/> of <see cref="DateTimeKind.Utc"/></param> /// <exception cref="ArgumentException"><paramref name="dateTime"/> is not of <see cref="DateTime.Kind"/> /// <see cref="DateTimeKind.Utc"/>.</exception> public static Instant FromDateTimeUtc(DateTime dateTime) { Preconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, nameof(dateTime), "Invalid DateTime.Kind for Instant.FromDateTimeUtc"); return(BclEpoch.PlusTicks(dateTime.Ticks)); }
/// <summary> /// Converts a <see cref="DateTimeOffset"/> into a new Instant representing the same instant in time. Note that /// the offset information is not preserved in the returned Instant. /// </summary> /// <returns>An <see cref="Instant"/> value representing the same instant in time as the given <see cref="DateTimeOffset"/>.</returns> /// <param name="dateTimeOffset">Date and time value with an offset.</param> public static Instant FromDateTimeOffset(DateTimeOffset dateTimeOffset) => BclEpoch.PlusTicks(dateTimeOffset.Ticks - dateTimeOffset.Offset.Ticks);