package org.codiki.core.utils;

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

public class DateUtils {
	private static final String FORMAT_DEFAULT = "dd/MM/yyyy HH:mm:ss";

	public static Date parseDate(String pSource, String pPattern) throws ParseException {
		Date result = null;
		if (pSource != null && !pSource.isEmpty()) {
			DateFormat formatter = getSimpleDateFormat(pPattern);
			formatter.setLenient(false);
			result = formatter.parse(pSource);
		}
		return result;
	}
	
	public static String format(Date pDate, String pPattern) {
        return getSimpleDateFormat(pPattern).format(pDate);
    }
	
	public static String format(Date pDate) {
        return getSimpleDateFormat(FORMAT_DEFAULT).format(pDate);
    }

	private static SimpleDateFormat getSimpleDateFormat(String pPattern) {
		SimpleDateFormat result = new SimpleDateFormat(pPattern, Locale.FRENCH);
		result.setLenient(false);
		return result;
	}
}
