From 3ecaaf07c019e1e45e323f899fb56de646991fe6 Mon Sep 17 00:00:00 2001 From: Tpt Date: Thu, 27 Aug 2020 00:00:09 +0200 Subject: [PATCH] Fixes MONTH() and DAY() function evaluation on xsd:date --- CHANGELOG.md | 2 ++ lib/src/model/xsd/date_time.rs | 16 ++++++++-------- lib/src/sparql/eval.rs | 4 ++-- testsuite/src/sparql_evaluator.rs | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 715f9f9f..f05cb62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ### Added - [SPARQL 1.1 Update](https://www.w3.org/TR/sparql11-update/) support for Rust, Python and JavaScript. +## Changed +- Fixes evaluation of `MONTH()` and `DAY()` functions on the `xsd:date` values. ## [0.1.1] - 2020-08-14 diff --git a/lib/src/model/xsd/date_time.rs b/lib/src/model/xsd/date_time.rs index de967134..3f68a1d2 100644 --- a/lib/src/model/xsd/date_time.rs +++ b/lib/src/model/xsd/date_time.rs @@ -142,7 +142,7 @@ impl DateTime { } } - /// [op:sub-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-dateTime) + /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-dateTime) pub fn checked_sub_year_month_duration( &self, rhs: impl Into, @@ -150,7 +150,7 @@ impl DateTime { self.checked_sub_duration(Duration::from(rhs.into())) } - /// [op:sub-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-dateTime) + /// [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-dateTime) pub fn checked_sub_day_time_duration(&self, rhs: impl Into) -> Option { let rhs = rhs.into(); Some(Self { @@ -158,7 +158,7 @@ impl DateTime { }) } - /// [op:sub-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-dateTime) and [op:sub-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-dateTime) + /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-dateTime) and [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-dateTime) pub fn checked_sub_duration(&self, rhs: impl Into) -> Option { let rhs = rhs.into(); if let Ok(rhs) = DayTimeDuration::try_from(rhs) { @@ -314,12 +314,12 @@ impl Time { .ok() } - /// [op:sub-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-time) + /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-time) pub fn checked_sub_day_time_duration(&self, rhs: impl Into) -> Option { self.checked_sub_duration(Duration::from(rhs.into())) } - /// [op:sub-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-time) + /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-time) pub fn checked_sub_duration(&self, rhs: impl Into) -> Option { DateTime::new( 1972, @@ -466,7 +466,7 @@ impl Date { .ok() } - /// [op:sub-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-date) + /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-date) pub fn checked_sub_year_month_duration( &self, rhs: impl Into, @@ -474,12 +474,12 @@ impl Date { self.checked_sub_duration(Duration::from(rhs.into())) } - /// [op:sub-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-date) + /// [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-date) pub fn checked_sub_day_time_duration(&self, rhs: impl Into) -> Option { self.checked_sub_duration(Duration::from(rhs.into())) } - /// [op:sub-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-date) and [op:sub-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-date) + /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-date) and [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-date) pub fn checked_sub_duration(&self, rhs: impl Into) -> Option { DateTime::try_from(*self) .ok()? diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 216cff8b..330d5d71 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -1285,7 +1285,7 @@ where }, PlanExpression::Month(e) => match self.eval_expression(e, tuple)? { EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.month().into()), - EncodedTerm::DateLiteral(date) => Some(date.year().into()), + EncodedTerm::DateLiteral(date) => Some(date.month().into()), EncodedTerm::GYearMonthLiteral(year_month) => Some(year_month.month().into()), EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.month().into()), EncodedTerm::GMonthLiteral(month) => Some(month.month().into()), @@ -1293,7 +1293,7 @@ where }, PlanExpression::Day(e) => match self.eval_expression(e, tuple)? { EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.day().into()), - EncodedTerm::DateLiteral(date) => Some(date.year().into()), + EncodedTerm::DateLiteral(date) => Some(date.day().into()), EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.day().into()), EncodedTerm::GDayLiteral(day) => Some(day.day().into()), _ => None, diff --git a/testsuite/src/sparql_evaluator.rs b/testsuite/src/sparql_evaluator.rs index e05ad376..3971d353 100644 --- a/testsuite/src/sparql_evaluator.rs +++ b/testsuite/src/sparql_evaluator.rs @@ -114,8 +114,8 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { } else { Err(anyhow!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", test, - actual_results, expected_results, + actual_results, Query::parse(&read_file_to_string(query_file)?, Some(query_file)).unwrap(), store ))