Strabon

changeset 668:b3c5b5e0a552

Started adding support for a function that adds minutes to a dateTime value, producing a new dateTime value. Not working yet.
author constant
date Sun Oct 28 23:44:51 2012 +0200 (2012-10-28)
parents 4b2117a1b743
children 130f6aca1765
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/link/AddDateTimeFunc.java evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/link/AddDateTimeFunc.java	Sun Oct 28 23:44:51 2012 +0200
     1.3 @@ -0,0 +1,62 @@
     1.4 +package org.openrdf.query.algebra.evaluation.function.link;
     1.5 +
     1.6 +import java.text.SimpleDateFormat;
     1.7 +import java.util.Calendar;
     1.8 +
     1.9 +import javax.xml.datatype.XMLGregorianCalendar;
    1.10 +
    1.11 +import org.openrdf.model.Value;
    1.12 +import org.openrdf.model.ValueFactory;
    1.13 +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    1.14 +import org.openrdf.query.algebra.evaluation.function.Function;
    1.15 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants;
    1.16 +
    1.17 +public class AddDateTimeFunc implements Function {
    1.18 +	
    1.19 +
    1.20 +	
    1.21 +	protected static String name = "addDatetime";
    1.22 +	
    1.23 +	@Override
    1.24 +	public String getURI() {
    1.25 +		return GeoConstants.stRDF+name;
    1.26 +	}
    1.27 +
    1.28 +    @SuppressWarnings("deprecation")
    1.29 +	public Value evaluate(ValueFactory valueFactory, Value... args)
    1.30 +            throws ValueExprEvaluationException {
    1.31 +        if (args.length != 2) {
    1.32 +            throw new ValueExprEvaluationException("strdf:" + name
    1.33 +                    + " requires exactly 2 arguments, got " + args.length);
    1.34 +        }
    1.35 +        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DDThh:mm:ss"); //the format of xsd:Datetime
    1.36 +		XMLGregorianCalendar calendar=null;
    1.37 +
    1.38 +    	try {
    1.39 +    	    int minutesToAdd = Integer.parseInt(args[1].toString());
    1.40 +    	    String date = args[0].toString();
    1.41 +    	    Calendar cal = sdf.getCalendar();
    1.42 +    		cal.setTime(sdf.parse(date));
    1.43 +    		System.out.println("OLD TIME:"+cal.getTime());
    1.44 +    		cal.add(Calendar.MINUTE, minutesToAdd);
    1.45 +    		System.out.println("NEW TIME:"+cal.getTime());
    1.46 +    		
    1.47 +    		calendar.setYear(cal.getTime().getYear());
    1.48 +    		calendar.setYear(cal.getTime().getMonth());
    1.49 +    		calendar.setYear(cal.getTime().getDay());
    1.50 +    		calendar.setYear(cal.getTime().getHours());
    1.51 +    		calendar.setYear(cal.getTime().getMinutes());
    1.52 +    		calendar.setYear(cal.getTime().getSeconds());
    1.53 +    		
    1.54 +    	} catch (java.text.ParseException e) {
    1.55 +			// TODO Auto-generated catch block
    1.56 +			e.printStackTrace();
    1.57 +		}
    1.58 +		
    1.59 +		
    1.60 +        return valueFactory.createLiteral(calendar);
    1.61 +    }
    1.62 +
    1.63 +
    1.64 +
    1.65 +}
     2.1 --- a/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function	Thu Oct 25 19:25:57 2012 +0300
     2.2 +++ b/evaluation/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function	Sun Oct 28 23:44:51 2012 +0200
     2.3 @@ -6,6 +6,7 @@
     2.4  org.openrdf.query.algebra.evaluation.function.BooleanCast
     2.5  org.openrdf.query.algebra.evaluation.function.DateTimeCast
     2.6  org.openrdf.query.algebra.evaluation.function.link.SimilarTermFunc
     2.7 +org.openrdf.query.algebra.evaluation.function.link.AddDateTimeFunc
     2.8  org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbIntersectsFunc
     2.9  org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbContainsFunc
    2.10  org.openrdf.query.algebra.evaluation.function.spatial.stsparql.relation.mbb.MbbInsideFunc