package com.gree.mall.miniapp.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

public class DateConputeUtils {

    public static Date getLastMonthStart(Date specifiedDate){
        return getMonthStart(specifiedDate,-1);
    }

    public static Date getPreviousLastMonthStart(Date specifiedDate){
        Calendar date = Calendar.getInstance();
        date.setTime(specifiedDate);
        date.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), 1, 0, 0, 0);
        date.add(Calendar.MONTH, -2);
        return getMonthStart(specifiedDate,-2);
    }

    public static Date getCurrentMonthStart(Date specifiedDate){
        Calendar date = Calendar.getInstance();
        date.setTime(specifiedDate);
        date.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), 1, 0, 0, 0);
        return date.getTime();
    }

    public static Date getCurrentDayStart(Date specifiedDate){
        Calendar date = Calendar.getInstance();
        date.setTime(specifiedDate);
        date.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        return date.getTime();
    }

    private static Date getMonthStart(Date specifiedDate,int berfore){
        Calendar date = Calendar.getInstance();
        date.setTime(specifiedDate);
        date.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), 1, 0, 0, 0);
        date.add(Calendar.MONTH, berfore);
        return date.getTime();
    }



}
