Skip to content

Commit

Permalink
Implemented adujst-time-to-timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
ales004 committed Jun 4, 2016
1 parent 5dcb82b commit 739a2a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,8 @@ public static NodeValue adjustDatetimeToTimezone(NodeValue nv1,NodeValue nv2){
if(nv1 == null)
return null;

if(!nv1.isDateTime() && !nv1.isDate()){
throw new ExprEvalException("Not a valid date or datetime:"+nv1);
if(!nv1.isDateTime() && !nv1.isDate() && !nv1.isTime()){
throw new ExprEvalException("Not a valid date, datetime or time:"+nv1);
}

XMLGregorianCalendar calValue = nv1.getDateTime();
Expand All @@ -1575,6 +1575,8 @@ public static NodeValue adjustDatetimeToTimezone(NodeValue nv1,NodeValue nv2){
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);
}
Expand All @@ -1595,6 +1597,8 @@ public static NodeValue adjustDatetimeToTimezone(NodeValue nv1,NodeValue nv2){
calValue.setTimezone(tzOffset);
if(nv1.isDateTime())
return NodeValue.makeDateTime(calValue);
else if(nv1.isTime())
return NodeValue.makeNode(calValue.toXMLFormat(),XSDDatatype.XSDtime);
else
return NodeValue.makeDate(calValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static void loadStdDefs(FunctionRegistry registry)
// 9.6.2 fn:adjust-date-to-timezone
add(registry, xfn+"adjust-date-to-timezone", FN_AdjustDatetimeToTimezone.class) ;
// 9.6.3 fn:adjust-time-to-timezone
add(registry, xfn+"adjust-time-to-timezone", FN_AdjustDatetimeToTimezone.class) ;
// 9.8.1 fn:format-dateTime
// 9.8.2 fn:format-date
// 9.8.3 fn:format-time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,28 @@ private String getDynamicDurationString(){
@Test public void exprAdjustDateToTz_05(){test("fn:adjust-date-to-timezone('2002-03-07'^^xsd:date,'')",NodeValue.makeDate("2002-03-07"));}

@Test public void exprAdjustDateToTz_06(){test("fn:adjust-date-to-timezone('2002-03-07-07:00'^^xsd:date,'')",NodeValue.makeDate("2002-03-07"));}

@Test public void exprAdjustTimeToTz_01(){
testEqual(
"fn:adjust-time-to-timezone('10:00:00'^^xsd:time)",
"fn:adjust-time-to-timezone('10:00:00'^^xsd:time,'"+getDynamicDurationString()+"'^^xsd:dayTimeDuration)");
}

@Test public void exprAdjustTimeToTz_02(){
testEqual(
"fn:adjust-time-to-timezone('10:00:00-07:00'^^xsd:time)",
"fn:adjust-time-to-timezone('10:00:00-07:00'^^xsd:time,'"+getDynamicDurationString()+"'^^xsd:dayTimeDuration)");
}

@Test public void exprAdjustTimeToTz_03(){test("fn:adjust-time-to-timezone('10:00:00'^^xsd:time,'-PT10H'^^xsd:dayTimeDuration)",NodeValue.makeNode("10:00:00-10:00",XSDDatatype.XSDtime));}

@Test public void exprAdjustTimeToTz_04(){test("fn:adjust-time-to-timezone('10:00:00-07:00'^^xsd:time,'-PT10H'^^xsd:dayTimeDuration)",NodeValue.makeNode("07:00:00-10:00",XSDDatatype.XSDtime));}

@Test public void exprAdjustTimeToTz_05(){test("fn:adjust-time-to-timezone('10:00:00'^^xsd:time,'')",NodeValue.makeNode("10:00:00",XSDDatatype.XSDtime));}

@Test public void exprAdjustTimeToTz_06(){test("fn:adjust-time-to-timezone('10:00:00-07:00'^^xsd:time,'')",NodeValue.makeNode("10:00:00",XSDDatatype.XSDtime));}

@Test public void exprAdjustTimeToTz_07(){test("fn:adjust-time-to-timezone('10:00:00-07:00'^^xsd:time,'PT10H'^^xsd:dayTimeDuration)",NodeValue.makeNode("03:00:00+10:00",XSDDatatype.XSDtime));}
//@Test public void exprStrJoin() { test("fn:string-join('a', 'b')", NodeValue.makeString("ab")) ; }

@Test public void exprSameTerm1() { test("sameTerm(1,1)", TRUE) ; }
Expand Down

0 comments on commit 739a2a3

Please sign in to comment.