Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date-time validation fails depending on local time zone #362

Closed
ennoruijters opened this issue Dec 22, 2020 · 3 comments
Closed

Date-time validation fails depending on local time zone #362

ennoruijters opened this issue Dec 22, 2020 · 3 comments

Comments

@ennoruijters
Copy link
Contributor

Schema:

{
  "$id": "https://example.com/dateTimeTest.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "items": {
    "type": "string",
    "format": "date-time"
  }
}

Document:

[
        "2020-03-29T02:00:00Z",
        "2020-09-27T02:00:00Z",
        "2020-03-15T02:00:00Z",
        "2020-03-08T02:00:00Z",
        "2020-03-27T02:00:00Z",
        "2020-08-04T02:00:00Z"
]

This should be accepted, as all one the listed times are perfectly valid UTC times. However, on my machine (Amsterdam time), it fails with the message "$[0]: 2020-03-29T02:00:00Z is an invalid date-time".

This is because DateTimeValidator.validateDateTime does not set the time zone of the SimpleDateFormat which therefore defaults to the system time. The first date in the list was the time when daylight savings time began, so the local timed jumped to 03:00, and 02:00 never existed. The other dates in the list are times when DST started elsewhere in the world, so it should be relatively easy to test in other time zones.

Proposal: Since the RFC-3339 time format does not provide sufficient information to determine whether daylight savings time might apply (only a time zone offset can be specified), set the SimpleDateFormat to the UTC time zone, so that all valid times are accepted.

@ennoruijters
Copy link
Contributor Author

A testcase and proposed fix are available in this branch.

@stevehu
Copy link
Contributor

stevehu commented Dec 22, 2020

@ennoruijters It makes perfect sense to set the time zone. Could you please submit a PR? Thanks.

@ennoruijters
Copy link
Contributor Author

Submitted, PR #363.

@stevehu stevehu closed this as completed Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants