package com.eactive.eai.rms.common.util;

import java.io.StringWriter;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import edu.emory.mathcs.backport.java.util.Collections;

public class CommonUtil {

	private static final Logger logger = Logger.getLogger(CommonUtil.class);
	private static final String DEFAULT_DELIMITER = "";
	
	private static final DateTimeFormatter SDF_YYYYMMDDHHMMSS                  =  DateTimeFormatter.ofPattern( "yyyyMMddHHmmss");
    private static final DateTimeFormatter SDF_YYYYMMDDHHMMSSMS_SLASH_CEMI_COL =  DateTimeFormatter.ofPattern( "yyyy/MM/dd  HH:mm:ss.SSS" );
    
    @Deprecated
    public static Object getBean(HttpServletRequest request, String beanId)
            throws Exception {
        ServletContext ctx = request.getSession().getServletContext();
        WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(ctx);

        return context.getBean(beanId);
    }

    public static String getThisWeekStart( String base ) {
        Calendar cal = getCalendar(base);
        int week = cal.get(Calendar.DAY_OF_WEEK);
        
        int date = 0 ;
        switch( week ) {
        case Calendar.SUNDAY:
            date = 1 ;
            break;
        case Calendar.MONDAY:
            date = 2 ;
            break;
        case Calendar.TUESDAY:
            date = 3 ;
            break;
        case Calendar.WEDNESDAY:
            date = 4 ;
            break;
        case Calendar.THURSDAY:
            date = 5 ;
            break;
        case Calendar.FRIDAY:
            date = 6 ;
            break;
        case Calendar.SATURDAY:
            date = 7 ;
            break;
        }
        
        return getDiffHourDate(base, date*-24, "yyyyMMdd");
    }
    
    public static String getThisWeekEnd( String base ) {
        Calendar cal = getCalendar(base);
        int week = cal.get(Calendar.DAY_OF_WEEK);
        
        int date = 0 ;
        switch( week ) {
        case Calendar.SUNDAY:
            date = 5 ;
            break;
        case Calendar.MONDAY:
            date = 4 ;
            break;
        case Calendar.TUESDAY:
            date = 3 ;
            break;
        case Calendar.WEDNESDAY:
            date = 2 ;
            break;
        case Calendar.THURSDAY:
            date = 1 ;
            break;
        case Calendar.FRIDAY:
            date = 0 ;
            break;
        case Calendar.SATURDAY:
            date = -1 ;
            break;
        }
        
        return getDiffHourDate(base, date*24, "yyyyMMdd");
    }

    public static String getToday(String format) {        
        Date date = new Date();
        return getToday( date, format );
    }
    
    public static String getZeroToday() {
    	return getToday("yyyyMMdd") + "000000" ;
    }
    
    public static String getToday( Date date, String format ) {
        if( format == null || "".equals(format) ) {
            format = "yyyyMMddHHmmss" ;
        }
        
        TimeZone tz;
        DateFormat df = new SimpleDateFormat(format);

        tz = TimeZone.getTimeZone("Asia/Seoul");
        df.setTimeZone(tz);
        
        return df.format(date);
    }

    public static String getDiffHourDate( String base, int hour, String format ) {
        
        Calendar cal = getCalendar(base);
        
        cal.add( Calendar.HOUR_OF_DAY, hour);
        Date date = cal.getTime();
        
        return getToday( date, format );
    }
    
    public static String getDiffDayDate( String base, int days, String format ) {
        
        Calendar cal = getCalendar(base);
        
        cal.add( Calendar.DAY_OF_YEAR, days);
        Date date = cal.getTime();
        
        return getToday( date, format );
    }

    public static String getDiffMinDate( String base, int min, String format ) {
        Calendar cal = getCalendar(base);
        
        cal.add( Calendar.MINUTE, min);
        Date date = cal.getTime();
        
        return getToday( date, format);
    }
    
    public static String getDiffSecDate( String base, int sec, String format ) {
        Calendar cal = getCalendar(base);
        
        cal.add( Calendar.SECOND, sec);
        Date date = cal.getTime();
        
        return getToday( date, format);    	
    }
    
    public static String getRecentDivMin( String currTime, int min ) {
    	
    	if( currTime.length() > 12 ) {
    		currTime = currTime.substring(0,12) + "00" ;
    	}
    	
    	String date = getDiffMinDate( currTime, 1, "" );
    	while( true ) {
    		date = getDiffMinDate( date, -1, "" );
    		int minTmp = getInt(date.substring(10,12));
    		if( minTmp % min == 0 ) {
    			break;
    		}
    	}
    	
    	
    	
    	return date ;
    }

    public static long getTimeMillis( String d1, String d2 ) {
        
        d1 = d1.trim();
        d2 = d2.trim();
        
        if( d1.length() == 16 ) {
            d1 = d1 + "0" ;
        }
        
        if( d2.length() == 16 ) {
            d2 = d2 + "0" ;
        }
        
        Calendar c1 = getCalendar(d1);
        Calendar c2 = getCalendar(d2);
        
        return c2.getTimeInMillis() - c1.getTimeInMillis();
    }

    public static String getAddDate(String date) throws Exception 
	{
		String datePattern = "yyyyMMdd";
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(datePattern);
		LocalDate localDate = LocalDate.parse(date,dtf).plusDays(-1);

		String addDateTime = localDate.format(dtf);
		
		return addDateTime;
	}
    
    public static String getNextDate(String date) throws Exception 
	{
		String datePattern = "yyyyMMdd";
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(datePattern);
		LocalDate localDate = LocalDate.parse(date,dtf).plusDays(1);

		String addDateTime = localDate.format(dtf);
		
		return addDateTime;
	}
    
    public static String getdelDate(String date , long day) throws Exception 
  	{
  		String datePattern = "yyyyMMdd";
  		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(datePattern);
  		LocalDate localDate = LocalDate.parse(date,dtf).minusDays(day);

  		String addDateTime = localDate.format(dtf);
  		
  		return addDateTime;
  	}

    public static long getCountDate(String startDate, String endDate) throws Exception 
	{
		String datePattern = "yyyyMMdd";
		DateTimeFormatter dtf = DateTimeFormatter.ofPattern(datePattern);
		LocalDate startLocalDate = LocalDate.parse(startDate,dtf);
		LocalDate endLocalDate = LocalDate.parse(endDate,dtf);

		long countDate = ChronoUnit.DAYS.between(startLocalDate,endLocalDate);
		
		return countDate;
	}
    
    public static String convertLocal2UTC(String datetime) throws Exception
	{
		LocalDateTime localDateTime = LocalDateTime.parse(datetime, SDF_YYYYMMDDHHMMSS);
		ZonedDateTime zonedDateTimeLocal = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Seoul"));
		ZonedDateTime zonedDateTimeUTC = zonedDateTimeLocal.withZoneSameInstant(ZoneOffset.UTC);
		
		return zonedDateTimeUTC.format(SDF_YYYYMMDDHHMMSS);
	}
    
    public static String convertUTC2Local(String datetime) throws Exception
	{
		LocalDateTime localDateTime = LocalDateTime.parse(datetime, SDF_YYYYMMDDHHMMSSMS_SLASH_CEMI_COL);
		ZonedDateTime zonedDateTimeUTC = ZonedDateTime.of(localDateTime, ZoneOffset.UTC);
		ZonedDateTime zonedDateTimeLocal = zonedDateTimeUTC.withZoneSameInstant(ZoneId.of("Asia/Seoul"));
		
		return zonedDateTimeLocal.format(SDF_YYYYMMDDHHMMSSMS_SLASH_CEMI_COL);
	}

	public static String convertLocal2UTCSlash(String datetime) throws Exception
	{
		LocalDateTime localDateTime = LocalDateTime.parse(datetime, SDF_YYYYMMDDHHMMSSMS_SLASH_CEMI_COL);
		ZonedDateTime zonedDateTimeUTC = ZonedDateTime.of(localDateTime, ZoneId.of("Asia/Seoul"));
		ZonedDateTime zonedDateTimeLocal = zonedDateTimeUTC.withZoneSameInstant(ZoneOffset.UTC);
		
		return zonedDateTimeLocal.format(SDF_YYYYMMDDHHMMSSMS_SLASH_CEMI_COL);
	}

    public static String setQuery(String header, String table, String tail) {
        StringBuilder query = new StringBuilder();
        return query.append(header).append(table).append(tail).toString();
    }

    public static String getMapString(Map<String, ?> map, String delimiter) {
        if (map == null) {
            return "";
        }

        if (delimiter == null) {
            delimiter = DEFAULT_DELIMITER;
        }

        StringBuilder sb = new StringBuilder();
        
        for (Map.Entry<String, ?> entry : map.entrySet()) {
            if (sb.length() > 0) {
                sb.append(delimiter);
            }
            
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(String.valueOf(entry.getValue()));
        }
        
        return sb.toString();
    }

	public static String getMapString(Map<String, ?> map, boolean newLineBetweenEntries) {
		String delimiter = newLineBetweenEntries ? "\n" : DEFAULT_DELIMITER;
		return getMapString(map, delimiter);
	}

	public static String getMapString(Map<String, ?> map) {
		return getMapString(map, DEFAULT_DELIMITER);
	}
    
    public static String getArrayString(Object[] array, String delimiter) {
    	if( array == null) return null;
    	if( delimiter == null ) delimiter = "";

        StringBuffer sb = new StringBuffer();
        sb.append("[");
        for(int i=0; i< array.length-1; i++ ) {
        	sb.append(array[i]).append(delimiter);        	
        }
        sb.append("]");
        sb.append(array[array.length-1]);
    	return sb.toString();
    }
    public static boolean getBooleanForSuccess(HashMap map) {
        boolean result = true;
    	if (map == null)
            return false;
        
        Iterator it = map.keySet().iterator();
       // StringBuffer sb = new StringBuffer();
        while (it.hasNext()) {
            String key = (String) it.next();
            String value = (String) map.get(key);
            if (!"success".equals(value)){
            	result = false;
            }
        }

        return result;
    }    
    
    public static String getDump(Throwable t) {
        StringWriter sw = new StringWriter();
       // PrintWriter pw = new PrintWriter(sw);
        //t.printStackTrace(pw);
        return sw.toString();
    }

    public static int getInt(String val) {
        if (val == null || val.equals("")) {
            return 0;
        }

        try {
            return Integer.parseInt(val.trim());
        } catch (Exception e) {
        	logger.error("getInt error",e);
        }

        return 0;
    }
    
    public static double getDouble(String val) {
        if( val == null || val.equals("") ) {
            return 0 ;
        }
        
        try {
            return Double.parseDouble(val.trim());
        } catch ( Exception e ) {
        	logger.error("getDouble error",e);
        }
        
        return 0 ;
    }

    public static Calendar getCalendar(String date) {
        Calendar ret = Calendar.getInstance();
        date = date.trim();
        int len = date.length();
        int[] tmp = { 0, 0, 0, 0, 0, 0, 0 };
        if (len == 8) {
            tmp[0] = getInt(date.substring(0, 4));
            tmp[1] = getInt(date.substring(4, 6));
            tmp[2] = getInt(date.substring(6));
        } else if (len == 12) {
            tmp[0] = getInt(date.substring(0, 4));
            tmp[1] = getInt(date.substring(4, 6));
            tmp[2] = getInt(date.substring(6, 8));
            tmp[3] = getInt(date.substring(8, 10));
            tmp[4] = getInt(date.substring(10));
        } else if (len == 14) {
            tmp[0] = getInt(date.substring(0, 4));
            tmp[1] = getInt(date.substring(4, 6));
            tmp[2] = getInt(date.substring(6, 8));
            tmp[3] = getInt(date.substring(8, 10));
            tmp[4] = getInt(date.substring(10, 12));
            tmp[5] = getInt(date.substring(12));
        } else if (len == 16 || len == 17) {
            tmp[0] = getInt(date.substring(0, 4));
            tmp[1] = getInt(date.substring(4, 6));
            tmp[2] = getInt(date.substring(6, 8));
            tmp[3] = getInt(date.substring(8, 10));
            tmp[4] = getInt(date.substring(10, 12));
            tmp[5] = getInt(date.substring(12, 14));
            tmp[6] = getInt(date.substring(14));
        } else if (len == 20 ) {
            // micro -> milli
            tmp[0] = getInt(date.substring(0, 4));
            tmp[1] = getInt(date.substring(4, 6));
            tmp[2] = getInt(date.substring(6, 8));
            tmp[3] = getInt(date.substring(8, 10));
            tmp[4] = getInt(date.substring(10, 12));
            tmp[5] = getInt(date.substring(12, 14));
            tmp[6] = getInt(date.substring(14));
            
            tmp[6] = tmp[6] / 1000 ; // micro sec -> milli sec
        } else {
            return ret;
        }

        ret.set(tmp[0], tmp[1] - 1, tmp[2], tmp[3], tmp[4], tmp[5]);
        ret.set(Calendar.MILLISECOND, tmp[6]);

        return ret;
    }

