| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.functions; |
| 9 | |
| 10 | import net.sf.saxon.expr.XPathContext; |
| 11 | import net.sf.saxon.om.Sequence; |
| 12 | import net.sf.saxon.om.ZeroOrOne; |
| 13 | import net.sf.saxon.trans.XPathException; |
| 14 | import net.sf.saxon.value.CalendarValue; |
| 15 | import net.sf.saxon.value.DayTimeDurationValue; |
| 16 | |
| 17 | /** |
| 18 | * This class implements the XPath 2.0 functions |
| 19 | * adjust-date-to-timezone(), adjust-time-timezone(), and adjust-dateTime-timezone(), |
| 20 | * with two arguments |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | public class Adjust_2 extends SystemFunction { |
| 25 | |
| 26 | /** |
| 27 | * Evaluate the expression |
| 28 | * |
| 29 | * @param context the dynamic evaluation context |
| 30 | * @param arguments the values of the arguments, supplied as SequenceIterators |
| 31 | * @return the result of the evaluation, in the form of a SequenceIterator |
| 32 | * @throws net.sf.saxon.trans.XPathException |
| 33 | * if a dynamic error occurs during the evaluation of the expression |
| 34 | */ |
| 35 | public ZeroOrOne<CalendarValue> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 36 | CalendarValue in = (CalendarValue) arguments[0].head(); |
| 37 | if (in == null) { |
| 38 | return ZeroOrOne.empty(); |
| 39 | } else { |
| 40 | DayTimeDurationValue tz = (DayTimeDurationValue) arguments[1].head(); |
| 41 | if (tz == null) { |
| 42 | return new ZeroOrOne<>(in.removeTimezone()); |
| 43 | } else { |
| 44 | return new ZeroOrOne<>(in.adjustTimezone(tz)); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 |