-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added the fn:current-date Metapath function in support of #162. * Correct URL link to XPath current-date, not current-dateTime docs --------- Co-authored-by: A.J. Stein <[email protected]>
- Loading branch information
1 parent
55ee739
commit 793e73e
Showing
5 changed files
with
81 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...c/main/java/gov/nist/secauto/metaschema/core/metapath/function/library/FnCurrentDate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.metapath.function.library; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.DynamicContext; | ||
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IFunction; | ||
import gov.nist.secauto.metaschema.core.metapath.item.IItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.ISequence; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateWithTimeZoneItem; | ||
|
||
import java.util.List; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* Implements the XPath 3.1 <a href= | ||
* "https://www.w3.org/TR/xpath-functions-31/#func-current-date">fn:current-date</a> | ||
* function. | ||
*/ | ||
public final class FnCurrentDate { | ||
@NonNull | ||
static final IFunction SIGNATURE = IFunction.builder() | ||
.name("current-date") | ||
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS) | ||
.deterministic() | ||
.contextDependent() | ||
.focusIndependent() | ||
.returnType(IDateItem.type()) | ||
.returnOne() | ||
.functionHandler(FnCurrentDate::execute) | ||
.build(); | ||
|
||
private FnCurrentDate() { | ||
// disable construction | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@NonNull | ||
private static ISequence<IDateItem> execute(@NonNull IFunction function, | ||
@NonNull List<ISequence<?>> arguments, | ||
@NonNull DynamicContext dynamicContext, | ||
IItem focus) { | ||
return ISequence.of(fnCurrentDate(dynamicContext)); | ||
} | ||
|
||
/** | ||
* Implements <a href= | ||
* "https://www.w3.org/TR/xpath-functions-31/#func-current-date">fn:current-date</a>. | ||
* | ||
* @param dynamicContext | ||
* the dynamic evaluation context | ||
* @return the current date | ||
*/ | ||
@NonNull | ||
public static IDateItem fnCurrentDate(@NonNull DynamicContext dynamicContext) { | ||
return IDateWithTimeZoneItem.valueOf(dynamicContext.getCurrentDateTime()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters