home contribute faq download

FunctX XQuery Functions

functx:dayTimeDuration

Construct a dayTimeDuration from a number of days, hours, etc.

Google
Webxqueryfunctions.com

Description

The functx:dayTimeDuration function constructs an xs:dayTimeDuration value from arguments representing the number of days, hours, minutes and seconds. Zero can be represented either by the number 0 or the empty sequence. If all arguments are zero or the empty sequence, it returns P0M.

Arguments and Return Type

NameTypeDescription
$days xs:decimal? the number of days
$hours xs:decimal? the number of hours
$minutes xs:decimal? the number of minutes
$seconds xs:decimal? the number of seconds
return value xs:dayTimeDuration

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:dayTimeDuration 
  ( $days as xs:decimal? ,
    $hours as xs:decimal? ,
    $minutes as xs:decimal? ,
    $seconds as xs:decimal? )  as xs:dayTimeDuration {
       
    (xs:dayTimeDuration('P1D') * functx:if-empty($days,0)) +
    (xs:dayTimeDuration('PT1H') * functx:if-empty($hours,0)) +
    (xs:dayTimeDuration('PT1M') * functx:if-empty($minutes,0)) +
    (xs:dayTimeDuration('PT1S') * functx:if-empty($seconds,0))
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:dayTimeDuration 
  ( $days as xs:decimal? ,
    $hours as xs:decimal? ,
    $minutes as xs:decimal? ,
    $seconds as xs:decimal? )  as xdt:dayTimeDuration {
       
    (xdt:dayTimeDuration('P1D') * functx:if-empty($days,0)) +
    (xdt:dayTimeDuration('PT1H') * functx:if-empty($hours,0)) +
    (xdt:dayTimeDuration('PT1M') * functx:if-empty($minutes,0)) +
    (xdt:dayTimeDuration('PT1S') * functx:if-empty($seconds,0))
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function dayTimeDuration 
  ( $days as xs:decimal? ,
    $hours as xs:decimal? ,
    $minutes as xs:decimal? ,
    $seconds as xs:decimal? )  as xdt:dayTimeDuration {
       
    (xdt:dayTimeDuration('P1D') * functx:if-empty($days,0)) +
    (xdt:dayTimeDuration('PT1H') * functx:if-empty($hours,0)) +
    (xdt:dayTimeDuration('PT1M') * functx:if-empty($minutes,0)) +
    (xdt:dayTimeDuration('PT1S') * functx:if-empty($seconds,0))
 }

Examples

XQuery ExampleResults
functx:dayTimeDuration(1,6,0,0)
P1DT6H
functx:dayTimeDuration(2.5,0,0,0)
P2DT12H
functx:dayTimeDuration(1,(),3,5.6)
P1DT3M5.6S
functx:dayTimeDuration(0,0,5,0)
PT5M
functx:dayTimeDuration(0,0,0,0)
PT0S

Depends On

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

See Also

functx:yearMonthDurationConstruct a yearMonthDuration from a number of years and months

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley