package com.ruoyi.test;


import org.apache.commons.lang3.Range;

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

public class TestDate {

    public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) throws Exception {
        Date start = format.parse("2023-01-01");
        Date end = format.parse("2023-12-31");
        splitByMonth(start, end);
    }

    public static void splitByMonth(Date start, Date end) {
//        List<Range> result = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        int index = 1;
        while (calendar.getTime().before(end)) {
            Date nextMonth = getNextMonth(calendar);
//            result.add(new Range(calendar.getTime(), nextMonth));
            System.out.println(index++ +"\t"+ format.format(nextMonth));
            calendar.setTime(nextMonth);
        }
//        return result;
    }

    public static Date getNextMonth(Calendar calendar) {
        Calendar nextMonthCalendar = Calendar.getInstance();
        nextMonthCalendar.setTime(calendar.getTime());
        nextMonthCalendar.add(Calendar.MONTH, 1);
        return nextMonthCalendar.getTime();
    }

}
