package com.smppw.common.timerange;

import com.smppw.constants.DateConst;
import com.smppw.common.pojo.enums.TimeRange;
import com.smppw.utils.DateUtil;

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

public class FromThisYear implements AbstractTimeRange{

    @Override
    public String generateStartDate(String endDateStr, TimeRange timeRange) {
        Date endDate = DateUtil.StringToDate(endDateStr);
        Calendar endDateCalendar = Calendar.getInstance();
        endDateCalendar.setTime(endDate);
        final int last = endDateCalendar.getActualMinimum(Calendar.DAY_OF_YEAR);
        endDateCalendar.set(Calendar.DAY_OF_YEAR, last);
        Date startDate = endDateCalendar.getTime();
        return DateUtil.DateToString(startDate, DateConst.YYYY_MM_DD);
    }
}
