if buildQuery is called with a QueryRepresentation that includes a date condition, it produces the correct SPARQL depending on the precision.
Query Examples:
Something happened on a day https://w.wiki/34zC:
# day -> precision === 11 SELECT ?item ?itemLabel WHERE { ?item p:P585/psv:P585/wikibase:timeValue "+1789-07-14T00:00:00Z"^^xsd:dateTime. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } }
something happened in a month https://w.wiki/34zD:
# month -> precision === 10 SELECT ?item ?itemLabel WHERE { ?item p:P585/psv:P585 ?timeValue. # has at least the given precision i.e. month ?timeValue wikibase:timePrecision ?precision. hint:Prior hint:rangeSafe true. # important for performance FILTER(?precision >= 10) # month precision # points to the correct month ?timeValue wikibase:timeValue ?dateTime. hint:Prior hint:rangeSafe true. # important for performance FILTER("1789-07-00"^^xsd:dateTime <= ?dateTime && ?dateTime < "1789-08-00"^^xsd:dateTime) # must be manually calculated SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } }
something happened in a year https://w.wiki/34zE:
# year -> precision === 9 SELECT ?item ?itemLabel WHERE { ?item p:P585/psv:P585 ?timeValue. # has at least the given precision i.e. year ?timeValue wikibase:timePrecision ?precision. hint:Prior hint:rangeSafe true. # important for performance FILTER(?precision >= 9) # year precision # points to the correct month ?timeValue wikibase:timeValue ?dateTime. hint:Prior hint:rangeSafe true. # important for performance FILTER("1789-00-00"^^xsd:dateTime <= ?dateTime && ?dateTime < "1790-00-00"^^xsd:dateTime) # must be manually calculated SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } }