package incheon.res.rdm.com.util;

public class DateUtil {
	/**
	 * 
	 * @MethodName : toSeperatedFormat
	 * @MethodDESC : 구분자 있는 날짜형식으로 변경(yyyymmdd -> yyyy-mm-dd, yymmdd -> yy-mm-dd)
	 * @param date
	 * @param seperator
	 * @return
	 * @Author 홍성욱
	 * @created 2014. 8. 27.
	 */
	public static String toSeperatedFormat(String date, String seperator){
		String result = "";
		String tempDate = date;
		String yy;
		String yyyy;
		String mm;
		String dd;
		if(tempDate != null){
			int size = tempDate.length();
			try{
				Integer.parseInt(tempDate);
			}catch(NumberFormatException nfe){
				nfe.getStackTrace();
			}
			
			if(size == 6){
				yy = tempDate.substring(0, 2);
				mm = tempDate.substring(2, 4);
				dd = tempDate.substring(4, 6);
				result = yy + seperator + mm + seperator + dd;
			}else if(size == 8){
				yyyy = tempDate.substring(0, 4);
				mm = tempDate.substring(4, 6);
				dd = tempDate.substring(6, 8);
				result = yyyy + seperator + mm + seperator + dd;
			}else if(size > 8){
				result = tempDate.substring(0, 8);
			}else{
				result = date;
			}
		}
		return result;
	}
	
	/**
	 * 
	 * @MethodName : toNumberFormat
	 * @MethodDESC : 구분자 없는 날짜형식으로 변경(yyyy-mm-dd -> yyyymmdd)
	 * @param date
	 * @param seperator
	 * @return
	 * @Author 홍성욱
	 * @created 2014. 8. 27.
	 */
	public static String toNumberFormat(String date, String seperator){
		String result = "";
		String tempDate = date;
		String[] tempArray = {};
		
		if(tempDate != null){
			if(tempDate.length() > 8){
				tempArray = tempDate.split(seperator);
				for(int i = 0; i < tempArray.length; i++){
					result += tempArray[i];
				}
			}else{
				result = date;
			}
		}
		return result;
	}
}
