home contribute faq download

FunctX XQuery Functions

functx:duration-from-timezone

Converts a timezone like "-05:00" or "Z" into xs:dayTimeDuration

Google
Webxqueryfunctions.com

Description

The functx:duration-from-timezone function accepts a timezone (as it appears in xs:date, xs:time, xs:dateTime etc. values) and converts it to an xs:dayTimeDuration value. The $timezone value can be Z, or in the format (+|-)HH:MM.

Arguments and Return Type

NameTypeDescription
$timezone xs:string the time zone, in (+|-)HH:MM format
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:duration-from-timezone 
  ( $timezone as xs:string )  as xs:dayTimeDuration {
       
   xs:dayTimeDuration(
     if (not(matches($timezone,'Z|[\+\-]\d{2}:\d{2}')))
     then error(xs:QName('functx:Invalid_Timezone_Value'))
     else if ($timezone = 'Z')
     then 'PT0S'
     else replace($timezone,'\+?(\d{2}):\d{2}','PT$1H')
        )
 } ;
XQuery Syntax for July 2004 - November 2005 (CR):
declare namespace functx = "http://www.functx.com"; 
declare function functx:duration-from-timezone 
  ( $timezone as xs:string )  as xdt:dayTimeDuration {
       
   xdt:dayTimeDuration(
     if (not(matches($timezone,'Z|[\+\-]\d{2}:\d{2}')))
     then error(xs:QName('functx:Invalid_Timezone_Value'))
     else if ($timezone = 'Z')
     then 'PT0S'
     else replace($timezone,'\+?(\d{2}):\d{2}','PT$1H')
        )
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function duration-from-timezone 
  ( $timezone as xs:string )  as xdt:dayTimeDuration {
       
   xdt:dayTimeDuration(
     if (fn:not(fn:matches($timezone,'Z|[\+\-]\d{2}:\d{2}')))
     then fn:error(xs:QName('functx:Invalid_Timezone_Value'))
     else if ($timezone = 'Z')
     then 'PT0S'
     else fn:replace($timezone,'\+?(\d{2}):\d{2}','PT$1H')
        )
 }

Examples

XQuery ExampleResults
functx:duration-from-timezone('Z')
PT0S
functx:duration-from-timezone('-05:00')
-PT5H
functx:duration-from-timezone('+09:00')
PT9H

See Also

functx:timezone-from-durationConverts an xs:dayTimeDuration into a timezone like "-05:00" or "Z"
fn:timezone-from-timeThe timezone portion of a time
fn:timezone-from-dateTimeThe timezone portion of a date/time

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