package com.its.vds.stat.server.utils;

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

public class TimeUtils {
	public static final int TYPE_CURR_05MIN = 0;
	public static final int TYPE_PRCS_05MIN = 1;
	public static final int TYPE_PRCS_15MIN = 2;
	public static final int TYPE_PRCS_HOUR = 3;
	public static final int TYPE_PRCS_DAY = 4;
	public static final int TYPE_PRCS_MONTH = 5;
	public static final int TYPE_PRCS_YEAR = 6;

	public static String getCurrentTimeString() {
		Calendar cal = Calendar.getInstance();
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	public static String getCurrentTimeString(String parmaFmt) {
		Calendar cal = Calendar.getInstance();
		return (new SimpleDateFormat(parmaFmt)).format(cal.getTime());
	}

	public static Date getCurrentDate() {
		Calendar cal = Calendar.getInstance();
		return cal.getTime();
	}

	public static Date stringToDate(String paramTime) {
		SimpleDateFormat transFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		Date to = null;

		try {
			to = transFormat.parse(paramTime);
		} catch (ParseException var4) {
			var4.printStackTrace();
		}

		return to;
	}

	public static String dateToString(Date paramDt, String paramFmt) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		return (new SimpleDateFormat(paramFmt)).format(cal.getTime());
	}

	public static String dateToString(Date paramDt) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	public static long getCurrentTimeSeconds() {
		Calendar cal = Calendar.getInstance();
		return Math.round((double) cal.getTimeInMillis() / 1000.0D);
	}

	public static long getCurrentTimeMilliSeconds() {
		Calendar cal = Calendar.getInstance();
		return cal.getTimeInMillis();
	}

	public static String getFiveMinString(Date paramDt) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		cal.set(13, 0);
		cal.set(14, 0);
		int min = cal.get(12);
		cal.add(12, -(min % 5));
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	public static String getFiveMinString() {
		Calendar cal = Calendar.getInstance();
		return getFiveMinString(cal.getTime());
	}

	private static String getItsTimeString(Date paramDt, int cycle, int period) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		cal.set(13, 0);
		cal.set(14, 0);
		int min = cal.get(12);
		cal.add(12, -(min % cycle) - cycle * period);
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	private static String getItsTimeToString(Date paramDt, int type) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		switch (type) {
			case 0 :
			case 1 :
				cal.add(12, 5);
				break;
			case 2 :
				cal.add(12, 15);
				break;
			case 3 :
				cal.add(11, 1);
				break;
			case 4 :
				cal.add(5, 1);
				break;
			case 5 :
				cal.add(2, 1);
				break;
			case 6 :
				cal.add(1, 1);
		}

		cal.add(13, -1);
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	public static String getTime(int type) {
		Calendar cal = Calendar.getInstance();
		return getTime(cal.getTime(), type);
	}

	public static String getTime(String paramStr, int type) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(stringToDate(paramStr));
		return getTime(cal.getTime(), type);
	}

	public static String getTime(Date paramDt, int type) {
		switch (type) {
			case 0 :
				return getItsTimeString(paramDt, 5, 0);
			case 1 :
				return getItsTimeString(paramDt, 5, 1);
			case 2 :
				return getItsTimeString(paramDt, 15, 1);
			case 3 :
				return getItsTimeString(paramDt, 60, 1);
			case 4 :
				return getItsTimeString(paramDt, 1440, 1).substring(0, 8) + "000000";
			case 5 :
				return getItsTimeString(paramDt, 1440, 1).substring(0, 6) + "01000000";
			case 6 :
				return getItsTimeString(paramDt, 1440, 1).substring(0, 4) + "0101000000";
			default :
				return "";
		}
	}

	public static String getToTime(int type) {
		String prcsTime = getTime(type);
		return getToTime(prcsTime, type);
	}

	public static String getToTime(String paramStr, int type) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(stringToDate(paramStr));
		return getToTime(cal.getTime(), type);
	}

	public static String getToTime(Date paramDt, int type) {
		return getItsTimeToString(paramDt, type);
	}

	public static String getCurrMin() {
		Calendar cal = Calendar.getInstance();
		return getItsTimeString(cal.getTime(), 5, 0);
	}

	public static String getCurrMin(String paramStr) {
		return getItsTimeString(stringToDate(paramStr), 5, 0);
	}

	public static String getCurrMin(Date paramDt) {
		return getItsTimeString(paramDt, 5, 0);
	}

	public static String get05Min() {
		Calendar cal = Calendar.getInstance();
		return getItsTimeString(cal.getTime(), 5, 1);
	}

	public static String get05Min(String paramStr) {
		return getItsTimeString(stringToDate(paramStr), 5, 1);
	}

	public static String get05Min(Date paramDt) {
		return getItsTimeString(paramDt, 5, 1);
	}

	public static String get15Min() {
		Calendar cal = Calendar.getInstance();
		return getItsTimeString(cal.getTime(), 15, 1);
	}

	public static String get15Min(String paramStr) {
		return getItsTimeString(stringToDate(paramStr), 15, 1);
	}

	public static String get15Min(Date paramDt) {
		return getItsTimeString(paramDt, 15, 1);
	}

	public static String getHour() {
		Calendar cal = Calendar.getInstance();
		return getItsTimeString(cal.getTime(), 60, 1);
	}

	public static String getHour(String paramStr) {
		return getItsTimeString(stringToDate(paramStr), 60, 1);
	}

	public static String getHour(Date paramDt) {
		return getItsTimeString(paramDt, 60, 1);
	}

	public static String getDay() {
		Calendar cal = Calendar.getInstance();
		return getItsTimeString(cal.getTime(), 1440, 1).substring(0, 8) + "000000";
	}

	public static String getDay(String paramStr) {
		return getItsTimeString(stringToDate(paramStr), 1440, 1).substring(0, 8) + "000000";
	}

	public static String getDay(Date paramDt) {
		return getItsTimeString(paramDt, 1440, 1).substring(0, 8) + "000000";
	}

	public static String getToString(Date paramDt) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(paramDt);
		cal.add(13, -1);
		return (new SimpleDateFormat("yyyyMMddHHmmss")).format(cal.getTime());
	}

	public static String getFiveMinToString(Date paramDt) {
		String strFiveMin = getFiveMinString(paramDt);
		Date dtFiveMin = stringToDate(strFiveMin);
		return getToString(dtFiveMin);
	}

	public static String getFiveMinToString() {
		Calendar cal = Calendar.getInstance();
		return getFiveMinToString(cal.getTime());
	}
}