Accept "-00:00" as a valid timezone offset on RDF.DateTime literals

This commit is contained in:
Marcel Otto 2018-11-04 04:02:36 +01:00
parent 1907e22c62
commit 10dc249531
4 changed files with 16 additions and 2 deletions

View file

@ -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)

View file

@ -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 ->

View file

@ -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

View file

@ -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" },