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

Use NaiveDatetime as parsing module for date-time format #68

Merged
merged 5 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the project to your Mix dependencies in `mix.exs`:
```elixir
defp deps do
[
{:ex_json_schema, "~> 0.9.0"}
{:ex_json_schema, "~> 0.9.1"}
]
end
```
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_json_schema/validator/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ defmodule ExJsonSchema.Validator.Format do
defp do_validate(_, "date-time" = format, data) do
data
|> String.upcase()
|> DateTime.from_iso8601()
|> NaiveDateTime.from_iso8601()
|> case do
{:ok, %DateTime{}, _} -> []
{:ok, %NaiveDateTime{}} -> []
_ -> [%Error{error: %Error.Format{expected: format}}]
end
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ExJsonSchema.Mixfile do
use Mix.Project

@source_url "https://github.com/jonasschmidt/ex_json_schema"
@version "0.9.0"
@version "0.9.1"

def project do
[
Expand Down
6 changes: 5 additions & 1 deletion test/ex_json_schema/validator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,14 @@ defmodule ExJsonSchema.ValidatorTest do
assert :ok == validate(%{"format" => "date-time"}, false)
end

test "format validation succeeds for datetime with tz offset" do
mrnovalles marked this conversation as resolved.
Show resolved Hide resolved
assert :ok == validate(%{"format" => "date-time"}, "2012-12-12 12:12:12Z")
mrnovalles marked this conversation as resolved.
Show resolved Hide resolved
end

test "validation errors for date-time format" do
assert_validation_errors(
%{"format" => "date-time"},
"2012-12-12 12:12:12",
"2012-12-12 12:12:12-1.5",
[{"Expected to be a valid ISO 8601 date-time.", "#"}],
[%Error{error: %Error.Format{expected: "date-time"}, path: "#"}]
)
Expand Down