package de.tblsoft.solr.util;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	
	public static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";

	public static String SOLR_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

	public static String date2String(Date date) {
		SimpleDateFormat sdfPipeline = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH:mm:ssZ");
		return sdfPipeline.format(date);

	}
	
	public static Date getDate(String date) {
		SimpleDateFormat sdfPipeline = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH:mm:ssZ");
		try {
			return sdfPipeline.parse(date);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static String date2String(Date date, String format) {
		SimpleDateFormat sdfPipeline = new SimpleDateFormat(
				format);
		return sdfPipeline.format(date);

	}
	
	public static Date getDate(String date, String format) {
		SimpleDateFormat sdfPipeline = new SimpleDateFormat(
				format);
		try {
			return sdfPipeline.parse(date);
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
		
	}

	public static String toSolrDate(String date) {
		DateTime jodaDate = new DateTime(date);
		DateTimeFormatter formatter = DateTimeFormat.forPattern(SOLR_DATE_FORMAT).withZone(DateTimeZone.UTC);
		return jodaDate.toString(formatter);
	}

}

@@ -181,16 +181,95 @@
 matter;%0A
+import sun.text.resources.cldr.ti.FormatData_ti_ER;%0A%0Aimport java.sql.Timestamp;
 %0Aimport 
@@ -325,24 +325,49 @@
 DateFormat;%0A
+import java.time.ZoneId;%0A
 import java.
@@ -534,24 +534,146 @@
 mm:ss'Z'%22;%0A%0A
+%09public static java.time.format.DateTimeFormatter FORMATTER = java.time.format.DateTimeFormatter.ofPattern(DATE_FORMAT);%0A%0A
 %09public stat
@@ -770,32 +770,19 @@
 %09%09%09%09
-%22yyyy-MM-dd'T'HH:mm:ssZ%22
+DATE_FORMAT
 );%0A%09
@@ -810,32 +810,193 @@
 ormat(date);%0A%0A%09%7D
+%0A%0A%09public static String timestamp2String(Timestamp timestamp, String timezone) %7B%0A%09%09return timestamp.toInstant().atZone(ZoneId.of(timezone)).format(FORMATTER);%0A%09%7D
 %0A%09%0A%09public stati

use a constant for date pattern