@Test public void testCompare16() { // One in a timezone, one not. Within +/- 14 hours. Can't compare. NodeValue nv1 = NodeValue.makeDateTime("2007-08-31T16:20:03") ; NodeValue nv2 = NodeValue.makeDateTime("2007-08-31T16:20:03Z") ; try { NodeValue.compare(nv1, nv2) ; assertFalse("Compared the uncomparable: "+nv1+" & "+nv2, true) ; } catch (ExprNotComparableException ex) {} }
@Test public void testCompare18() { // One in a timezone, one not. More than +/- 14 hours. Can compare. NodeValue nv1 = NodeValue.makeDateTime("2007-08-31T16:20:03") ; NodeValue nv2 = NodeValue.makeDateTime("2007-08-31T01:20:03Z") ; assertEquals(Expr.CMP_GREATER, NodeValue.compare(nv1, nv2)) ; }
@Test public void testDateTime8() { NodeValue v0 = NodeValue.makeDateTime("2005-02-18T20:39:10-05:00"); NodeValue v1 = NodeValue.makeDateTime("2005-02-18T17:39:10.000-08:00"); assertEquals("Not Calendar.equals: ", v0.getDateTime(), v1.getDateTime()); }
@Test public void testDateTime7() { NodeValue v0 = NodeValue.makeDateTime("2005-02-18T20:39:10Z"); NodeValue v1 = NodeValue.makeDateTime("2005-02-18T20:39:10.001Z"); assertNotSame("Calendar.equals: ", v0.getDateTime(), v1.getDateTime()); }
@Test public void testDateTime1() { Calendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); // Clear/ set all fields (milliseconds included). cal.setTimeInMillis(0); cal.set(2005, 01, 18, 20, 39, 10); // NB Months from 0, not 1 NodeValue v = NodeValue.makeDateTime(cal); assertTrue("Not a dateTime: " + v, v.isDateTime()); assertFalse("A date: " + v, v.isDate()); // DateTimes always have nodes because we used that to parse the thing. }
@Test public void exprAdjustDatetimeToTz_03() { test("fn:adjust-dateTime-to-timezone('2002-03-07T10:00:00'^^xsd:dateTime,'-PT10H'^^xsd:dayTimeDuration)",NodeValue.makeDateTime("2002-03-07T10:00:00-10:00"));}
@Test public void testSameDateTime_1() { NodeValue nv1 = NodeValue.makeDateTime("2007-09-04T09:22:03") ; NodeValue nv2 = NodeValue.makeDateTime("2007-09-04T09:22:03") ; assertTrue(NodeValue.sameAs(nv1, nv2)) ; assertFalse(NodeValue.notSameAs(nv1, nv2)) ; }
@Test public void exprAdjustDatetimeToTz_07() { test("fn:adjust-dateTime-to-timezone('2002-03-07T10:00:00'^^xsd:dateTime,'')",NodeValue.makeDateTime("2002-03-07T10:00:00"));}
private static NodeValue fixupDateTime(NodeValue nv) { DateTimeStruct dts = DateTimeStruct.parseDateTime(nv.asNode().getLiteralLexicalForm()) ; if ( dts.timezone != null ) return null ; dts.timezone = defaultTimezone ; nv = NodeValue.makeDateTime(dts.toString()) ; if ( !nv.isDateTime() ) throw new ARQInternalErrorException("Failed to reform an xsd:dateTime") ; return nv ; }
@Test public void testSameDateTime_2() { NodeValue nv1 = NodeValue.makeDateTime("2007-09-04T09:22:03") ; NodeValue nv2 = NodeValue.makeDateTime("2007-09-04T19:00:00") ; assertFalse(NodeValue.sameAs(nv1, nv2)) ; assertTrue(NodeValue.notSameAs(nv1, nv2)) ; }
@Test public void testSameDateTime_3() { // These are the same. NodeValue nv1 = NodeValue.makeDateTime("2007-09-04T10:22:03+01:00") ; NodeValue nv2 = NodeValue.makeDateTime("2007-09-04T09:22:03Z") ; assertTrue(NodeValue.sameAs(nv1, nv2)) ; assertFalse(NodeValue.notSameAs(nv1, nv2)) ; }
@Test public void testSameDateTime_4() { // These are not the same. NodeValue nv1 = NodeValue.makeDateTime("2007-09-04T10:22:03+01:00") ; NodeValue nv2 = NodeValue.makeDateTime("2007-09-04T10:22:03Z") ; assertFalse(NodeValue.sameAs(nv1, nv2)) ; assertTrue(NodeValue.notSameAs(nv1, nv2)) ; }
@Test public void testDateTime6() { NodeValue v0 = NodeValue.makeDateTime("2005-02-18T20:39:10Z"); NodeValue v1 = NodeValue.makeDateTime("2005-02-18T20:39:10.0Z"); NodeValue v2 = NodeValue.makeDateTime("2005-02-18T20:39:10.00Z"); NodeValue v3 = NodeValue.makeDateTime("2005-02-18T20:39:10.000Z"); assertEquals("Not Calendar.equals: ", v0.getDateTime(), v1.getDateTime()); assertEquals("Not Calendar.equals: ", v0.getDateTime(), v2.getDateTime()); assertEquals("Not Calendar.equals: ", v0.getDateTime(), v3.getDateTime()); }
@Test public void testBadLexcial4() { boolean b = NodeValue.VerboseWarnings; try { // Has a space String s = "2005-10-14T 09:30:23+01:00"; NodeValue.VerboseWarnings = false; NodeValue v1 = NodeValue.makeDateTime(s); assertFalse("Good date: " + v1, v1.isDateTime()); s = s.replaceAll(" ", ""); NodeValue v2 = NodeValue.makeDateTime(s); assertTrue("Bad date: " + v2, v2.isDateTime()); } finally { NodeValue.VerboseWarnings = b; } }
@Test public void testSameDateTime_5() { NodeValue nv1 = NodeValue.makeDateTime("2007-09-04T10:22:03+01:00") ; NodeValue nv2 = NodeValue.makeDateTime("2007-09-04T09:22:03") ; // No timezone try { NodeValue.sameAs(nv1, nv2) ; fail("Should not sameValueAs (but did) "+nv1+" & "+nv2) ; } catch (ExprEvalException ex) {} try { NodeValue.notSameAs(nv1, nv2) ; fail("Should not notSameValueAs (but did) "+nv1+" & "+nv2) ; } catch (ExprEvalException ex) {} }
@Test public void testBadLexcial3() { boolean b = NodeValue.VerboseWarnings; try { NodeValue.VerboseWarnings = false; NodeValue v = NodeValue.makeDateTime("2005-10-34T00:00:01Z"); assertFalse("Good date: " + v, v.isDateTime()); } finally { NodeValue.VerboseWarnings = b; } }
@Test public void testCompare11() { NodeValue nv1 = NodeValue.makeDateTime("2005-10-14T13:09:43-08:00") ; // Different timezones NodeValue nv2 = NodeValue.makeNodeDateTime("2005-10-14T13:09:43+01:00") ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_GREATER, NodeValue.compare(nv1, nv2) ) ; }
@Test public void testCompare10() { NodeValue nv1 = NodeValue.makeDateTime("2005-10-14T13:09:43Z") ; NodeValue nv2 = NodeValue.makeNodeDateTime("2005-10-14T14:09:43Z") ; assertEquals("Does not compare "+nv1+" & "+nv2, NodeValue.CMP_LESS, NodeValue.compare(nv1, nv2) ) ; }
@Test public void testDateTime3() { NodeValue v1 = NodeValue.makeDateTime("2005-02-18T20:39:10Z"); NodeValue v2 = NodeValue.makeNodeDateTime("2005-02-18T20:39:10Z"); assertEquals("Not Calendar.equals: ", v1.getDateTime(), v2.getDateTime()); }
private static void test_exprSprintf_tz_possibilites(String nodeStr, String... possible) { String exprStr = "afn:sprintf('%1$tm %1$te,%1$tY', "+NodeValue.makeDateTime(nodeStr).toString()+")" ; Expr expr = ExprUtils.parse(exprStr) ; NodeValue r = expr.eval(null, LibTestExpr.createTest()) ; assertTrue(r.isString()) ; String s = r.getString() ; // Timezones! The locale data can be -1, 0, +1 from the Z day. boolean b = false ; for (String poss : possible ) { if ( poss.equals(s) ) b = true ; } assertTrue(b) ; }