diff --git a/CHANGELOG.md b/CHANGELOG.md index 2777406..859f632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and ### Fixed - `RDF.Date.equal_value?/2` did not handle timezones correctly +- `-00:00` is a valid timezone offset on `RDF.DateTime` [Compare v0.5.1...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.5.1...HEAD) diff --git a/lib/rdf/datatypes/date_time.ex b/lib/rdf/datatypes/date_time.ex index 953f6e8..b6e1946 100644 --- a/lib/rdf/datatypes/date_time.ex +++ b/lib/rdf/datatypes/date_time.ex @@ -29,6 +29,14 @@ defmodule RDF.DateTime do _ -> super(value, opts) end + {:error, :invalid_format} -> + if String.ends_with?(value, "-00:00") do + String.replace_trailing(value, "-00:00", "Z") + |> convert(opts) + else + super(value, opts) + end + {:error, :invalid_time} -> if String.contains?(value, "T24:00:00") do with [day, tz] <- String.split(value, "T24:00:00", parts: 2), @@ -43,6 +51,7 @@ defmodule RDF.DateTime do else super(value, opts) end + _ -> super(value, opts) end @@ -129,7 +138,7 @@ defmodule RDF.DateTime do nil -> nil - zone when zone in ["Z", "", "+00:00"] -> + zone when zone in ["Z", "", "+00:00", "-00:00"] -> canonical_lexical(literal.value) zone -> diff --git a/test/unit/datatypes/date_time_test.exs b/test/unit/datatypes/date_time_test.exs index cbe2229..6cda499 100644 --- a/test/unit/datatypes/date_time_test.exs +++ b/test/unit/datatypes/date_time_test.exs @@ -17,12 +17,14 @@ defmodule RDF.DateTimeTest do "2010-01-01T00:00:00.123456Z" => { dt( "2010-01-01T00:00:00.123456Z") , nil , "2010-01-01T00:00:00.123456Z" }, "2010-01-01T00:00:00" => { dt( "2010-01-01T00:00:00") , nil , "2010-01-01T00:00:00" }, "2010-01-01T00:00:00+00:00" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T00:00:00+00:00", "2010-01-01T00:00:00Z" }, + "2010-01-01T00:00:00-00:00" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T00:00:00-00:00", "2010-01-01T00:00:00Z" }, "2010-01-01T01:00:00+01:00" => { dt( "2010-01-01T00:00:00Z") , "2010-01-01T01:00:00+01:00", "2010-01-01T00:00:00Z" }, "2009-12-31T23:00:00.42-01:00" => { dt( "2010-01-01T00:00:00.42Z") , "2009-12-31T23:00:00.42-01:00", "2010-01-01T00:00:00.42Z" }, "2009-12-31T23:00:00-01:00" => { dt( "2010-01-01T00:00:00Z") , "2009-12-31T23:00:00-01:00", "2010-01-01T00:00:00Z" }, "2009-12-31T24:00:00" => { dt( "2010-01-01T00:00:00") , "2009-12-31T24:00:00" , "2010-01-01T00:00:00" }, "2009-12-31T24:00:00+00:00" => { dt( "2010-01-01T00:00:00Z") , "2009-12-31T24:00:00+00:00", "2010-01-01T00:00:00Z" }, -# TODO: DateTimes on Elixir versions < 1.7.2 don't handle negative years correctly, so we test this conditionally below + "2009-12-31T24:00:00-00:00" => { dt( "2010-01-01T00:00:00Z") , "2009-12-31T24:00:00-00:00", "2010-01-01T00:00:00Z" }, +# DateTimes on Elixir versions < 1.7.2 don't handle negative years correctly, so we test this conditionally below # "-2010-01-01T00:00:00Z" => { dt("-2010-01-01T00:00:00Z") , nil, "-2010-01-01T00:00:00Z" }, }, invalid: ~w( @@ -174,6 +176,7 @@ defmodule RDF.DateTimeTest do assert RDF.date_time(~N[2010-01-01T12:34:56]) |> DateTime.canonical_lexical_with_zone() == "2010-01-01T12:34:56" assert RDF.date_time("2010-01-01T12:34:56") |> DateTime.canonical_lexical_with_zone() == "2010-01-01T12:34:56" assert RDF.date_time("2010-01-01T00:00:00+00:00") |> DateTime.canonical_lexical_with_zone() == "2010-01-01T00:00:00Z" + assert RDF.date_time("2010-01-01T00:00:00-00:00") |> DateTime.canonical_lexical_with_zone() == "2010-01-01T00:00:00Z" assert RDF.date_time("2010-01-01T01:00:00+01:00") |> DateTime.canonical_lexical_with_zone() == "2010-01-01T01:00:00+01:00" assert RDF.date_time("2010-01-01 01:00:00+01:00") |> DateTime.canonical_lexical_with_zone() == "2010-01-01T01:00:00+01:00" end diff --git a/test/unit/datatypes/time_test.exs b/test/unit/datatypes/time_test.exs index f04b14e..357800c 100644 --- a/test/unit/datatypes/time_test.exs +++ b/test/unit/datatypes/time_test.exs @@ -10,6 +10,7 @@ defmodule RDF.TimeTest do "00:00:00.1234Z" => { {~T[00:00:00.1234], true }, nil , "00:00:00.1234Z" }, "00:00:00.0000Z" => { {~T[00:00:00.0000], true }, nil , "00:00:00.0000Z" }, "00:00:00+00:00" => { {~T[00:00:00], true } , "00:00:00+00:00" , "00:00:00Z" }, + "00:00:00-00:00" => { {~T[00:00:00], true } , "00:00:00-00:00" , "00:00:00Z" }, "01:00:00+01:00" => { {~T[00:00:00], true } , "01:00:00+01:00" , "00:00:00Z" }, "23:00:00-01:00" => { {~T[00:00:00], true } , "23:00:00-01:00" , "00:00:00Z" }, "23:00:00.45-01:00" => { {~T[00:00:00.45], true } , "23:00:00.45-01:00" , "00:00:00.45Z" },