Page MenuHomePhabricator

Dates returned by SPARQL queries are syntactically incorrect (lacks one leading zero for a negative four-digit year)
Closed, ResolvedPublic

Description

Summary

When performing SPARQL queries against Wikidata, the dates are returned in a format that does not comply with the XML Schema specifications.

Details

The curl command below queries Wikidata for Julius Caesar's birth date:

curl 'https://query.wikidata.org/sparql?query=select%20*%20where%20%7B%0A%20%20wd%3AQ1048%20wdt%3AP569%20%3Fdate%0A%7D'
select * where {
  wd:Q1048 wdt:P569 ?date
}

Expected result

According to the XML schema specificiations:

'-'? yyyy is a four-or-more digit optionally negative-signed numeral that represents the year; if more than four digits, leading zeros are prohibited

Thus, the date should be formatted as

-0099-01-01T00:00:00Z

Notice the two leading zeroes, ensuring that the year is a "a four-or-more digit optionally negative-signed numeral".

Actual result

The date is formatted as:

-099-01-01T00:00:00Z

making it invalid.

Miscellaneous

Interestingly enough, the bug only occurs for BCE dates. For example, Caligula (Q1409)'s date of birth is correctly formatted as:

0012-08-29T00:00:00Z

Event Timeline

Aklapper renamed this task from Dates returned by SPARQL queries are syntqctically incorrect to Dates returned by SPARQL queries are syntactically incorrect (lacks one leading zero for a negative four-digit year).Dec 3 2018, 7:11 PM
Aklapper added a project: Wikidata.

This also doesn’t occur in the Wikibase RDF export:

<wdt:P569 rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">-0099-01-01T00:00:00Z</wdt:P569>
wd:Q1048 wdt:P569 "-0099-01-01T00:00:00Z"^^xsd:dateTime .

I seem to recall that WDQS implements a custom date type (instead of using Blazegraph’s built-in one), so presumably it must be a bug there.

Change 491863 had a related patch set uploaded (by Smalyshev; owner: Smalyshev):
[wikidata/query/rdf@master] Fix display of small negative dates

https://gerrit.wikimedia.org/r/491863

Change 491863 merged by jenkins-bot:
[wikidata/query/rdf@master] Fix display of small negative dates

https://gerrit.wikimedia.org/r/491863

Smalyshev triaged this task as Medium priority.Feb 22 2019, 11:22 PM
Smalyshev claimed this task.