package com.bokecc.livemodule.utils;

import android.content.Context;

import com.bokecc.dwlivedemo.R;

import java.text.MessageFormat;

/**
 * 时间相关工具类
 */
public class TimeUtil {

    /**
     * 将long时间转化为String
     *
     * @param oriTime long
     * @return string
     */
    public static String getFormatTime(long oriTime) {
        oriTime = oriTime / 1000; // 单位为毫秒
        StringBuilder sb = new StringBuilder();

        sb.append(getFillZero(oriTime / 60));
        sb.append(":");
        sb.append(getFillZero(oriTime % 60));

        return sb.toString();
    }
    public static String secToTime(int seconds) {

        int hour = seconds / 3600;

        int minute = (seconds - hour * 3600) / 60;

        int second = (seconds - hour * 3600 - minute * 60);

        StringBuffer sb = new StringBuffer();

        if (hour > 0) {

            sb.append(hour + "小时");

        }

        if (minute > 0) {

            sb.append(minute + "分");

        }

        if (second > 0) {

            sb.append(second + "秒");

        }

        if (second == 0) {

            sb.append("<1秒");

        }

        return sb.toString();

    }


    /**
 * 填充数字
 *
 * @param number number
 * @return string
 */
    public static String getFillZero(long number) {
        if (number < 10) {
            return "0" + number;
        } else {
            return String.valueOf(number);
        }
    }

    /**
     * 将毫秒转换为年月日时分秒
     */
    public static String getYearMonthDayHourMinuteSecond(Context mContext, long timeMillis) {
        int second = (int) (timeMillis % 60);// 秒
        long totalMinutes = timeMillis / 60;
        int minute = (int) (totalMinutes % 60);// 分
        long totalHours = totalMinutes / 60;
        int hour = (int) (totalHours % 24);// 时
        int day = (int) (totalHours / 24);
        if (day > 0) {
            return mContext.getString(R.string.string_utils_count_down_day_hour_minute_second,
                    day>99?99:day, hour, minute, second);
        } else if (hour > 0) {
            return mContext.getString(R.string.string_utils_count_down_hour_minute_second,
                    hour, minute, second);
        } else if (minute > 0) {
            return mContext.getString(
                    R.string.string_utils_count_down_minute_second, minute,
                    second);
        } else {
            return mContext.getString(R.string.string_utils_count_down_second,
                    second);
        }
    }
}
