home contribute faq download

FunctX XQuery Functions

functx:timezone-from-duration

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

Google
Webdatypic.com

Description

The functx:timezone-from-duration function accepts an xs:dayTimeDuration and converts it to a timezone value (formatted as it appears in xs:date, xs:time, xs:dateTime etc. values). The dayTimeDuration may only have the hours (H) component (or the seconds component if the value is PT0S) and must be between -PT14H and PT14H inclusive.

Arguments and Return Type

NameTypeDescription
$duration xs:dayTimeDuration the duration
return value xs:string

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:timezone-from-duration
  ( $duration as xs:dayTimeDuration )  as xs:string {

   if (string($duration) = ('PT0S','-PT0S'))
   then 'Z'
   else if (matches(string($duration),'-PT[1-9]H'))
   then replace(string($duration),'PT([1-9])H','0$1:00')
   else if (matches(string($duration),'PT[1-9]H'))
   then replace(string($duration),'PT([1-9])H','+0$1:00')
   else if (matches(string($duration),'-PT1[0-4]H'))
   then replace(string($duration),'PT(1[0-4])H','$1:00')
   else if (matches(string($duration),'PT1[0-4]H'))
   then replace(string($duration),'PT(1[0-4])H','+$1:00')
   else error(xs:QName('functx:Invalid_Duration_Value'))
 } ;

Examples

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

See Also

functx:duration-from-timezoneConverts a timezone like "-05:00" or "Z" into xs:dayTimeDuration
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
Datypic XQuery Services

Recommended Reading:

XQuery