private static NodeValue fixupDateOrDateTime(NodeValue nv) { if ( nv.isDateTime() ) return fixupDateTime(nv); if ( nv.isDate() ) return fixupDate(nv); throw new ARQInternalErrorException("Attempt to fixupDateOrDateTime on "+nv); }
@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 localDateTime_1() { test("afn:nowtz()", nv-> nv.isDateTime()); } // Test field defined.
@Test public void testDate1() { Calendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); // Clear/ set all fields (milliseconds included). cal.setTimeInMillis(0); // NB Months from 0, not 1 // For a date, must be time = 00:00:00 cal.set(2005, 01, 18, 0, 0, 0); NodeValue v = NodeValue.makeDate(cal); assertTrue("Not a date: " + v, v.isDate()); assertFalse("A dateTime: " + v, v.isDateTime()); // DateTimes always have nodes because we used that to parse the thing. }
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 ; }
private static DateTimeStruct parseTime(NodeValue nv) { String lex = nv.asNode().getLiteralLexicalForm() ; if ( nv.isDateTime() ) return DateTimeStruct.parseDateTime(lex) ; else if ( nv.isTime() ) return DateTimeStruct.parseTime(lex) ; else throw new ExprEvalException("Not a datatype for time") ; }
public static NodeValue dtGetDay(NodeValue nv) { if ( nv.isDateTime() || nv.isDate() || nv.isGMonthDay() || nv.isGDay() ) { DateTimeStruct dts = parseAnyDT(nv) ; return NodeValue.makeNode(dts.day, XSDDatatype.XSDinteger) ; } throw new ExprEvalException("Not a month datatype") ; }
public static NodeValue dtGetYear(NodeValue nv) { if ( nv.isDateTime() || nv.isDate() || nv.isGYear() || nv.isGYearMonth() ) { DateTimeStruct dts = parseAnyDT(nv) ; return NodeValue.makeNode(dts.year, XSDDatatype.XSDinteger) ; } throw new ExprEvalException("Not a year datatype") ; }
@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; } }
public static NodeValue dtGetMonth(NodeValue nv) { if ( nv.isDateTime() || nv.isDate() || nv.isGYearMonth() || nv.isGMonth() || nv.isGMonthDay() ) { DateTimeStruct dts = parseAnyDT(nv) ; return NodeValue.makeNode(dts.month, XSDDatatype.XSDinteger) ; } throw new ExprEvalException("Not a month datatype") ; }
@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; } }
public boolean hasDateTime() { return isDateTime() || isDate() || isTime() || isGYear() || isGYearMonth() || isGMonth() || isGMonthDay() || isGDay() ; } public boolean isDateTime() { return false ; }
@Test public void testDateTime4() { Calendar cal1 = new GregorianCalendar(); cal1.setTimeZone(TimeZone.getTimeZone("GMT")); // Clear/ set all fields (milliseconds included). cal1.setTimeInMillis(0); cal1.set(2005, 01, 18, 20, 39, 10); // NB Months from 0, not 1 NodeValue v = NodeValue.makeNode("2005-02-18T20:39:10Z", XSDDatatype.XSDdateTime); assertTrue("Not a dateTime: " + v, v.isDateTime()); assertFalse("A date: " + v, v.isDate()); assertTrue("Not a node: " + v, v.hasNode()); Calendar cal2 = v.getDateTime().toGregorianCalendar(); assertEquals("Not equal: " + v, 0, cal1.compareTo(cal2)); }
@Test public void testDate4() { Calendar cal1 = new GregorianCalendar(); cal1.setTimeZone(TimeZone.getTimeZone("GMT")); // Clear/ set all fields (milliseconds included). cal1.setTimeInMillis(0); // Must be ",0,0,0" cal1.set(2005, 01, 18, 0, 0, 0); // NB Months from 0, not 1 NodeValue v = NodeValue.makeNode("2005-02-18Z", XSDDatatype.XSDdate); assertTrue("Not a date: " + v, v.isDate()); assertFalse("A dateTime: " + v, v.isDateTime()); assertTrue("Not a node: " + v, v.hasNode()); Calendar cal2 = v.getDateTime().toGregorianCalendar(); assertEquals("Not equal: " + v, 0, cal1.compareTo(cal2)); }
@Test public void testDateTime5() { boolean b = NodeValue.VerboseWarnings; try { NodeValue.VerboseWarnings = false; // Illegal lexical for a dateTime. NodeValue v = NodeValue.makeNode("2005-02-18", XSDDatatype.XSDdateTime); assertFalse("Date!: " + v, v.isDate()); assertFalse("Datetime!: " + v, v.isDateTime()); } finally { NodeValue.VerboseWarnings = b; } }
@Test public void testDate5() { boolean b = NodeValue.VerboseWarnings; try { NodeValue.VerboseWarnings = false; // Illegal lexical for a date. NodeValue v = NodeValue.makeNode("2005-02-18T20:39:10Z", XSDDatatype.XSDdate); assertFalse("Datetime!: " + v, v.isDateTime()); assertFalse("Date!: " + v, v.isDate()); } finally { NodeValue.VerboseWarnings = b; } }
@Test public void testDateTime2() { NodeValue v = NodeValue.makeNodeDateTime("2005-02-18T20:39:10Z"); assertTrue("Not a dateTime: " + v, v.isDateTime()); assertFalse("A date: " + v, v.isDate()); assertTrue("Not a node: " + v, v.hasNode()); }
@Test public void testDate2() { NodeValue v = NodeValue.makeNodeDate("2005-02-18"); assertTrue("Not a date: " + v, v.isDate()); assertFalse("A dateTime: " + v, v.isDateTime()); assertTrue("Not a node: " + v, v.hasNode()); }
private static ValueSpaceClassification classifyValueSpace(NodeValue nv) { if ( nv.isNumber() ) return VSPACE_NUM ; if ( nv.isDateTime() ) return VSPACE_DATETIME ; if ( nv.isString()) return VSPACE_STRING ; if ( nv.isBoolean()) return VSPACE_BOOLEAN ; if ( ! nv.isLiteral() ) return VSPACE_NODE ; if ( ! SystemARQ.ValueExtensions ) return VSPACE_UNKNOWN ; // Datatypes and their value spaces that are an extension of strict SPARQL. if ( nv.isDate() ) return VSPACE_DATE ; if ( nv.isTime() ) return VSPACE_TIME ; if ( nv.isDuration() ) return VSPACE_DURATION ; if ( nv.isGYear() ) return VSPACE_G_YEAR ; if ( nv.isGYearMonth() ) return VSPACE_G_YEARMONTH ; if ( nv.isGMonth() ) return VSPACE_G_MONTH ; if ( nv.isGMonthDay() ) return VSPACE_G_MONTHDAY ; if ( nv.isGDay() ) return VSPACE_G_DAY ; if ( nv.isSortKey() ) return VSPACE_SORTKEY ; // Already a literal by this point. if ( NodeUtils.hasLang(nv.asNode()) ) return VSPACE_LANG ; return VSPACE_UNKNOWN ; }
private static DateTimeStruct parseAnyDT(NodeValue nv) { String lex = nv.asNode().getLiteralLexicalForm() ; if ( nv.isDateTime() ) return DateTimeStruct.parseDateTime(lex) ; if ( nv.isDate() ) return DateTimeStruct.parseDate(lex) ; if ( nv.isGYear() ) return DateTimeStruct.parseGYear(lex) ; if ( nv.isGYearMonth() ) return DateTimeStruct.parseGYearMonth(lex) ; if ( nv.isGMonth() ) return DateTimeStruct.parseGMonth(lex) ; if ( nv.isGMonthDay() ) return DateTimeStruct.parseGMonthDay(lex) ; if ( nv.isGDay() ) return DateTimeStruct.parseGDay(lex) ; if ( nv.isTime() ) return DateTimeStruct.parseTime(lex) ; return null ; }