Strabon

changeset 682:a49d35fba425

over and out with addDateTimeFunc. works in select clause but in filter functions comparisons between timezoned and non-timezoned xsd datetimes (exported by this function) seem to have a problem.
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Thu Nov 01 19:52:56 2012 +0200 (2012-11-01)
parents bc88ed7620bc
children 580a09bb600c
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/link/AddDateTimeFunc.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/link/AddDateTimeFunc.java	Thu Nov 01 12:57:13 2012 +0200
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/link/AddDateTimeFunc.java	Thu Nov 01 19:52:56 2012 +0200
     1.3 @@ -2,7 +2,10 @@
     1.4  
     1.5  import java.text.SimpleDateFormat;
     1.6  import java.util.Calendar;
     1.7 +import java.util.GregorianCalendar;
     1.8  
     1.9 +import javax.xml.datatype.DatatypeConfigurationException;
    1.10 +import javax.xml.datatype.DatatypeFactory;
    1.11  import javax.xml.datatype.XMLGregorianCalendar;
    1.12  
    1.13  import org.openrdf.model.Value;
    1.14 @@ -19,7 +22,8 @@
    1.15  	
    1.16  	@Override
    1.17  	public String getURI() {
    1.18 -		return GeoConstants.stRDF+name;
    1.19 +		return "http://example.org/custom-function/addDateTime";
    1.20 +		
    1.21  	}
    1.22  
    1.23      @SuppressWarnings("deprecation")
    1.24 @@ -29,32 +33,53 @@
    1.25              throw new ValueExprEvaluationException("strdf:" + name
    1.26                      + " requires exactly 2 arguments, got " + args.length);
    1.27          }
    1.28 -        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DDThh:mm:ss"); //the format of xsd:Datetime
    1.29 -		XMLGregorianCalendar calendar=null;
    1.30 +        
    1.31 +        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD'T'hh:mm:ss"); //the format of xsd:Datetime
    1.32 +		GregorianCalendar calendar = new GregorianCalendar();
    1.33 +		GregorianCalendar cal = new GregorianCalendar(); 
    1.34 +	    DatatypeFactory dafa = null;
    1.35 +	    XMLGregorianCalendar xmlcal =null;
    1.36 +	    XMLGregorianCalendar gxml1 =null;
    1.37  
    1.38      	try {
    1.39 -    	    int minutesToAdd = Integer.parseInt(args[1].toString());
    1.40 +    		String toParse = args[1].toString().replace("^^<http://www.w3.org/2001/XMLSchema#integer>", "").replace("\"", "");
    1.41 +    		System.out.println("TO PARSE:"+ toParse);
    1.42 +    		int minutesToAdd = Integer.parseInt(toParse);
    1.43      	    String date = args[0].toString();
    1.44 -    	    Calendar cal = sdf.getCalendar();
    1.45 +    	    date = args[0].toString().replace("^^<http://www.w3.org/2001/XMLSchema#dateTime>", "").replace("\"", "");
    1.46 +    	    //cal = sdf.getCalendar();
    1.47      		cal.setTime(sdf.parse(date));
    1.48      		System.out.println("OLD TIME:"+cal.getTime());
    1.49      		cal.add(Calendar.MINUTE, minutesToAdd);
    1.50      		System.out.println("NEW TIME:"+cal.getTime());
    1.51 +    	   
    1.52      		
    1.53 -    		calendar.setYear(cal.getTime().getYear());
    1.54 -    		calendar.setYear(cal.getTime().getMonth());
    1.55 -    		calendar.setYear(cal.getTime().getDay());
    1.56 -    		calendar.setYear(cal.getTime().getHours());
    1.57 -    		calendar.setYear(cal.getTime().getMinutes());
    1.58 -    		calendar.setYear(cal.getTime().getSeconds());
    1.59 +          // xmlcal =  dafa.newXMLGregorianCalendar(cal.toString());
    1.60 +
    1.61 +    		System.out.println(cal.get(Calendar.YEAR));
    1.62 +    		System.out.println(cal.get(Calendar.MONTH));
    1.63 +    		System.out.println(cal.get(Calendar.DAY_OF_MONTH));
    1.64 +    		System.out.println(cal.get(Calendar.HOUR));
    1.65 +    		System.out.println(cal.get(Calendar.MINUTE));
    1.66 +    		System.out.println(cal.get(Calendar.MILLISECOND));
    1.67      		
    1.68      	} catch (java.text.ParseException e) {
    1.69  			// TODO Auto-generated catch block
    1.70  			e.printStackTrace();
    1.71  		}
    1.72 -		
    1.73 -		
    1.74 -        return valueFactory.createLiteral(calendar);
    1.75 +    
    1.76 +        //valueFactory.createLiteral(xmlmcal);
    1.77 +    	XMLGregorianCalendar gxml=null;
    1.78 +		try {
    1.79 +			gxml = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    1.80 +		} catch (DatatypeConfigurationException e) {
    1.81 +			// TODO Auto-generated catch block
    1.82 +			e.printStackTrace();
    1.83 +		}
    1.84 +		//gxml = dafa.newXMLGregorianCalendar(cal);
    1.85 +		Value value =  valueFactory.createLiteral(gxml);
    1.86 +		System.out.println("value="+value.toString());
    1.87 +		return value;
    1.88      }
    1.89  
    1.90