<PackageReference Include="NJsonSchema" Version="11.0.0-preview007" />

TimeFormatValidator

Validator for "Time" format.
using Newtonsoft.Json.Linq; using System; using System.Globalization; using System.Runtime.CompilerServices; namespace NJsonSchema.Validation.FormatValidators { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class TimeFormatValidator : IFormatValidator { public string Format { get; } = "time"; public ValidationErrorKind ValidationErrorKind { get; } = ValidationErrorKind.TimeExpected; public bool IsValid(string value, JTokenType tokenType) { DateTime result; if (tokenType != JTokenType.Date) return DateTime.TryParseExact(value, "HH:mm:ss.FFFFFFFK", null, DateTimeStyles.None, out result); return true; } } }