From 5f3eed0c4c921c50e5c2a83d0bd356ea10bce43d Mon Sep 17 00:00:00 2001 From: Martin Middel Date: Tue, 6 Dec 2022 09:58:22 +0100 Subject: [PATCH] Implement adding and subtracting durations from datetimes --- .../dataTypes/valueTypes/DateTime.ts | 48 +++++++++++++++-- test/assets/unrunnableTestCases.csv | 52 +++---------------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/expressions/dataTypes/valueTypes/DateTime.ts b/src/expressions/dataTypes/valueTypes/DateTime.ts index fb7a91b0a..3eb7811c0 100644 --- a/src/expressions/dataTypes/valueTypes/DateTime.ts +++ b/src/expressions/dataTypes/valueTypes/DateTime.ts @@ -466,13 +466,51 @@ export function subtract( return new DayTimeDuration(secondsOfDuration); } -export function addDuration(dateTime: DateTime, _duration: AbstractDuration): DateTime { - throw new Error(`Not implemented: adding durations to ${valueTypeToString(dateTime.type)}`); +export function addDuration(dateTime: DateTime, duration: AbstractDuration): DateTime { + const jsDateTime = dateTime.toJavaScriptDate(); + jsDateTime.setUTCFullYear(jsDateTime.getUTCFullYear() + duration.getYears()); + jsDateTime.setUTCMonth(jsDateTime.getUTCMonth() + duration.getMonths()); + jsDateTime.setUTCDate(jsDateTime.getUTCDate() + duration.getDays()); + jsDateTime.setUTCHours(jsDateTime.getUTCHours() + duration.getHours()); + jsDateTime.setUTCMinutes(jsDateTime.getUTCMinutes() + duration.getMinutes()); + jsDateTime.setUTCSeconds(jsDateTime.getUTCSeconds() + Math.floor(duration.getSeconds())); + jsDateTime.setUTCMilliseconds(jsDateTime.getUTCMilliseconds() + (duration.getSeconds() % 1)); + + return new DateTime( + jsDateTime.getUTCFullYear(), + jsDateTime.getUTCMonth() + 1, + jsDateTime.getUTCDate(), + jsDateTime.getUTCHours(), + jsDateTime.getUTCMinutes(), + jsDateTime.getUTCSeconds(), + jsDateTime.getUTCMilliseconds(), + + dateTime.getTimezone(), + dateTime.type, + ); } -export function subtractDuration(dateTime: DateTime, _duration: AbstractDuration): DateTime { - throw new Error( - `Not implemented: subtracting durations from ${valueTypeToString(dateTime.type)}`, +export function subtractDuration(dateTime: DateTime, duration: AbstractDuration): DateTime { + const jsDateTime = dateTime.toJavaScriptDate(); + jsDateTime.setUTCFullYear(jsDateTime.getUTCFullYear() - duration.getYears()); + jsDateTime.setUTCMonth(jsDateTime.getUTCMonth() - duration.getMonths()); + jsDateTime.setUTCDate(jsDateTime.getUTCDate() - duration.getDays()); + jsDateTime.setUTCHours(jsDateTime.getUTCHours() - duration.getHours()); + jsDateTime.setUTCMinutes(jsDateTime.getUTCMinutes() - duration.getMinutes()); + jsDateTime.setUTCSeconds(jsDateTime.getUTCSeconds() - Math.floor(duration.getSeconds())); + jsDateTime.setUTCMilliseconds(jsDateTime.getUTCMilliseconds() - (duration.getSeconds() % 1)); + + return new DateTime( + jsDateTime.getUTCFullYear(), + jsDateTime.getUTCMonth() + 1, + jsDateTime.getUTCDate(), + jsDateTime.getUTCHours(), + jsDateTime.getUTCMinutes(), + jsDateTime.getUTCSeconds(), + jsDateTime.getUTCMilliseconds(), + + dateTime.getTimezone(), + dateTime.type, ); } diff --git a/test/assets/unrunnableTestCases.csv b/test/assets/unrunnableTestCases.csv index 013e0a8ee..e2d96c204 100644 --- a/test/assets/unrunnableTestCases.csv +++ b/test/assets/unrunnableTestCases.csv @@ -252,14 +252,6 @@ fn-countnpi1args-1,Error: FOCA0003: can not cast -999999999999999999 to xs:integ fn-countnpi1args-2,Error: FOCA0003: can not cast -475688437271870490 to xs:integer, it is out of bounds for JavaScript numbers. fn-countnni1args-2,Error: FOCA0003: can not cast 303884545991464527 to xs:integer, it is out of bounds for JavaScript numbers. fn-countnni1args-3,Error: FOCA0003: can not cast 999999999999999999 to xs:integer, it is out of bounds for JavaScript numbers. -fn-current-date-6,Error: Not implemented: adding durations to xs:date -fn-current-date-7,Error: Not implemented: subtracting durations from xs:date -fn-current-date-21,Error: Not implemented: subtracting durations from xs:date -fn-current-dateTime-6,Error: Not implemented: adding durations to xs:dateTime -fn-current-datetime-7,Error: Not implemented: subtracting durations from xs:dateTime -fn-current-dateTime-21,Error: Not implemented: subtracting durations from xs:dateTime -fn-current-time-6,Error: Not implemented: adding durations to xs:time -fn-current-time-7,Error: Not implemented: subtracting durations from xs:time fn-dataintg1args-1,Error: FOCA0003: can not cast -999999999999999999 to xs:integer, it is out of bounds for JavaScript numbers. fn-dataintg1args-2,Error: FOCA0003: can not cast 830993497117024304 to xs:integer, it is out of bounds for JavaScript numbers. fn-dataintg1args-3,Error: FOCA0003: can not cast 999999999999999999 to xs:integer, it is out of bounds for JavaScript numbers. @@ -278,10 +270,10 @@ fn-datanni1args-2,Error: FOCA0003: can not cast 303884545991464527 to xs:integer fn-datanni1args-3,Error: FOCA0003: can not cast 999999999999999999 to xs:integer, it is out of bounds for JavaScript numbers. K2-DataFunc-6,AssertionError: expected [Function] to throw an error fn-dateTime-22,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-dateTime-to-timezone with arity of 2 not registered. Did you mean "Q{test}custom-dateTime-function ()"? -fn-dateTime-24,Error: Not implemented: adding durations to xs:dateTime -fn-dateTime-25,Error: Not implemented: adding durations to xs:dateTime -fn-dateTime-26,Error: Not implemented: subtracting durations from xs:dateTime -fn-dateTime-27,Error: Not implemented: subtracting durations from xs:dateTime +fn-dateTime-24,AssertionError: fn:dateTime(xs:date("1999-12-31+10:00"), xs:time("23:00:00+10:00")) + xs:yearMonthDuration("P1Y2M"): expected '2001-03-03T13:00:00+10:00' to equal '2001-02-28T23:00:00+10:00' +fn-dateTime-25,AssertionError: fn:dateTime(xs:date("1999-12-31+10:00"), xs:time("23:00:00+10:00")) + xs:dayTimeDuration("P3DT1H15M"): expected '2000-01-03T14:15:00+10:00' to equal '2000-01-04T00:15:00+10:00' +fn-dateTime-26,AssertionError: fn:dateTime(xs:date("1999-12-31+10:00"), xs:time("23:00:00+10:00")) - xs:yearMonthDuration("P1Y2M"): expected '1998-10-31T13:00:00+10:00' to equal '1998-10-31T23:00:00+10:00' +fn-dateTime-27,AssertionError: fn:dateTime(xs:date("1999-12-31+10:00"), xs:time("23:00:00+10:00")) - xs:dayTimeDuration("P3DT1H15M"): expected '1999-12-28T11:45:00+10:00' to equal '1999-12-28T21:45:00+10:00' cbcl-dateTime-001,Error: XPTY0004: eqOp not available for xs:string and xs:dateTime cbcl-dateTime-002,AssertionError: expected [Function] to throw error matching /FORG0008/ but got 'XPST0017: Function Q{http://www.w3.or…' fn-day-from-dateTime-3,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-dateTime-to-timezone with arity of 2 not registered. Did you mean "Q{test}custom-dateTime-function ()"? @@ -343,7 +335,6 @@ K2-SeqDeepEqualFunc-14,Error: No selector counterpart for: computedDocumentConst K2-SeqDeepEqualFunc-15,Error: No selector counterpart for: computedDocumentConstructor. K2-SeqDeepEqualFunc-16,Error: No selector counterpart for: computedDocumentConstructor. K2-SeqDeepEqualFunc-17,Error: No selector counterpart for: computedDocumentConstructor. -K2-SeqDeepEqualFunc-40,Error: Not implemented: subtracting durations from xs:dateTime cbcl-deep-equal-005,Error: 1: declare function local:f($x as xs:integer)as xs:integer* { 1 to $x }; deep-equal((local:f(3), 2, local:f(1)), (local:f(3), 2)) ^ Error: XPST0003: Failed to parse script. Expected {,external at <>:1:43 - 1:44 fn-distinct-valuesintg1args-1,Error: FOCA0003: can not cast -999999999999999999 to xs:integer, it is out of bounds for JavaScript numbers. fn-distinct-valuesintg1args-2,Error: FOCA0003: can not cast 830993497117024304 to xs:integer, it is out of bounds for JavaScript numbers. @@ -782,12 +773,6 @@ fn-idref-4,Error: No selector counterpart for: computedDocumentConstructor. cbcl-idref-001,Error: No selector counterpart for: computedDocumentConstructor. cbcl-idref-002,AssertionError: Expected executing the XPath " let $doc := document { } return fn:empty( fn:idref( (), $doc) ) " to resolve to one of the expected results, but got Error: No selector counterpart for: computedDocumentConstructor., AssertionError: expected [Function] to throw error matching /XPST0005/ but got 'No selector counterpart for: computed…'. cbcl-idref-003,Error: No selector counterpart for: computedDocumentConstructor. -fn-implicit-timezone-15,Error: Not implemented: adding durations to xs:time -fn-implicit-timezone-16,Error: Not implemented: subtracting durations from xs:time -fn-implicit-timezone-17,Error: Not implemented: subtracting durations from xs:date -fn-implicit-timezone-18,Error: Not implemented: adding durations to xs:date -fn-implicit-timezone-19,Error: Not implemented: subtracting durations from xs:dateTime -fn-implicit-timezone-20,Error: Not implemented: adding durations to xs:dateTime fn-implicit-timezone-21,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-date-to-timezone with arity of 2 not registered. No similar functions found. fn-implicit-timezone-22,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-time-to-timezone with arity of 2 not registered. No similar functions found. fn-implicit-timezone-23,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-dateTime-to-timezone with arity of 2 not registered. Did you mean "Q{test}custom-dateTime-function ()"? @@ -1772,11 +1757,6 @@ xs-error-048,AssertionError: expected [Function] to throw error matching /XPDY00 xs-error-049,Error: No selector counterpart for: treatExpr. xs-float-004,AssertionError: expected [Function] to throw an error K-DayTimeDurationAdd-3,AssertionError: Expected XPath xs:dayTimeDuration("P3DT4H3M3.100S") + xs:dayTimeDuration("P3DT12H31M56.303S") eq xs:dayTimeDuration("P6DT16H34M59.403S") to resolve to true: expected false to be true -cbcl-plus-001,Error: Not implemented: adding durations to xs:date -cbcl-plus-003,Error: Not implemented: adding durations to xs:date -cbcl-plus-005,Error: Not implemented: adding durations to xs:dateTime -cbcl-plus-007,Error: Not implemented: adding durations to xs:dateTime -cbcl-plus-009,Error: Not implemented: adding durations to xs:time cbcl-plus-015,Error: XPTY0004: addOp not available for types xs:dayTimeDuration and xs:date cbcl-plus-017,Error: XPTY0004: addOp not available for types xs:yearMonthDuration and xs:date cbcl-plus-019,Error: XPTY0004: addOp not available for types xs:dayTimeDuration and xs:dateTime @@ -2231,13 +2211,6 @@ K2-StringEqual-6,Error: No selector counterpart for: treatExpr. K2-StringLT-1,AssertionError: Expected XPath "" lt "𑅰" to resolve to true: expected false to be true op-subtract-dates-yielding-DTD-8,AssertionError: xs:date("0001-01-01Z") - xs:date("2005-07-06Z"): expected '-P38172D' to equal '-P732132D' op-subtract-dateTimes-yielding-DTD-8,AssertionError: xs:dateTime("0001-01-01T01:01:01Z") - xs:dateTime("2005-07-06T12:12:12Z"): expected '-P38172DT11H11M11S' to equal '-P732132DT11H11M11S' -K2-DayTimeDurationSubtract-1,Error: Not implemented: subtracting durations from xs:time -K2-DayTimeDurationSubtract-2,Error: Not implemented: subtracting durations from xs:dateTime -cbcl-minus-001,Error: Not implemented: subtracting durations from xs:date -cbcl-minus-003,Error: Not implemented: subtracting durations from xs:date -cbcl-minus-005,Error: Not implemented: subtracting durations from xs:dateTime -cbcl-minus-007,Error: Not implemented: subtracting durations from xs:dateTime -cbcl-minus-009,Error: Not implemented: subtracting durations from xs:time cbcl-subtract-times-003,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-time-to-timezone with arity of 1 not registered. No similar functions found. cbcl-subtract-times-004,Error: XPST0017: Function Q{http://www.w3.org/2005/xpath-functions}adjust-time-to-timezone with arity of 2 not registered. No similar functions found. rangeExpr-28,AssertionError: Expected executing the XPath "18446744073709551616 to 18446744073709551620" to resolve to one of the expected results, but got AssertionError: 18446744073709551616 to 18446744073709551620: expected '18446744073709552000' to equal '18446744073709551616 1844674407370955…', AssertionError: expected [Function] to throw an error. @@ -2375,7 +2348,6 @@ CastAs175,AssertionError: Expected XPath xs:float("5.4321E-100") cast as xs:deci CastAs201,AssertionError: xs:double("1e8") cast as xs:string: expected '100000000' to equal '1.0E8' CastAs600,AssertionError: xs:base64Binary("aA+zZ/09") cast as xs:hexBinary: expected '68FB367FD3D' to equal '680FB367FD3D' CastAs647,AssertionError: Expected executing the XPath "xs:string(2.123456789123456789) cast as xs:decimal" to resolve to one of the expected results, but got AssertionError: xs:string(2.123456789123456789) cast as xs:decimal: expected '2.123456789123457' to equal '2.123456789123456789', AssertionError: expected [Function] to throw an error. -CastAs670,AssertionError: Expected executing the XPath "let $d1 := '2006-07-12' cast as xs:date let $oneky := xs:yearMonthDuration('P1000Y') let $d2 := $d1 + $oneky let $d3 := $d2 + $oneky let $d4 := $d3 + $oneky let $d5 := $d4 + $oneky let $d6 := $d5 + $oneky let $d7 := $d6 + $oneky let $d8 := $d7 + $oneky let $d9 := $d8 + $oneky let $d10 := $d9 + $oneky return $d10" to resolve to one of the expected results, but got Error: Not implemented: adding durations to xs:date, AssertionError: expected [Function] to throw error matching /FODT0001/ but got 'Not implemented: adding durations to …'. CastAs673b,Error: Casting to xs:QName is not implemented. CastAs674a,Error: Casting to xs:QName is not implemented. CastAs675a,AssertionError: expected [Function] to throw error matching /XPTY0117/ but got 'Casting to xs:QName is not implemente…' @@ -3504,8 +3476,6 @@ K-ValCompTypeChecking-27,AssertionError: expected [Function] to throw an error K-ValCompTypeChecking-28,AssertionError: expected [Function] to throw an error K-ValCompTypeChecking-29,AssertionError: expected [Function] to throw an error VarDecl020,AssertionError: declare variable $x := 9.999999999999999; $x: expected '9.999999999999998' to equal '9.999999999999999' -VarDecl046,Error: Not implemented: adding durations to xs:date -VarDecl048,Error: Not implemented: adding durations to xs:time VarDecl059,Error: No selector counterpart for: computedDocumentConstructor. vardeclerr-1,AssertionError: expected [Function] to throw error matching /XQDY0054/ but got 'Maximum call stack size exceeded' K2-InternalVariablesWithout-1a,AssertionError: expected [Function] to throw error matching /XQDY0054/ but got 'Maximum call stack size exceeded' @@ -3571,7 +3541,6 @@ K2-ExternalVariablesWith-22a,Error: 1: declare variable $v as element(*, xs:unty K2-ExternalVariablesWith-23,Error: 1: declare variable $v as element(elementName, xs:anyType?)+ := ; 1 = 1 ^ Error: XPST0003: Failed to parse script. Expected :=, , , , ,(: at <>:1:31 - 1:32 extvardef-002b,AssertionError: expected [Function] to throw error matching /XPTY0004/ but got 'FOTY0013: Atomization is not supporte…' extvardef-003a,Error: FORG0006: items passed to fn:sum are not all numeric. -extvardef-007,Error: Not implemented: adding durations to xs:date extvardef-008,AssertionError: expected [Function] to throw error matching /XPDY0002/ but got 'XQDY0054: The variable x is declared …' extvardef-011,AssertionError: expected [Function] to throw error matching /XQDY0054/ but got 'Maximum call stack size exceeded' extvardef-011a,AssertionError: expected [Function] to throw error matching /XQDY0054/ but got 'Maximum call stack size exceeded' @@ -3825,10 +3794,9 @@ functx-fn-root-1,AssertionError: Expected XPath let $in-xml := 123 functx-fn-root-all,Error: No selector counterpart for: computedDocumentConstructor. functx-fn-sum-3,Error: FORG0006: items passed to fn:sum are not all numeric. functx-fn-sum-all,Error: FORG0006: items passed to fn:sum are not all numeric. -functx-functx-add-months-1,Error: Not implemented: adding durations to xs:date -functx-functx-add-months-2,Error: Not implemented: adding durations to xs:date -functx-functx-add-months-3,Error: Not implemented: adding durations to xs:date -functx-functx-add-months-all,Error: Not implemented: adding durations to xs:date +functx-functx-add-months-2,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Adds months to a date : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_add-months.html : @param $date the date : @param $months the number of months to add :) declare function functx:add-months ( $date as xs:anyAtomicType? , $months as xs:integer ) as xs:date? { xs:date($date) + functx:yearMonthDuration(0,$months) } ; (:~ : The first argument if it is not blank, otherwise the second argument : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_if-empty.html : @param $arg the node that may be empty : @param $value the item(s) to use if the node is empty :) declare function functx:if-empty ( $arg as item()? , $value as item()* ) as item()* { if (string($arg) != '') then data($arg) else $value } ; (:~ : Construct a yearMonthDuration from a number of years and months : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_yearmonthduration.html : @param $years the number of years : @param $months the number of months :) declare function functx:yearMonthDuration ( $years as xs:decimal? , $months as xs:integer? ) as xs:yearMonthDuration { (xs:yearMonthDuration('P1M') * functx:if-empty($months,0)) + (xs:yearMonthDuration('P1Y') * functx:if-empty($years,0)) } ; (functx:add-months( xs:dateTime('2005-12-31T12:00:13'),2)): expected '2006-03-03' to equal '2006-02-28' +functx-functx-add-months-3,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Adds months to a date : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_add-months.html : @param $date the date : @param $months the number of months to add :) declare function functx:add-months ( $date as xs:anyAtomicType? , $months as xs:integer ) as xs:date? { xs:date($date) + functx:yearMonthDuration(0,$months) } ; (:~ : The first argument if it is not blank, otherwise the second argument : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_if-empty.html : @param $arg the node that may be empty : @param $value the item(s) to use if the node is empty :) declare function functx:if-empty ( $arg as item()? , $value as item()* ) as item()* { if (string($arg) != '') then data($arg) else $value } ; (:~ : Construct a yearMonthDuration from a number of years and months : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_yearmonthduration.html : @param $years the number of years : @param $months the number of months :) declare function functx:yearMonthDuration ( $years as xs:decimal? , $months as xs:integer? ) as xs:yearMonthDuration { (xs:yearMonthDuration('P1M') * functx:if-empty($months,0)) + (xs:yearMonthDuration('P1Y') * functx:if-empty($years,0)) } ; (functx:add-months('2005-12-31',-3)): expected '2005-10-01' to equal '2005-09-30' +functx-functx-add-months-all,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Adds months to a date : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_add-months.html : @param $date the date : @param $months the number of months to add :) declare function functx:add-months ( $date as xs:anyAtomicType? , $months as xs:integer ) as xs:date? { xs:date($date) + functx:yearMonthDuration(0,$months) } ; (:~ : The first argument if it is not blank, otherwise the second argument : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_if-empty.html : @param $arg the node that may be empty : @param $value the item(s) to use if the node is empty :) declare function functx:if-empty ( $arg as item()? , $value as item()* ) as item()* { if (string($arg) != '') then data($arg) else $value } ; (:~ : Construct a yearMonthDuration from a number of years and months : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_yearmonthduration.html : @param $years the number of years : @param $months the number of months :) declare function functx:yearMonthDuration ( $years as xs:decimal? , $months as xs:integer? ) as xs:yearMonthDuration { (xs:yearMonthDuration('P1M') * functx:if-empty($months,0)) + (xs:yearMonthDuration('P1Y') * functx:if-empty($years,0)) } ; (functx:add-months(xs:date('2004-01-23'),1), functx:add-months( xs:dateTime('2005-12-31T12:00:13'),2), functx:add-months('2005-12-31',-3)): expected '2004-02-23 2006-03-03 2005-10-01' to equal '2004-02-23 2006-02-28 2005-09-30' functx-functx-camel-case-to-words-1,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Turns a camelCase string into space-separated words : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_camel-case-to-words.html : @param $arg the string to modify : @param $delim the delimiter for the words (e.g. a space) :) declare function functx:camel-case-to-words ( $arg as xs:string? , $delim as xs:string ) as xs:string { concat(substring($arg,1,1), replace(substring($arg,2),'(\p{Lu})', concat($delim, '$1'))) } ; (functx:camel-case-to-words( 'thisIsACamelCaseTerm',' ')): expected 'thisIsACamelCaseTerm' to equal 'this Is A Camel Case Term' functx-functx-camel-case-to-words-2,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Turns a camelCase string into space-separated words : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_camel-case-to-words.html : @param $arg the string to modify : @param $delim the delimiter for the words (e.g. a space) :) declare function functx:camel-case-to-words ( $arg as xs:string? , $delim as xs:string ) as xs:string { concat(substring($arg,1,1), replace(substring($arg,2),'(\p{Lu})', concat($delim, '$1'))) } ; (functx:camel-case-to-words( 'thisIsACamelCaseTerm',',')): expected 'thisIsACamelCaseTerm' to equal 'this,Is,A,Camel,Case,Term' functx-functx-camel-case-to-words-all,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Turns a camelCase string into space-separated words : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_camel-case-to-words.html : @param $arg the string to modify : @param $delim the delimiter for the words (e.g. a space) :) declare function functx:camel-case-to-words ( $arg as xs:string? , $delim as xs:string ) as xs:string { concat(substring($arg,1,1), replace(substring($arg,2),'(\p{Lu})', concat($delim, '$1'))) } ; (functx:camel-case-to-words( 'thisIsACamelCaseTerm',' '), functx:camel-case-to-words( 'thisIsACamelCaseTerm',',')): expected 'thisIsACamelCaseTerm thisIsACamelCase…' to equal 'this Is A Camel Case Term this,Is,A,C…' @@ -3840,12 +3808,6 @@ functx-functx-get-matches-2,AssertionError: declare namespace functx = "http://w functx-functx-get-matches-all,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : Splits a string into matching and non-matching regions : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_get-matches-and-non-matches.html : @param $string the string to split : @param $regex the pattern :) declare function functx:get-matches-and-non-matches ( $string as xs:string? , $regex as xs:string ) as element()* { let $iomf := functx:index-of-match-first($string, $regex) return if (empty($iomf)) then {$string} else if ($iomf > 1) then ({substring($string,1,$iomf - 1)}, functx:get-matches-and-non-matches( substring($string,$iomf),$regex)) else let $length := string-length($string) - string-length(functx:replace-first($string, $regex,'')) return ({substring($string,1,$length)}, if (string-length($string) > $length) then functx:get-matches-and-non-matches( substring($string,$length + 1),$regex) else ()) } ; (:~ : Return the matching regions of a string : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_get-matches.html : @param $string the string to split : @param $regex the pattern :) declare function functx:get-matches ( $string as xs:string? , $regex as xs:string ) as xs:string* { functx:get-matches-and-non-matches($string,$regex)/ string(self::match) } ; (:~ : The first position of a matching substring : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_index-of-match-first.html : @param $arg the string : @param $pattern the pattern to match :) declare function functx:index-of-match-first ( $arg as xs:string? , $pattern as xs:string ) as xs:integer? { if (matches($arg,$pattern)) then string-length(tokenize($arg, $pattern)[1]) + 1 else () } ; (:~ : Replaces the first match of a pattern : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_replace-first.html : @param $arg the entire string to change : @param $pattern the pattern of characters to replace : @param $replacement the replacement string :) declare function functx:replace-first ( $arg as xs:string? , $pattern as xs:string , $replacement as xs:string ) as xs:string { replace($arg, concat('(^.*?)', $pattern), concat('$1',$replacement)) } ; (functx:get-matches( 'abc123def', '\d+'), functx:get-matches( 'abc123def', '\d'), functx:get-matches( 'abc123def', '[a-z]{2}')): expected '123 1 3 2 ab de ' to equal ' 123 1 2 3 ab de ' functx-functx-line-count-2,AssertionError: Expected XPath declare namespace functx = "http://www.example.com/"; (:~ : The number of lines : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_line-count.html : @param $arg the string to test :) declare function functx:line-count ( $arg as xs:string? ) as xs:integer { count(functx:lines($arg)) } ; (:~ : Split a string into separate lines : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_lines.html : @param $arg the string to split :) declare function functx:lines ( $arg as xs:string? ) as xs:string* { tokenize($arg, '(\r\n?|\n\r?)') } ; let $lines := 'a value on many lines' return (functx:line-count($lines)) to resolve to 5: expected false to be true functx-functx-line-count-all,AssertionError: declare namespace functx = "http://www.example.com/"; (:~ : The number of lines : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_line-count.html : @param $arg the string to test :) declare function functx:line-count ( $arg as xs:string? ) as xs:integer { count(functx:lines($arg)) } ; (:~ : Split a string into separate lines : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_lines.html : @param $arg the string to split :) declare function functx:lines ( $arg as xs:string? ) as xs:string* { tokenize($arg, '(\r\n?|\n\r?)') } ; let $lines := 'a value on many lines' return (functx:line-count('a value'), functx:line-count($lines)): expected '1 9' to equal '1 5' -functx-functx-next-day-1,Error: Not implemented: adding durations to xs:date -functx-functx-next-day-2,Error: Not implemented: adding durations to xs:date -functx-functx-next-day-all,Error: Not implemented: adding durations to xs:date -functx-functx-previous-day-1,Error: Not implemented: subtracting durations from xs:date -functx-functx-previous-day-2,Error: Not implemented: subtracting durations from xs:date -functx-functx-previous-day-all,Error: Not implemented: subtracting durations from xs:date functx-functx-right-trim-all,Error: 1: deep-equal((declare namespace functx = "http://www.example.com/"; ^ 2: (:~ : Trims trailing whitespace : : @author Priscilla Walmsley, Datypic : @version 1.0 : @see http://www.xqueryfunctions.com/xq/functx_right-trim.html : @param $arg the string to trim :) 3: declare function functx:right-trim ( $arg as xs:string? ) as xs:string { replace($arg,'\s+$','') } ; Error: XPST0003: Failed to parse script. Expected end of input at <>:1:11 - 1:12 functx-functx-sort-as-numeric-all,Error: No selector counterpart for: computedDocumentConstructor. functx-functx-sort-case-insensitive-all,Error: No selector counterpart for: computedDocumentConstructor.