package com.smppw.common.rollrange.date.item;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;

/**
 * @author Yu Liu
 */
public class Day extends BaseDateTime {

    @Override
    public int between(Calendar startDate, Calendar endDate) {
        long endInstant = endDate.getTimeInMillis();
        double presumedDays = ((double) (endInstant - startDate.getTimeInMillis()) / MILLIS_IN_DAY);

        if (!Double.isNaN(presumedDays) && !Double.isInfinite(presumedDays)) {
            BigDecimal bd = new BigDecimal(presumedDays);
            BigDecimal bd1 = bd.setScale(0, RoundingMode.HALF_UP);
            presumedDays = bd1.doubleValue();
        }
        return (int) presumedDays;
    }

    @Override
    public Calendar shift(Calendar startDate, int offside) {
        startDate.add(Calendar.DAY_OF_YEAR, offside);
        return startDate;
    }

    @Override
    public Calendar startDayOfPeriod(Calendar date) {
        return date;
    }

}
