package com.willalp.common.utils;

import cn.hutool.core.date.DateUtil;


import java.text.SimpleDateFormat;
import java.util.Date;

public class PeriodUtil {


    public static Integer judgmentPeriod(Date date,String[] morningArr, String[] noonArr, String[] nightArr){
        Integer period = null;
        SimpleDateFormat df = new SimpleDateFormat("HH:mm");
        Date morningBegin = null;
        Date morningEnd = null;
        Date noonBegin = null;
        Date noonEnd = null;
        Date nightBegin = null;
        Date nightEnd = null;

        try {
            //当前时间
            date = df.parse(df.format(date));
            //早上
            morningBegin = df.parse(morningArr[0]);
            morningEnd = df.parse(morningArr[1]);
            //中午
            noonBegin = df.parse(noonArr[0]);
            noonEnd = df.parse(noonArr[1]);
            //晚上
            nightBegin = df.parse(nightArr[0]);
            nightEnd = df.parse(nightArr[1]);
            if (DateUtil.isIn(date,morningBegin,morningEnd)){
                period = 1;
            }else if (DateUtil.isIn(date,noonBegin,noonEnd)){
                period = 2;
            }else if (DateUtil.isIn(date,nightBegin,nightEnd)){
                period = 3;
            }else{
                period = 4;
            }

        }catch (Exception e){
            e.printStackTrace();
        }

        return period;
    }

}
