package com.jpsoft.shinestar.modules.common.utils;

/**
 * @author 墨鱼_mo
 * @date 2020-4-1 13:14
 */
public class TimeZonesUtil {
    public static String getUpperTimeZone(String timeZones){
        String timeZoneStr = timeZones.substring(0,timeZones.lastIndexOf("-")+1);
        String minStr = timeZones.substring(timeZones.lastIndexOf("-")+1,timeZones.length());
        String s = minStr.replace("",".");
        Double minDou = Double.valueOf(s.substring(1,s.length()-1));
        Double timeZoneMinDou = minDou;
        String resultTimeZoneMinStr = "";
        /*String timZoneMinStr = String.valueOf(timeZoneMinDou*10);
        String resultTimeZoneMinStr = timZoneMinStr.substring(0,timZoneMinStr.indexOf("."));
        if ("0".equals(resultTimeZoneMinStr)){
            resultTimeZoneMinStr = resultTimeZoneMinStr+"0";
        }*/
        if (timeZoneMinDou.compareTo(0.5) ==-1){
            resultTimeZoneMinStr ="00";
        }
        if (timeZoneMinDou.compareTo(0.5) !=-1 && timeZoneMinDou.compareTo(1.0) ==-1){
            resultTimeZoneMinStr = "05";
        }
        if (timeZoneMinDou.compareTo(1.0) !=-1 && timeZoneMinDou.compareTo(1.5) ==-1){
            resultTimeZoneMinStr = "10";
        }
        if (timeZoneMinDou.compareTo(1.5) !=-1 && timeZoneMinDou.compareTo(2.0) ==-1){
            resultTimeZoneMinStr = "15";
        }
        if (timeZoneMinDou.compareTo(2.0) !=-1 && timeZoneMinDou.compareTo(2.5) ==-1){
            resultTimeZoneMinStr = "20";
        }
        if (timeZoneMinDou.compareTo(2.5) !=-1 && timeZoneMinDou.compareTo(3.0) ==-1){
            resultTimeZoneMinStr = "25";
        }
        if (timeZoneMinDou.compareTo(3.0) !=-1 && timeZoneMinDou.compareTo(3.5) ==-1){
            resultTimeZoneMinStr = "30";
        }
        if (timeZoneMinDou.compareTo(3.5) !=-1 && timeZoneMinDou.compareTo(4.0) ==-1){
            resultTimeZoneMinStr = "35";
        }
        if (timeZoneMinDou.compareTo(4.0) !=-1 && timeZoneMinDou.compareTo(4.5) ==-1){
            resultTimeZoneMinStr = "40";
        }
        if (timeZoneMinDou.compareTo(4.5) !=-1 && timeZoneMinDou.compareTo(5.0) ==-1){
            resultTimeZoneMinStr = "45";
        }
        if (timeZoneMinDou.compareTo(5.0) !=-1 && timeZoneMinDou.compareTo(5.5) ==-1){
            resultTimeZoneMinStr = "50";
        }
        if (timeZoneMinDou.compareTo(5.5) !=-1 && timeZoneMinDou.compareTo(6.0) ==-1){
            resultTimeZoneMinStr = "55";
        }

        String resultTimeZone = timeZoneStr + resultTimeZoneMinStr;

        return resultTimeZone;
    }

    public static String parseSecond(Long second){
        int h= Math.toIntExact(second / 3600);
        int m= Math.toIntExact((second % 3600) / 60);
        int s= Math.toIntExact((second % 3600) % 60);


        return h+"时"+m+"分"+s+"秒";
    }

    public static String friendlyTimeFormat(long time){
        long sec = 1000;
        long min = 60*sec;

        StringBuilder sb = new StringBuilder();

        if (time>min) {
            sb.append(String.format("%d分",time/min));
        }

        long remainder = time % min;

        if (remainder>sec){
            sb.append(String.format("%d秒",remainder/sec));
        }

        remainder = remainder % sec;

        sb.append(String.format("%d毫秒",remainder));

        return sb.toString();
    }
}