    public static String getLogTable(Calendar cal, boolean isMain) {
        int week = cal.get(Calendar.DAY_OF_WEEK);

        String table = "TSEAILG1";
        if (isMain == false) {
            table = "TSEAILG2";
        }
        return table + week;
    }
    
    public static String getLogTableWithPrefix(String tablePrefix, String date) {
        
        return getLogTableWithPrefix(tablePrefix, getCalendar(date));
    }
    public static String getLogTableWithPrefix(String tablePrefix, Calendar cal) {
        int week = cal.get(Calendar.DAY_OF_WEEK);
        return tablePrefix + week;
    }
 /*   public static String getLogTable(Calendar cal, boolean isMain) {
        String date = StringUtils.leftPad(String.valueOf(cal.get(Calendar.DATE)),2,"0");

        StringBuffer sb = new StringBuffer();
        if( isMain ) sb.append("TSEAILM"); else sb.append("TSEAILD");
        sb.append(date);
        
        return sb.toString();
    }*/

    public static String getLogTable(String date, boolean isMain) {
        return getLogTable(getCalendar(date), isMain);
    }
    
    public static String getLogErrTable(String date ) {
    	Calendar cal = getCalendar(date);
        int week = cal.get(Calendar.DAY_OF_WEEK);

        String table = "TSEAILG3";

        switch (week) {
        case Calendar.SUNDAY:
            return table + "1";
        case Calendar.MONDAY:
            return table + "2";
        case Calendar.TUESDAY:
            return table + "3";
        case Calendar.WEDNESDAY:
            return table + "4";
        case Calendar.THURSDAY:
            return table + "5";
        case Calendar.FRIDAY:
            return table + "6";
        case Calendar.SATURDAY:
            return table + "7";
        }

        return "";
    }
//    public static String getLogErrTable(String date ) {
//    	Calendar cal = getCalendar(date);
//        String dd = StringUtils.leftPad(String.valueOf(cal.get(Calendar.DATE)),2,"0");
//
//        StringBuffer sb = new StringBuffer();
//        sb.append("TSEAILE");
//        sb.append(dd);
//        return sb.toString();
//    }
    
    public static boolean betweenDate( String base, String start, String end ) {

        if( compareDate(start, base) >= 0 ) {
            if( compareDate(base, end) >= 0 ) {
                return true;
            }
        }
        
        return false ;
    }

    public static int compareDate(String start, String end) {
        if (start.length() > 8) {
            start = start.substring(0, 8);
        }

        if (end.length() > 8) {
            end = end.substring(0, 8);
        }

        Calendar s = getCalendar(start);
        Calendar e = getCalendar(end);

        int diff = 0;
        if (e.after(s)) {
            while (e.after(s)) {
                diff++;
                s.add(Calendar.DATE, 1);
            }
        } else if (e.before(s)) {
            while (e.before(s)) {
                diff--;
                e.add(Calendar.DATE, 1);
            }
        } else {
            // same date
        }

        return diff;
    }

    public static int compareTime(String start, String end ) {
        Calendar s = getCalendar(start);
        Calendar e = getCalendar(end);
        return e.compareTo(s);
    }

    public static String leftPadString(String src, int cnt, String padStr) {
        StringBuffer sb = new StringBuffer();

        if( src == null ) src = "" ;
        
        int size = 0 ;
        if( !"".equals( src ) ) {
            size = src.getBytes().length ;
        }
        
        for (int i = 0; i < (cnt - size); i++) {
          sb.append(padStr);
        }
        return sb.toString() + src;
    }

    public static String rightPadString(String src, int cnt, String padStr) {
        StringBuffer sb = new StringBuffer();
        
        if( src == null ) src = "" ;
        
        int size = 0 ;
        if( !"".equals( src ) ) {
            size = src.getBytes().length ;
        }
        
        for( int i = 0 ; i < (cnt - size); i++) {
            sb.append(padStr);
        }
        return src + sb.toString();
    }

    public static void stamp( Log logger, String msg ) {
        logger.debug("[" + getToday("") + "]:" + msg );
    }
    

    public static String leftTrim( String before , char t ) {
        String after = "" ;
        
        if( before == null || "".equals(before) ) {
            return after ;
        }
        
        if( before.startsWith("" + t) ) {
            for( int i = 0 ; i < before.length() ; i++ ) {
                if( before.charAt(i) != t ) {
                    after = before.substring(i);
                    break;
                }
            }
        } else {
            after = before ;
        }
        
        return after ;
    }
    
