Skip to content

Commit

Permalink
Merge pull request #571 from danielstarck/master
Browse files Browse the repository at this point in the history
Make `time-offset` required for `date-time`
  • Loading branch information
gregsdennis committed Dec 2, 2023
2 parents 2b7ed0a + dd73646 commit 6754e40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions JsonSchema.Tests/FormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public void DateTime_Pass(string dateString)
Assert.True(result.IsValid);
}

[Test]
public void DateTime_MissingTimeOffset_Fail()
{
JsonSchema schema = new JsonSchemaBuilder()
.Format(Formats.DateTime);

var value = JsonNode.Parse("\"2023-04-28T21:51:26\"");

var result = schema.Evaluate(value, new EvaluationOptions { RequireFormatValidation = true });

result.AssertInvalid();
}

private static readonly Uri _formatAssertionMetaSchemaId = new("https://json-everything/test/format-assertion");
private static readonly JsonSchema _formatAssertionMetaSchema =
new JsonSchemaBuilder()
Expand Down
2 changes: 1 addition & 1 deletion JsonSchema/Formats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private static bool CheckDateFormat(JsonNode? node, params string[] formats)
//We use a fallback to catch these cases

//from built from https://regex101.com/r/qH0sU7/1, edited to support all date+time examples in https://ijmacd.github.io/rfc3339-iso8601/
var regex = new Regex(@"^((?:(\d{4}-\d{2}-\d{2})([Tt_]| )(\d{2}:\d{2}:\d{2}(?:\.\d+)?))([Zz]|[\+-]\d{2}:\d{2})?)$");
var regex = new Regex(@"^((?:(\d{4}-\d{2}-\d{2})([Tt_]| )(\d{2}:\d{2}:\d{2}(?:\.\d+)?))([Zz]|[\+-]\d{2}:\d{2}))$");
var match = regex.Match(dateString);
return match.Success;

Expand Down

0 comments on commit 6754e40

Please sign in to comment.