package com.tofly.xrtygis.custom.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author by 汪截流
 * @date 2020/9/2.
 */
public class Date7Utils {
    /**
     * 自定义的方法；根据周期计算下次周检时间
     *
     * @param period 相加月份
     * @return
     */
    public static Date addNextPeriod(int period, Date nowTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(nowTime);
        //增加月份
        calendar.add(Calendar.MONTH, period);
        Date time = calendar.getTime();
        return time;
    }

    /**
     * 比较时间差天数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static int distanceDate(Date startTime, Date endTime) {
        return (int) ((endTime.getTime() - startTime.getTime()) / (1000 * 3600 * 24));
    }

    /**
     * 得到某一年的全部月份
     * @param year 年份
     * @return  list
     */
    public static List<String> getInitMonthMapWithZero(String year) {
        List<String> list = new ArrayList<>();

        for (int i = 1; i <= 12 ; i++) {
            String yearMonth = "";
            if (i <= 9) {
                yearMonth = year + "-0" + i;
            } else {
                yearMonth = year + "-" + i;
            }
            list.add(yearMonth);
        }
        return list;
    }
}