    public static String nullTrim( String str ) {
        if( str == null || "".equals(str) )
            return "" ;
        else
            return str.trim();
    }
    
    public static String rightTrim( String str, String t ) {
    	if( str == null || "".equals(str) ) {
    		return "" ;
    	}
    	
    	while( true ) {
    		if( str.endsWith(t) ) {
    			str = str.substring(0, str.length() - t.length() );
    		} else {
    			break;
    		}
    	}
    	
    	return str ;    	
    }
    
    public static String leftString( String str, int size ) {
        if( str == null || "".equals(str) ) {
            return "" ;
        }
        
        int len = str.length();
        if( size >= len ) {
            return str ;
        } else {
            return str.substring(0, size);
        }
    }
    
    public static String rightString( String str, int size ) {
        if( str == null || "".equals(str) ) {
            return "" ;
        }
        
        int len = str.length();
        if( size >= len ) {
            return str ;
        } else {
            return str.substring(len - size);
        }
    }
    
    public static Object objTrim( Object obj ) {
        if( obj != null ) {
            if( obj instanceof String ) {
                String str = (String)obj;
                str = str.trim();
                obj = str;
            }
        }        
        return obj;
    }
    
    public static String getByteSub( byte[] line, int s, int e ) {
        if( line != null ) {
            byte[] ret = new byte[line.length+1];
            int step = 0 ;
            for( int i = s ; i < line.length ; i++ ) {
                if( e == -1 || i < e) {
                    ret[step++] = line[i];
                } else {
                    break;
                }
            }
            ret[step] = 0 ;
            return new String(ret).trim() ;
        }

        return "" ;
    }
    
    public static String getByteSub( byte[] line, int s ) {
        return getByteSub(line, s, -1);
    }
        
    public static String removeArrayTag( String src ) {
        if( src == null || "".equals(src) ) {
            return "" ;
        }
        
        int s = src.indexOf('[');
        int e = src.indexOf(']');
        String ret = src ;
        while( s > -1 && e > -1 ) {
            ret = src.substring(0, s) + src.substring(e+1);
            
            src = ret ;
            s = src.indexOf('[');
            e = src.indexOf(']');
        }
        
        return ret ;
     }
    
    public static String getFormattedDate(String srcFormat, String srcDate, String tgtFormat) throws ParseException {
		if (srcDate == null || "".equals(srcDate.trim()))
			return "";
		
		DateFormat formatter = new SimpleDateFormat(srcFormat);
        Date date = (Date)formatter.parse(srcDate);
        
        formatter = new SimpleDateFormat(tgtFormat);
        String tgtDate = formatter.format(date);
		
		return tgtDate;
    }    

    public static boolean checkNode(String server, int port, int timeout) {
    	if( port < 2 ) {
    		port = 23 ;
    	}
    	
    	boolean ret = false ;
    	  
    	SocketAddress socketAddress = new InetSocketAddress(server, port);
    	Socket socket = new Socket();    	
    	try {
        	socket.connect(socketAddress, timeout);    		
    		ret = true ;
    	} catch (SocketTimeoutException e){
    		logger.error("SocketTimeoutException :" + socketAddress);
    	} catch (ConnectException e){
    		logger.error("Connection refused: connect" + socketAddress);
    	} catch( Exception e ) {
    		//e.printStackTrace();   
    		logger.error("checkNode error",e);
    	} finally {
    		try {
        		socket.close();
    		} catch ( Exception e2 ) {
    		}
    	}
    	
    	return ret ;
    }
    
    public static List<String> getDistinctList( List<String> list, boolean isSort ) {
    	HashMap map = new HashMap();
    	List<String> ret = new ArrayList<String>();
    	
    	if( list != null ) {
    		for( String s : list ) {
    			map.put(s,s);
    		}
    		Iterator it = map.keySet().iterator();
    		while( it.hasNext() ) {
    			ret.add((String)it.next());
    		}
    		
    		// sort
    		if( isSort ) {
    			Collections.sort( ret );
    		}
    	}
    	
    	return ret ;   	
    }
    
    public static String getTimeoutErrorCodes() {
    	StringBuffer sb = new StringBuffer();
    	sb.append("'RECEAIOSA777',");
    	sb.append("'RECEAIOHP003',");
    	sb.append("'RECEAIOSP004',");
    	sb.append("'RECEAIOTC913',");
    	sb.append("'RECEAIOSA010',");
    	sb.append("'RECEAIOEP010',");
    	sb.append("'RECEAIOHP010',");
    	sb.append("'RECEAIOSP010',");
    	sb.append("'RECEAIOTP010'");
    	
    	return sb.toString();
    }
    
    

