Skip to content

Commit a1191fc

Browse files
Use NaiveDatetime as parsing module for date-time format (#68)
* Use NaiveDatetime as parsing module for date-time format * Bump patch version * Update lib/ex_json_schema/validator/format.ex Co-authored-by: Jonas Schmidt <[email protected]> * Make project test to be for a date with not tz * Update test/ex_json_schema/validator_test.exs Co-authored-by: Jonas Schmidt <[email protected]> Co-authored-by: Jonas Schmidt <[email protected]>
1 parent a71ad59 commit a1191fc

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Add the project to your Mix dependencies in `mix.exs`:
1717
```elixir
1818
defp deps do
1919
[
20-
{:ex_json_schema, "~> 0.9.0"}
20+
{:ex_json_schema, "~> 0.9.1"}
2121
]
2222
end
2323
```

lib/ex_json_schema/validator/format.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ defmodule ExJsonSchema.Validator.Format do
6464
defp do_validate(_, "date-time" = format, data) do
6565
data
6666
|> String.upcase()
67-
|> DateTime.from_iso8601()
67+
|> NaiveDateTime.from_iso8601()
6868
|> case do
69-
{:ok, %DateTime{}, _} -> []
69+
{:ok, %NaiveDateTime{}} -> []
7070
_ -> [%Error{error: %Error.Format{expected: format}}]
7171
end
7272
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule ExJsonSchema.Mixfile do
22
use Mix.Project
33

44
@source_url "https://github.com/jonasschmidt/ex_json_schema"
5-
@version "0.9.0"
5+
@version "0.9.1"
66

77
def project do
88
[

test/ex_json_schema/validator_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,14 @@ defmodule ExJsonSchema.ValidatorTest do
667667
assert :ok == validate(%{"format" => "date-time"}, false)
668668
end
669669

670+
test "format validation succeeds for datetime without tz offset" do
671+
assert :ok == validate(%{"format" => "date-time"}, "2012-12-12 12:12:12")
672+
end
673+
670674
test "validation errors for date-time format" do
671675
assert_validation_errors(
672676
%{"format" => "date-time"},
673-
"2012-12-12 12:12:12",
677+
"2012-12-12 12:12:12-1.5",
674678
[{"Expected to be a valid ISO 8601 date-time.", "#"}],
675679
[%Error{error: %Error.Format{expected: "date-time"}, path: "#"}]
676680
)

0 commit comments

Comments
 (0)