Class DateInterval


  • public abstract class DateInterval
    extends Object
    Abstract class for calculation of difference between two dates in days, weeks, years
    Author:
    Vladyslav Pikus
    • Method Detail

      • toDays

        public abstract Double toDays()
        Calculate a difference in full days. The result are always integer. Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "D")
        Returns:
        difference in full
      • toWeeks

        public abstract Double toWeeks​(DateInterval.Scale scale)
        Calculate a difference in weeks. If parameter has Scale.INT - the result will be calculated in full weeks, otherwise will contain a fractional part of a last uncompleted week
        Parameters:
        scale - specifies a scale of the result
        Returns:
        difference in weeks
      • toMonths

        public abstract Double toMonths​(DateInterval.Scale scale)
        Calculate a difference in months. If parameter has Scale.INT - the result will be calculated in full months, otherwise will contain a fractional part of a last uncompleted month Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "M")
        Parameters:
        scale - specifies a scale of the result
        Returns:
        difference in months
      • toYears

        public abstract Double toYears​(DateInterval.Scale scale)
        Calculate a difference in years. If parameter has Scale.INT - the result will be calculated in full years, otherwise will contain a fractional part of a last uncompleted year Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "Y")
        Parameters:
        scale - specifies a scale of the result
        Returns:
        difference in years
      • toDaysExcludeYearsAndMonths

        public abstract Double toDaysExcludeYearsAndMonths()
        Calculate a difference in full days regarding last month. Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "MD")
        Returns:
        difference in days
      • toDaysExcludeYears

        public abstract Double toDaysExcludeYears()
        Calculate a difference in full days regarding last year. Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "YD")
        Returns:
        difference in days
      • toMonthsExcludeYears

        public abstract Double toMonthsExcludeYears​(DateInterval.Scale scale)
        Calculate a difference in months regarding last year. If parameter has Scale.INT - the result will be calculated in full months, otherwise will contain a fractional part of a last uncompleted month Current implementation is an equivalent to Excel native functions DATEDIF(start, end, "YM")
        Parameters:
        scale - specifies a scale of the result
        Returns:
        difference in months
      • between

        public static DateInterval between​(Date start,
                                           Date end)
        Choose a suitable implementation for target date interval
        Parameters:
        start - start date
        end - end date
        Returns:
      • between

        public static DateInterval between​(Calendar start,
                                           Calendar end)
        Choose a suitable implementation for target date interval
        Parameters:
        start - start date
        end - end date
        Returns: