[
https://issues.apache.org/jira/browse/JENA-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15320451#comment-15320451
]
ASF GitHub Bot commented on JENA-508:
-------------------------------------
Github user afs commented on a diff in the pull request:
https://github.com/apache/jena/pull/148#discussion_r66245039
--- Diff:
jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/XSDFuncOp.java ---
@@ -1554,4 +1551,55 @@ private static Duration
valueCanonicalDuration(NodeValue nv) {
// dur = ...
return dur ;
}
+
+ public static NodeValue adjustDatetimeToTimezone(NodeValue
nv1,NodeValue nv2){
+ if(nv1 == null)
+ return null;
+
+ if(!nv1.isDateTime() && !nv1.isDate() && !nv1.isTime()){
+ throw new ExprEvalException("Not a valid date, datetime or
time:"+nv1);
+ }
+
+ XMLGregorianCalendar calValue = nv1.getDateTime();
+ Boolean hasTz = calValue.getTimezone() !=
DatatypeConstants.FIELD_UNDEFINED;
+ int inputOffset = 0;
+ if(hasTz){
+ inputOffset = calValue.getTimezone();
+ }
+
+ int tzOffset = TimeZone.getDefault().getRawOffset() / (1000*60);
+ if(nv2 != null){
+ if(!nv2.isDuration()) {
+ String nv2StrValue = nv2.getString();
+ if(nv2StrValue.equals("")){
+
calValue.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
+ if(nv1.isDateTime())
+ return NodeValue.makeDateTime(calValue);
+ else if(nv1.isTime())
+ return
NodeValue.makeNode(calValue.toXMLFormat(),XSDDatatype.XSDtime);
+ else
+ return NodeValue.makeDate(calValue);
+ }
+ throw new ExprEvalException("Not a valid duration:" + nv2);
+ }
+ Duration tzDuration = nv2.getDuration();
+ tzOffset = tzDuration.getSign()*(tzDuration.getMinutes() +
60*tzDuration.getHours());
+ if(tzDuration.getSeconds() > 0)
+ throw new ExprEvalException("The timezone duration should
be an integral number of minutes");
+ int absTzOffset = java.lang.Math.abs(tzOffset);
+ if(absTzOffset > 14*60)
+ throw new ExprEvalException("The timezone should be a
duration between -PT14H and PT14H.");
+ }
+ String tzSign = (tzOffset-inputOffset) > 0 ? "" : "-";
+ Duration durToAdd =
NodeValue.makeDuration(tzSign+"PT"+java.lang.Math.abs(tzOffset-inputOffset)+"M").getDuration();
--- End diff --
Could this be done with something like
`NodeValue.xmlDatatypeFactory.createDurationDayTime(tzOffset-inputOffset)`?
It avoids string parsing.
> Add support for XPath 3 Functions
> ---------------------------------
>
> Key: JENA-508
> URL: https://issues.apache.org/jira/browse/JENA-508
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ
> Reporter: Rob Vesse
> Assignee: Alessandro Seganti
> Labels: gsoc, gsoc2015
>
> XPath 3 is now a Candidate Recommendation -
> http://www.w3.org/TR/xpath-functions-30/
> It contains many new functions and operators (particularly in the
> mathematical space) which we should consider adding into future versions of
> ARQ.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)