// Path: src/org/dazzle/common/exception/BaseException.java
// public class BaseException extends RuntimeException {
// 
// 	private static final long serialVersionUID = 7369919371075409501L;
// 	
// 	private String code = null;
// 
// 	/** 获取异常编码 
// 	 * @author hcqt@qq.com*/
// 	public String getCode() {
// 		if(null != code) {
// 			return code;
// 		}
// 		return code;
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException() {
// 		super();
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException(
// 			final String code, 
// 			final String message, 
// 			final Object... msgArg) {
// 		super(MsgI18n.getMsg(code, message, msgArg));
// 		this.code = code;
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException(
// 			final String code, 
// 			final String message, 
// 			final Throwable cause, 
// 			final Object... msgArg) {
// 		super(MsgI18n.getMsg(code, message, msgArg), cause);
// 		this.code = code;
// 	}
// 
// }


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.dazzle.common.exception.BaseException;
package org.dazzle.utils;



/** @author hcqt@qq.com */
public class DateUtils {

	public static final String DEF_FMT = "yyyy-MM-dd HH:mm:ss";
	
	private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DEF_FMT);

	/** 得到几天前的时间
	 * @author hcqt@qq.com */
	public static Date getBeforeDay(Date date, Integer day) {
		if(null == date) {
			return null;
		}
		if(null == day){
			return date;
		} else {
			Calendar now = Calendar.getInstance();
			now.setTime(date);
			now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
			return now.getTime();
		}
	}

	/** 得到几天后的时间
	 * @author hcqt@qq.com */
	public static Date getAfterDay(Date date, Integer day) {
		if(null == date) {
			return null;
		}
		if(null == day){
			return date;
		} else {
			Calendar now = Calendar.getInstance();
			now.setTime(date);
			now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
			return now.getTime();
		}
	}
	
	/** @author hcqt@qq.com */
	public static final Date parse(String date, String format) {
		if(date == null || date.trim().isEmpty()) {
			return null;
		}
		DateFormat df = null;
		if(format == null || format.trim().isEmpty()) {
			df = DATE_FORMAT;
		} else {
			df = new SimpleDateFormat(format);
		}
		if(df == null) {
			df = DATE_FORMAT;
		}
		try {
			return df.parse(date);
		} catch (ParseException e) {
// Path: src/org/dazzle/common/exception/BaseException.java
// public class BaseException extends RuntimeException {
// 
// 	private static final long serialVersionUID = 7369919371075409501L;
// 	
// 	private String code = null;
// 
// 	/** 获取异常编码 
// 	 * @author hcqt@qq.com*/
// 	public String getCode() {
// 		if(null != code) {
// 			return code;
// 		}
// 		return code;
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException() {
// 		super();
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException(
// 			final String code, 
// 			final String message, 
// 			final Object... msgArg) {
// 		super(MsgI18n.getMsg(code, message, msgArg));
// 		this.code = code;
// 	}
// 
// 	/** @author hcqt@qq.com */
// 	public BaseException(
// 			final String code, 
// 			final String message, 
// 			final Throwable cause, 
// 			final Object... msgArg) {
// 		super(MsgI18n.getMsg(code, message, msgArg), cause);
// 		this.code = code;
// 	}
// 
// }


// Path: src/org/dazzle/utils/DateUtils.java
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.dazzle.common.exception.BaseException;

package org.dazzle.utils;



/** @author hcqt@qq.com */
public class DateUtils {

	public static final String DEF_FMT = "yyyy-MM-dd HH:mm:ss";
	
	private static final DateFormat DATE_FORMAT = new SimpleDateFormat(DEF_FMT);

	/** 得到几天前的时间
	 * @author hcqt@qq.com */
	public static Date getBeforeDay(Date date, Integer day) {
		if(null == date) {
			return null;
		}
		if(null == day){
			return date;
		} else {
			Calendar now = Calendar.getInstance();
			now.setTime(date);
			now.set(Calendar.DATE, now.get(Calendar.DATE) - day);
			return now.getTime();
		}
	}

	/** 得到几天后的时间
	 * @author hcqt@qq.com */
	public static Date getAfterDay(Date date, Integer day) {
		if(null == date) {
			return null;
		}
		if(null == day){
			return date;
		} else {
			Calendar now = Calendar.getInstance();
			now.setTime(date);
			now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
			return now.getTime();
		}
	}
	
	/** @author hcqt@qq.com */
	public static final Date parse(String date, String format) {
		if(date == null || date.trim().isEmpty()) {
			return null;
		}
		DateFormat df = null;
		if(format == null || format.trim().isEmpty()) {
			df = DATE_FORMAT;
		} else {
			df = new SimpleDateFormat(format);
		}
		if(df == null) {
			df = DATE_FORMAT;
		}
		try {
			return df.parse(date);
		} catch (ParseException e) {
			throw new BaseException("ser_date_39H8n", "传入的字符串\"{0}\"无法转换为时间格式\"{1}\"", e, date, ((format == null || format.trim().isEmpty() ? DEF_FMT : format)));