package com.android.launcher3.util;

import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeUtils {

    private static final String TAG = "TimeUtils";


    public static final String DATE_FORMAT_ALL = "yyyy.MM.dd hh:mm:ss";
    public static final String DATE_FORMAT_MM_dd = "MM月dd日";

    public static final String DATE_FORMAT_HH_MM = "HH:mm";

    public static final String[] WEEK = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};

    public static final String[] DAY = {"凌晨", "上午", "下午", "晚上"};

    public static String getTime(long millTimeStamp, String format) {
        Date date = new Date();

        date.setTime(millTimeStamp);
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String dateString = formatter.format(date);
        return dateString;
    }

    public static String getDate(long millTimeStamp, String format) {


        Date date = new Date();

        date.setTime(millTimeStamp);
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String dateString = formatter.format(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK);

        int clock = calendar.get(Calendar.HOUR_OF_DAY);


        String dayDesc = "";
        if (clock < 6) {
            dayDesc = DAY[0];
        } else if (clock < 12) {
            dayDesc = DAY[1];
        } else if (clock <= 18) {
            dayDesc = DAY[2];
        } else if (clock <= 24) {
            dayDesc = DAY[3];
        }


        if (calendar.getFirstDayOfWeek() == Calendar.SUNDAY) {
            week = week - 1;
        } else {
            week = week % 7;
        }

        StringBuilder time = new StringBuilder(dateString).append(" ").append(WEEK[week]).append(dayDesc);

        return time.toString();
    }

    public static long getTimeZeroClock() {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH),
                0, 0, 0);
        Logger.e(TAG, calendar1.getTime().getTime() + "");
        return calendar1.getTime().getTime();
    }


    public static boolean isWeekend() {

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            return true;
        } else {
            return false;
        }
    }
}
