public static Instant Iso8601ToInstant(string value, Iso8601ParseOptions options) { var result = OffsetDateTimePattern #if NODATIME2 .ExtendedIso // NodaTime 2.x #else .ExtendedIsoPattern // NodaTime 1.x #endif .Parse(value); if (result.Success) { return(result.Value.ToInstant()); } if ((options & Iso8601ParseOptions.AllowEndOfTime) != 0 && value.Equals("MaxInstant", StringComparison.InvariantCultureIgnoreCase)) { return(Instant.MaxValue); } if ((options & Iso8601ParseOptions.AllowBeginningOfTime) != 0 && value.Equals("MinInstant", StringComparison.InvariantCultureIgnoreCase)) { return(Instant.MinValue); } throw new ArgumentException(string.Format("Failed to parse '{0}'.", value), result.Exception); }
public void Iso8601ToInstantPassedInvalidValueThrowsArgumentException(string testValue, Iso8601ParseOptions options) { Assert.That(() => NodaTimeConverter.Iso8601ToInstant(testValue, options), Throws.ArgumentException); }