| 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.DateTimeValue; |
| 15 | import net.sf.saxon.value.DateValue; |
| 16 | import net.sf.saxon.value.TimeValue; |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * This class supports the dateTime($date, $time) function |
| 21 | */ |
| 22 | |
| 23 | public class DateTimeConstructor extends SystemFunction { |
| 24 | |
| 25 | /** |
| 26 | * Evaluate the expression |
| 27 | * |
| 28 | * @param context the dynamic evaluation context |
| 29 | * @param arguments the values of the arguments, supplied as Sequences |
| 30 | * @return the result of the evaluation, in the form of a Sequence |
| 31 | * @throws net.sf.saxon.trans.XPathException |
| 32 | * if a dynamic error occurs during the evaluation of the expression |
| 33 | */ |
| 34 | public ZeroOrOne<DateTimeValue> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 35 | DateValue arg0 = (DateValue) arguments[0].head(); |
| 36 | TimeValue arg1 = (TimeValue) arguments[1].head(); |
| 37 | if (arg0 == null || arg1 == null) { |
| 38 | return ZeroOrOne.empty(); |
| 39 | } |
| 40 | return new ZeroOrOne<>(DateTimeValue.makeDateTimeValue(arg0, arg1)); |
| 41 | } |
| 42 | |
| 43 | public String getCompilerName() { |
| 44 | return "DateTimeConstructorCompiler"; |
| 45 | } |
| 46 | |
| 47 | } |
| 48 |