home contribute faq download

FunctX XQuery Functions

functx:yearMonthDuration

Construct a yearMonthDuration from a number of years and months

Google
Webdatypic.com

Description

The functx:yearMonthDuration function constructs an xs:yearMonthDuration value from two arguments representing a number of years and a number of months. Zero can be represented either by the number 0 or the empty sequence. If both arguments are zero or the empty sequence, it returns P0M.

Arguments and Return Type

NameTypeDescription
$years xs:decimal? the number of years
$months xs:integer? the number of months
return value xs:yearMonthDuration

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
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))
 } ;

Examples

XQuery ExampleResults
functx:yearMonthDuration(1,6)
P1Y6M
functx:yearMonthDuration(1.5,0)
P1Y6M
functx:yearMonthDuration(1,())
P1Y
functx:yearMonthDuration(1,0)
P1Y
functx:yearMonthDuration(-1,-3)
-P1Y3M
functx:yearMonthDuration(-1,3)
-P9M
functx:yearMonthDuration(0,0)
P0M

Depends On

functx:if-emptyThe first argument if it is not blank, otherwise the second argument

See Also

functx:dayTimeDurationConstruct a dayTimeDuration from a number of days, hours, etc.

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery