Skip to content

DateTime Subtraction#2645

Open
yarox-1 wants to merge 28 commits intoad-freiburg:masterfrom
yarox-1:DateTimeSubtraction
Open

DateTime Subtraction#2645
yarox-1 wants to merge 28 commits intoad-freiburg:masterfrom
yarox-1:DateTimeSubtraction

Conversation

@yarox-1
Copy link

@yarox-1 yarox-1 commented Jan 16, 2026

  • overload for DateYearDuration operator- +Tests
  • ValueGetter für NumericOrDate
  • changes to SubtractExpression (to allow for DateYearDuration objects)

TODOS:

  • tests
  • DateTime Subtraction not yet working in the qlever ui

@sparql-conformance
Copy link

Overview

Number of Tests Passed ✅ Intended ✅ Failed ❌ Not tested
547 450 73 24 0

Conformance check passed ✅

No test result changes.

Details: https://qlever.dev/sparql-conformance-ui?cur=3698083ff25f281e06020dc441663f2075ecd9ae&prev=7ec91f836cb8c98b4e07c906574cb4bf7f6f4e02

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Member

@ullingerc ullingerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much. This will be a very useful addition to QLever.
And it is already quite nice. Let's iterate the details so we can get this PR on track for merge.

}

// no viable subtraction
throw std::invalid_argument("No Subtraction possible!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which subtractions between dates are not possible?
We should implement them also for Year, ...
So ideally this throw will not be necessary any more. In any case, a SPARQL function should not throw on invalid input, but return UNDEF instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that Duration - Date does not make sense (probably same for Duration - Year).
Other than that Date - Date, Date - Duration, Duration - Duration and Year - Year makes sense and should be implemented.

Comment on lines +408 to +411
60 -
(minute2 + (secondsPassed > 0.0
? 1
: 0)); // we add 1 because the seconds added a minute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the reason to add 1 here ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the time left until the next day is calculated. For example take the time 05:35:30 : I started with the seconds and saved the amount of seconds needed to get to the next minute (here 30s). But with this the time changed to 5:36:00 , therefore when calculating the amount of minutes needed to get to the next hour (here 06) I added 1 minute to get from 05:35 to 5:36. 0 is only added if 60.0 - seconds <= 0.0 (for example 60.0 - 60.0). The same is then done for the minutes when calculating the hoursPassed.

updatePassedTimes(otherDate, ownDate, daysPassed, hoursPassed,
minutesPassed, secondsPassed);
}
return DateYearOrDuration(DayTimeDuration(DayTimeDuration::Type::Positive,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, Shouldn't the duration be negative if I subtract an later date from a earlier one like 1. Jan 2005 - 1. Jan 2025 should be -20 years?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can look up how other engines that implement that.

The standard draft (https://github.com/w3c/sparql-dev/blob/main/SEP/SEP-0002/sep-0002.md) relies on XPath, which doesn't specify the negative case (https://www.w3.org/TR/xpath-functions/#func-subtract-dateTimes). And the examples for the SEP0002 are also not helpful unfortunately (https://github.com/kasei/sparql-12/blob/xsd_datetime_duration/tests/xsd_functions/dateTime_subtract-01.rq)

@ullingerc ullingerc marked this pull request as ready for review January 29, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants