op:multiply-yearMonthDuration

Multiplies $yearMonthDuration-var with $decimal-var.

Signatures

op:multiply-yearMonthDuration(xf:yearMonthDuration $yearMonthDuration-var, xs:decimal $decimal-var) —> xf:yearMonthDuration

Arguments

Data Type
Argument
Description

xf:yearMonthDuration

$yearMonthDuration-var

Contains a time duration that can contain years and months.

xs:decimal

$decimal-var

Contains a decimal value, for example: 1.1.

Returns

Returns the yearMonthDuration value of dividing $yearMonthDuration-var with $decimal-var. The return value is rounded up to the nearest month and year as shown in the following example.

Examples

Round Up

Multiplying the 1 year value of $yearMonthDuration-var by 1.5 results in 1 year and 6 months. Multiplying the 1 month value of $yearMonthDuration-var by 1.5 results in 1.5 months which is rounded up to 2 months. Adding 1 year and 6 months to 2 months results in a yearMonthDuration of 1 year and 8 months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1Y1M")
return
let $decimal-var := 1.5
return
let $mydur := op:multiply-yearMonthDuration($yearMonthDuration-var, $decimal-var)
return
<result>
	<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
	<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</result> 

The preceding query generates the following result:

<result>
	<years>1</years>
	<months>8</months>
</result> 

Not Enough to Round Up

Multiplying a 1 month yearMonthDuration by 0.49 results in 0.49 months which is rounded down to zero months as shown in the following example query:

let $yearMonthDuration-var := xf:yearMonthDuration("P1M")
return
let $decimal-var := 0.49
return
let $mydur := op:multiply-yearMonthDuration($yearMonthDuration-var, $decimal-var)
return
<result>
	<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
	<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</result> 

The preceding query generates the following result:

<result>
	<years>0</years>
	<months>0</months>
</result> 

Related Topics

W3C multiply-yearMonthDuration operator description.

W3C yearMonthDuration description.

xf:yearMonthDuration constructor description.