@Override public void inject(final SolrInputDocument document, final Object value) { final Calendar calendar = ((XSDDateTime)value).asCalendar(); final long millis = calendar.getTimeInMillis(); document.setField( Field.DATE_OBJECT, new Date(millis + calendar.getTimeZone().getOffset(millis))); }
public static NodeValue makeDate(Calendar cal) { XSDDateTime xdt = new XSDDateTime(cal) ; return new NodeValueDate(xdt) ; }
public NodeValueTime(XSDDateTime dt) { time = dt ; if (dt.getDays() != 0 && dt.getMonths() !=0 && dt.getYears() != 0) { throw new ExprException("Illegal time: "+dt) ; } if ( dt.getTimePart() == 0 ) throw new ExprException("Illegal time: "+dt) ; }
@Override public Date dateValue(Node node) { if(node.isLiteral()){ Object value = node.getLiteral().getValue(); try { if(value instanceof XSDDateTime){ return new GregorianCalendar( ((XSDDateTime)value).getYears(), ((XSDDateTime)value).getMonths() -1, ((XSDDateTime)value).getDays()).getTime(); } } catch (RuntimeException e) { /*ignore*/} return super.dateValue(node); } else { throw new IllegalArgumentException("parsed node is not an Literal"); } }
if ( ! nv.isDate() ) throw new ExprEvalTypeException("Can't cast to XSD:dateTime: "+nv) ; String x = String.format("%04d-%02d-%02dT00:00:00", xsdDT.getYears(), xsdDT.getMonths(),xsdDT.getDays()) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("%04d-%02d-%02d", xsdDT.getYears(), xsdDT.getMonths(),xsdDT.getDays()) ; return NodeValue.makeNode(x, xsd) ; String x = nf.format(xsdDT.getSeconds()) ; x = String.format("%02d:%02d:%s", xsdDT.getHours(), xsdDT.getMinutes(),x) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("%04d", xsdDT.getYears()) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("%04d-%02d", xsdDT.getYears(), xsdDT.getMonths()) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("--%02d", xsdDT.getMonths()) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("--%02d-%02d", xsdDT.getMonths(), xsdDT.getDays()) ; return NodeValue.makeNode(x, xsd) ; String x = String.format("---%02d", xsdDT.getDays()) ; return NodeValue.makeNode(x, xsd) ;
Calendar calendar = dateTime.asCalendar(); logger.debug("Month value before calendar is: " + dateTime.getMonths()); logger.debug("Calendar lexical string is: " + calendar.get(Calendar.YEAR) + "-" +
Calendar calendar = dateTime.asCalendar(); logger.debug("Day value before calendar is: " + dateTime.getDays()); logger.debug("Calendar lexical string is: " + calendar.get(Calendar.YEAR) + "-" +
private static int compareXSDDateTime(XSDDateTime dt1 , XSDDateTime dt2) { // Returns codes are -1/0/1 but also 2 for "Indeterminate" // which occurs when one has a timezone and one does not // and they are less then 14 hours apart. // F&O has an "implicit timezone" - this code implements the XMLSchema compare algorithm. int x = dt1.compare(dt2) ; if ( x == XSDDateTime.EQUAL ) return Expr.CMP_EQUAL ; if ( x == XSDDateTime.LESS_THAN ) return Expr.CMP_LESS ; if ( x == XSDDateTime.GREATER_THAN ) return Expr.CMP_GREATER ; if ( x == XSDDateTime.INDETERMINATE ) return Expr.CMP_INDETERMINATE ; throw new ARQInternalErrorException("Unexpected return from XSDDateTime.compare: "+x) ; }
/** * Return the time component of the dateTime - i.e. just the hours/mins/seconds, * and returns the values in seconds. * @throws IllegalDateTimeFieldException if there is no legal time component */ public double getTimePart() throws IllegalDateTimeFieldException { if ((mask & TIME_MASK) == 0) throw new IllegalDateTimeFieldException("Time not available"); return ((data[h]) * 60l + data[m]) * 60l + getSeconds(); }
@Override public Date dateValue(Node node) { if(node.isLiteral()){ Object value = node.getLiteral().getValue(); try { if(value instanceof XSDDateTime){ return new GregorianCalendar( ((XSDDateTime)value).getYears(), ((XSDDateTime)value).getMonths() -1, ((XSDDateTime)value).getDays()).getTime(); } } catch (RuntimeException e) { /*ignore*/} return super.dateValue(node); } else { throw new IllegalArgumentException("parsed node is not an Literal"); } }
XSDDateTime a = (XSDDateTime) v1; XSDDateTime b = (XSDDateTime) v2; return a.compare(b); } else { if (v1 instanceof Number && v2 instanceof Number) {
@Override public void inject(final SolrInputDocument document, final Object value) { document.setField(Field.DATE_OBJECT, ((XSDDateTime)value).asCalendar().getTime()); }
public static NodeValue makeDateTime(Calendar cal) { XSDDateTime xdt = new XSDDateTime(cal) ; return new NodeValueDateTime(xdt) ; }
/** * Compare two time Instant nodes. * @param n1 the first time instant (XSDDateTime) valued literal node * @param n2 the second time instant (XSDDateTime) valued literal node * @return -1 if n1 is less than n2, 0 if n1 equals n2 and +1 if n1 greater than n2 * @throws ClassCastException if either not is not numeric */ public static int compareInstants(Node n1, Node n2) { if (n1.isLiteral() && n2.isLiteral()) { Object v1 = n1.getLiteralValue(); Object v2 = n2.getLiteralValue(); if (v1 instanceof XSDDateTime && v2 instanceof XSDDateTime) { XSDDateTime a = (XSDDateTime) v1; XSDDateTime b = (XSDDateTime) v2; return a.compare(b); } } throw new ClassCastException("Non-numeric literal in compareNumbers"); }
private Date getDate(Individual individual, Property property) { Statement stmt = individual.getProperty(property); if (stmt != null) { Object obj = stmt.getObject(); if (obj instanceof Literal) { Literal lit = (Literal) obj; XSDDateTime d = (XSDDateTime) lit.getValue(); return d.asCalendar().getTime(); } } return null; } }
/** * Parse a validated date. This is invoked from * XSDDatatype.convertValidatedDataValue rather then from a local * parse method to make the implementation of XSDGenericType easier. */ @Override public Object parseValidated(String str) { int len = str.length(); int[] date = new int[TOTAL_SIZE]; int[] timeZone = new int[2]; // time // initialize to default values date[CY]=YEAR; date[M]=MONTH; date[D]=DAY; getTime(str, 0, len, date, timeZone); if ( date[utc]!=0 && date[utc]!='Z' ) { AbstractDateTime.normalize(date, timeZone); } return new XSDDateTime(date, TIME_MASK); }
@Override public Date dateTimeValue(Node node) { if(node.isLiteral()){ Object value = node.getLiteral().getValue(); try { if(value instanceof XSDDateTime){ return ((XSDDateTime)value).asCalendar().getTime(); } } catch (RuntimeException e) { /*ignore*/} return super.dateTimeValue(node); } else { throw new IllegalArgumentException("parsed node is not an Literal"); } }
/** * Parse a validated date. This is invoked from * XSDDatatype.convertValidatedDataValue rather then from a local * parse method to make the implementation of XSDGenericType easier. */ @Override public Object parseValidated(String str) { int len = str.length(); int[] date = new int[TOTAL_SIZE]; int[] timeZone = new int[2]; int end = getDate(str, 0, len, date); parseTimeZone (str, end, len, date, timeZone); if ( date[utc]!=0 && date[utc]!='Z' ) { AbstractDateTime.normalize(date, timeZone); } return new XSDDateTime(date, YEAR_MASK | MONTH_MASK | DAY_MASK); }
@Override public Date timeValue(Node node) { if(node.isLiteral()){ Object value = node.getLiteral().getValue(); try { if(value instanceof XSDDateTime){ Calendar cal = ((XSDDateTime)value).asCalendar(); cal.set(1900, 0, 1); //we need only the time return cal.getTime(); } } catch (RuntimeException e) { /*ignore*/} return super.timeValue(node); } else { throw new IllegalArgumentException("parsed node is not an Literal"); } }
/** * Create a typed literal xsd:dateTime from a Calendar object. */ @Override public Literal createTypedLiteral(Calendar cal) { Object value = new XSDDateTime(cal); LiteralLabel ll = LiteralLabelFactory.create(value, "", XSDDatatype.XSDdateTime); return new LiteralImpl(NodeFactory.createLiteral(ll), this); }