package ua.be.wee.model.util;

import java.sql.Timestamp;
import java.util.Calendar;

import org.apache.jena.atlas.lib.DateTimeUtils;

public class DateTimeConverter {
	
	public static Timestamp convertSPARQLDateTimeToTimestamp(String dateTimeSparql) {
		String[] split = dateTimeSparql.split("T");
		return Timestamp.valueOf(split[0].substring(0) + " " + split[1].substring(0,8));
	}

	public static String convertTimestampToSPARQLdateTime(Timestamp timestamp) {
		Calendar instance = Calendar.getInstance();
		instance.setTime(timestamp);
		String converted = DateTimeUtils.calendarToXSDDateTimeString(instance);
		converted = "\"" + converted + "\"^^<http://www.w3.org/2001/XMLSchema#dateTime>";
		return converted;
	}
}
