Fix RDF.DateTime to support 24:00:00 as valid time

This commit is contained in:
Marcel Otto 2018-06-03 23:21:14 +02:00
parent 71dc3d5acc
commit cae8e183e0
3 changed files with 22 additions and 0 deletions

View file

@ -17,6 +17,12 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
from the XPath and SPARQL specs on `RDF.Boolean`
### Fixed
- `RDF.DateTime`: '24:00:00' is a valid time in a xsd:dateTime; the dateTime
value so represented is the first instant of the following day
[Compare v0.4.1...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.4.1...HEAD)

View file

@ -24,6 +24,20 @@ defmodule RDF.DateTime do
_ -> 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),
{:ok, day} <- Date.from_iso8601(day)
do
"#{day |> Date.add(1) |> Date.to_string()}T00:00:00#{tz}"
|> convert(opts)
else
_ -> super(value, opts)
end
else
super(value, opts)
end
_ ->
super(value, opts)
end

View file

@ -16,6 +16,8 @@ defmodule RDF.DateTimeTest do
"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-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: DateTime doesn't support negative years (at least with the iso8601 conversion functions)
# "-2010-01-01T00:00:00Z" => { dt("-2010-01-01T00:00:00Z") , nil, "-2010-01-01T00:00:00Z" },
},