adjust-time-to-timezone
Adjusts a time to a specific timezone, or no timezone
Description
The fn:adjust-time-to-timezone function behaves differently depending on whether the $arg date value already has a time zone, and on the value of the time zone provided.
The $timezone argument is expressed as an xs:dayTimeDuration, for example -PT5H for US Eastern Standard Time. If $timezone is the empty sequence, it is assumed that the desired result is a date value that is in no time zone. If $timezone is omitted from the function call, it is assumed to be the implicit time zone.
If $arg does not already have a time zone, its date part stays the same, but it is now associated with the specified time zone. If $arg already has a time zone, its value is adjusted to that time zone.
Parameters |
Description |
|---|---|
arg:time() |
the time to adjust |
timezone:dateTime() |
the timezone to adjust it to |
Examples
XPath |
Results |
Explanation |
|---|---|---|
adjust-time-to-timezone(xs:time('17:00:00'), xs:dayTimeDuration('-PT7H')) |
17:00:00-07:00 |
|
adjust-time-to-timezone(xs:time('17:00:00-03:00'), xs:dayTimeDuration('-PT7H')) |
13:00:00-07:00 |
|
adjust-time-to-timezone(xs:time('17:00:00'), ()) |
17:00:00 |
|
adjust-time-to-timezone(xs:time('17:00:00-03:00'), ()) |
17:00:00 |
|
adjust-time-to-timezone(xs:time('17:00:00')) |
17:00:00Z |
The Mapper Idea server runs in UTC, so the implicit time zone is Z. |
adjust-time-to-timezone(xs:time('17:00:00'), xs:dayTimeDuration('-PT20H')) |
Error FODT0003 |
The following examples assume an implicit time zone of -05:00:
XPath |
Results |
Explanation |
|---|---|---|
adjust-time-to-timezone(xs:time('17:00:00-03:00')) |
20:00:00Z |
The Mapper Idea server runs in UTC, so the implicit time zone is Z. |
adjust-time-to-timezone(xs:time('22:00:00-08:00')) |
06:00:00Z |
The Mapper Idea server runs in UTC, so the implicit time zone is Z. |
adjust-time-to-timezone(xs:time('01:00:00-02:00')) |
03:00:00Z |
The Mapper Idea server runs in UTC, so the implicit time zone is Z. |
In a generator
Copy the snippet below and paste it in Freemapper, under a language node inside the generators element. Each line of the pattern prints the result of one example; to see them, run mi generate <project> <language> example-adjust-time-to-timezone. The examples that raise an error are left out, because an error stops the generation.
[e] example-adjust-time-to-timezone
[e] start
[e] match
[v] /
[e] body
[e] write-pattern
[v] examples
[e] patterns
[e] examples
[v] E01: {{ adjust-time-to-timezone(xs:time('17:00:00'), xs:dayTimeDuration('-PT7H')) }}
[v] E02: {{ adjust-time-to-timezone(xs:time('17:00:00-03:00'), xs:dayTimeDuration('-PT7H')) }}
[v] E03: {{ adjust-time-to-timezone(xs:time('17:00:00'), ()) }}
[v] E04: {{ adjust-time-to-timezone(xs:time('17:00:00-03:00'), ()) }}
[v] E05: {{ adjust-time-to-timezone(xs:time('17:00:00')) }}
[v] E07: {{ adjust-time-to-timezone(xs:time('17:00:00-03:00')) }}
[v] E08: {{ adjust-time-to-timezone(xs:time('22:00:00-08:00')) }}
[v] E09: {{ adjust-time-to-timezone(xs:time('01:00:00-02:00')) }}