    public static String toTimeFormat(String time) {
      if (time == null || time.length() < 6) {
       return time;
      }
            StringBuffer sb = new StringBuffer();
      
      sb.append(time.substring(0,2));
      sb.append(":");
      sb.append(time.substring(2,4));
      sb.append(":");
      sb.append(time.substring(4,6));
      
      if(time.length() > 6) {
       sb.append(".");
       sb.append(time.substring(6));
      }
      return sb.toString();
     }
    
    public static String getSimpleFormatTime( String time ) {
    	if( time == null || "".equals(time) ) {
    		return "" ;
    	}
    	
    	if( time.length() > 8 ) {
    		time = time.substring(8);
    	}
    	
    	return toTimeFormat(time) ;
    }
    
    public static String getThisTime() {
    	return getToday("HH:mm");
    }
//TODO JUN     
//    public static String getDataSourceName(ServiceType service) {
// 		String dsName = CommonConstants.DB_COMMON ;
// 		if( "INST1".equals(service.getKey()) ) {
// 			dsName = CommonConstants.DB_INST1_D;
// 		} else if( "INST2".equals(service.getKey()) ){
// 			dsName = CommonConstants.DB_INST2_D;
// 		} else if( "INST3".equals(service.getKey()) ) {
// 			dsName = CommonConstants.DB_INST3_D;
// 		} else if( "INST4".equals(service.getKey()) ) {
// 			dsName = CommonConstants.DB_INST4_D;
// 		}
// 		
// 		return dsName ;
//    }
    
    public static boolean getThisSchedule(String times, String delimiter) {
    	if( delimiter == null ) delimiter = ";";
		Calendar current = Calendar.getInstance();
    	current.set(Calendar.SECOND, 0);
    	current.set(Calendar.MILLISECOND, 0);
    	
    	try {
	    	String[] time     = times.split( delimiter );
	    	for( int i=0 ; i < time.length; i++) {
	    		logger.debug("time:"     + time[i]);
	    		if( time[i].matches("[0-9]{4}") ) {
	    	        DateFormat df = new SimpleDateFormat("HHmm");
	    	        df.parse(time[i]);
	    	        
	        		Calendar start = Calendar.getInstance();
	        		start.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[i].substring(0, 2)));
	        		start.set(Calendar.MINUTE, Integer.parseInt(time[i].substring(2, 4)));
	        		start.set(Calendar.SECOND, 0);
	        		start.set(Calendar.MILLISECOND, 0);
	        		
	        		Calendar end = (Calendar) start.clone();
	        		end.add(Calendar.MINUTE, 10);
	        		end.set(Calendar.SECOND, 0);
	        		end.set(Calendar.MILLISECOND, 0);
	        		logger.debug("����ð��� : " + start.get(Calendar.HOUR_OF_DAY) + ":" + start.get(Calendar.MINUTE) + " ~ " + end.get(Calendar.HOUR_OF_DAY) + ":" + end.get(Calendar.MINUTE));
	        		logger.debug("getThisSchedule[" + current.get(Calendar.HOUR_OF_DAY) + ":" + current.get(Calendar.MINUTE) +"][" + 
							        				 current.compareTo(start) + "][" + current.compareTo(end) + "][" + 
							        				 (current.compareTo(start) >= 0 && current.compareTo(end) == -1) + "]");
	        		logger.debug("current:" + current);
	        		logger.debug("start:" + start);
	        		logger.debug("end:" + end);
	        		if( current.compareTo(start) >= 0 && current.compareTo(end) == -1 ) {
	        			return true;
	        		}
	    		}
	    	}
    	} catch(Exception e) {
    		//e.printStackTrace();
    		logger.error("getThisSchedule error",e);
    	}
    	
    	return false; 
    }

    private static ZonedDateTime get(){
		return ZonedDateTime.now();
	}
    
    
    public static String getCurrentDateTime() {
        return (SDF_YYYYMMDDHHMMSS).format(get());
    }
    
//    public static void main(String[] argv) {
//    	String base = "20200119";
//    	int days = -30;
//    	System.out.println(base + ":" + days + " = " + CommonUtil.getDiffDayDate(base, days, "yyyyMMdd"));
//    }
    
}