Some SPARQL implementation support subtracting dates and date-times. RDF4J does not. I've whipped up a basic implementation in our RDF4J based implementation. Would such an implementation be okay for a PR?
I've hacked something like the following in XMLDatatypeMathUtil:
private static Literal operationsBetweenCalendars(Literal leftLit, Literal rightLit, MathOp op, ValueFactory vf) {
XMLGregorianCalendar left = (XMLGregorianCalendar) leftLit.calendarValue().clone();
XMLGregorianCalendar right = (XMLGregorianCalendar) rightLit.calendarValue().clone();
if (op == MathOp.MINUS) {
var difference = java.time.Duration.between(
toZonedDateTime(right),
toZonedDateTime(left)
);
var string = ...
return buildLiteral(dtFactory.newDuration(string), vf);
}
...
}
There are some finicky bits though here due to the conversion between java.time and javax.xml :( So I'm not guaranteeing 100% compatibility with xpath (op:subtract-dateTimes and friends).
Preferred solution
I think it would be good if RDF4J follows other implementations and supports the minus operator here. A function could also work, but is not ideal I think from a usage perspective. From an extension perspective it is of course.
Are you interested in contributing a solution yourself?
Problem description
Some SPARQL implementation support subtracting dates and date-times. RDF4J does not. I've whipped up a basic implementation in our RDF4J based implementation. Would such an implementation be okay for a PR?
See also https://github.com/w3c/sparql-dev/issues/32.
I've hacked something like the following in
XMLDatatypeMathUtil
:There are some finicky bits though here due to the conversion between
java.time
andjavax.xml
:( So I'm not guaranteeing 100% compatibility with xpath (op:subtract-dateTimes
and friends).Preferred solution
I think it would be good if RDF4J follows other implementations and supports the minus operator here. A function could also work, but is not ideal I think from a usage perspective. From an extension perspective it is of course.
Are you interested in contributing a solution yourself?
Yes
Alternatives you've considered
No response
Anything else?
No response