package com.example.db01;


public class Utils 
{
	
	public static final StringBuilder sb = new StringBuilder();
	
	public static final double MIN = 60 * 1000.0;
	public static final double HOUR = 60 * MIN;
	public static final double DAY = 24 * HOUR;
	public static final double MONTH = 30 * DAY;
	public static final double YEAR = 365 * DAY;
	
	
	 public static String concat(Object... objects)
	 {
		StringBuilder sb = new StringBuilder();
		sb.setLength(0);
		for (Object obj : objects) 
		{
			sb.append(obj);
		}
		return sb.toString();
	}

	public static String getTimeStr(int hour, int minute) 
	{
		 return concat(hour, ":", minute>9 ? "":"0", minute);
	}	 

	 public static String getDateStr(int year, int month, int date) 
	 {
		 return concat(year, "-", month, "-", date);
	 }
	
	 public static String getRemainingTime(long time, long now)
	 {
		 long diff = time - now;
		 if (diff < 0) return null;
		 
		 String txt = "";
		 double div = diff / DAY;
		 if (div >= 1) {
			 txt += ((int)div) + "d ";
			 diff = diff - ((int)div * (long)DAY);
		 }
		 div = diff / HOUR;
		 if (div >= 1) {
			 txt += ((int)div) + "h ";
			 diff = diff - ((int)div * (long)HOUR);
		 }
		 div = diff / MIN;
		 if (div >= 1) {
			 txt += ((int)div) + "m ";
			 diff = diff - ((int)div * (long)MIN);
		 }		 
		 
		 return txt;
	 }
	 
	 public static String getActualTime(int hour, int minute)
	 {
		 if (is24Hours()) return getTimeStr(hour, minute);
		 
		 if (hour < 12) return getTimeStr(hour, minute) + " AM";
		 else if (hour == 12) return getTimeStr(12, minute) + " PM";
		 else return getTimeStr(hour-12, minute) + " PM";
	 }
	
	 public static boolean is24Hours() 
	 {
			return true;
	}
}
