Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date/date-time subtraction #5171

Open
frensjan opened this issue Nov 5, 2024 · 1 comment
Open

Date/date-time subtraction #5171

frensjan opened this issue Nov 5, 2024 · 1 comment
Labels
📶 enhancement issue is a new feature or improvement
Milestone

Comments

@frensjan
Copy link
Contributor

frensjan commented Nov 5, 2024

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 w3c/sparql-dev#32.

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?

Yes

Alternatives you've considered

No response

Anything else?

No response

@frensjan frensjan added the 📶 enhancement issue is a new feature or improvement label Nov 5, 2024
@hmottestad
Copy link
Contributor

@frensjan Sorry for the late response. I think this sounds like a great idea! RDF4J has two modes for query evaluation, so this could be part of the standard mode (previously called "extended").

Would very much appreciate a PR for this :D

@hmottestad hmottestad added this to the 5.2.0 milestone Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📶 enhancement issue is a new feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants