package com.td.WaDa.game.complayerland.scheduled;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;

import java.util.Date;

/**
 * 每周是从周日到下周六
 */
public class ComPlayerDisasterDateUtil {

    /**
     * 获取本周开始时间
     * @return
     */
    public static Date getBegin() {
        Date now = new Date();
        if (Week.SUNDAY == DateUtil.dayOfWeekEnum(now)) {
            return DateUtil.beginOfDay(now);
        } else {
            return DateUtil.beginOfWeek(now).offset(DateField.DAY_OF_WEEK, -1);
        }
    }

    /**
     * 获取本周截止时间
     * @return
     */
    public static Date getEnd() {
        Date now = new Date();
        if (Week.SUNDAY == DateUtil.dayOfWeekEnum(now)) {
            return DateUtil.endOfDay(now).offset(DateField.DAY_OF_WEEK, 6);
        } else {
            return DateUtil.endOfWeek(now).offset(DateField.DAY_OF_WEEK, -1);
        }
    }
}
