package ve.gob.cnti.receiver.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Logger;


public class ConverDate implements IConvertDate{
	
	private static final Logger log = Logger.getLogger(ConverDate.class.getName());
	

	
	
	public String getFormattedTimeStampDate(String pattern, String date) {
		String fecha = null;
		log.info("convirtiendo fecha");
		date=date.replace("<?xml version=\"1.0\" ?><date>", "").replace("</date>", "").trim();
		try {
			DateFormat df = new SimpleDateFormat("yyyy-mm-dd HH:MM:ss",
					Locale.ENGLISH);
			Date dateObj = df.parse(date);
			fecha = new SimpleDateFormat(pattern,Locale.ENGLISH).format(dateObj);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		return fecha;
	}
	
	public String getFormattedLongDateDate(String pattern, String date) {
		String fecha = null;
		log.info("convirtiendo fecha");
		date=date.replace("<?xml version=\"1.0\" ?><date>", "").replace("</date>", "").trim();
		try {
			DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy",
					Locale.ENGLISH);
			Date dateObj = df.parse(date);
			fecha = new SimpleDateFormat(pattern,Locale.ENGLISH).format(dateObj);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		return fecha;
	}
	
	
	
	public String getFormattedShortDateDate(String pattern, String date) {
		String fecha = null;
		log.info("convirtiendo fecha");
		date=date.replace("<?xml version=\"1.0\" ?><date>", "").replace("</date>", "").trim();
		try {
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd",
					Locale.ENGLISH);
			Date dateObj = df.parse(date);
			fecha = new SimpleDateFormat(pattern,Locale.ENGLISH).format(dateObj);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		return fecha;
	}
	
	

	

}
