Class DateUnit


  • public class DateUnit
    extends Object
    A date unit is a unit for durations that span one or more days. The known date units are defined as constants of this class.
    See Also:
    DateDuration
    • Method Detail

      • getDurationString

        public String getDurationString​(int n)
        Returns a date duration string for the specified number of this date unit. For example, if this date unit is MONTH and you set n to 3, this method will return "3 months".
        Parameters:
        n - the number of date units
        Returns:
        the date duration string
      • parse

        public static DateUnit parse​(String s,
                                     DateUnit min,
                                     DateUnit max)
                              throws IllegalArgumentException
        Parses a date unit string. The string can be a singular or plural form of the date unit. You can specify the smallest and largest allowed date unit.
        Parameters:
        s - the string
        min - the smallest allowed date unit. You can set this to null for the smallest known date unit.
        max - the largest allowed date unit. You can set this to null for the largest known date unit.
        Returns:
        the date unit
        Throws:
        IllegalArgumentException - if the string is invalid
      • getDateUnits

        public static DateUnit[] getDateUnits​(DateUnit min,
                                              DateUnit max)
        Returns the known date units between the specified smallest and largest date unit.
        Parameters:
        min - the smallest date unit to return. You can set this to null for the smallest known date unit.
        max - the largest date unit to return. You can set this to null for the largest known date unit.
        Returns:
        the date units