Class CalendarDateUnit


  • @Immutable
    public class CalendarDateUnit
    extends Object
    A Calendar Date Unit: "[CALENDAR] unit SINCE baseDate". Its main job is to convert "value unit since baseDate" to a CalendarDate.
    • Field Detail

      • unixDateUnit

        public static final CalendarDateUnit unixDateUnit
        "seconds since the Unix epoch".
    • Method Detail

      • fromUdunitString

        public static Optional<CalendarDateUnit> fromUdunitString​(@Nullable
                                                                  Calendar calt,
                                                                  String udunitString)
        Create a CalendarDateUnit from a calendar and a udunit string = "unit since calendarDate"
        Parameters:
        calt - use this Calendar, or null for default calendar
        udunitString - "unit since calendarDate"
        Returns:
        CalendarDateUnit or empty if udunitString is not parseable
      • of

        public static CalendarDateUnit of​(CalendarPeriod.Field periodField,
                                          boolean isCalendarField,
                                          CalendarDate baseDate)
        Create a CalendarDateUnit from a CalendarPeriod.Field, and a base date
        Parameters:
        periodField - a CalendarPeriod.Field like Hour or second
        baseDate - "since baseDate"
        Returns:
        CalendarDateUnit
      • of

        public static CalendarDateUnit of​(CalendarPeriod period,
                                          boolean isCalendarField,
                                          CalendarDate baseDate)
        Create a CalendarDateUnit from a CalendarPeriod, and a base date
        Parameters:
        period - a CalendarPeriod like 1 Hour or 30 seconds
        baseDate - "since baseDate"
        Returns:
        CalendarDateUnit
      • fromAttributes

        public static Optional<CalendarDateUnit> fromAttributes​(AttributeContainer atts,
                                                                @Nullable
                                                                String units)
        Create a CalendarDateUnit from attributes.
        Parameters:
        atts - AttributeContainer, look for 'units' attribute and 'calendar' attribute
        units - the units string, may be null
        Returns:
        CalendarDateUnit if possible
      • getBaseDateTime

        public CalendarDate getBaseDateTime()
        The base date "[CALENDAR] unit SINCE baseDate".
      • getCalendar

        public Calendar getCalendar()
        The Calendar used (default proleptic_gregorian).
      • getCalendarField

        public CalendarPeriod.Field getCalendarField()
        The period field taken from the unit: "[CALENDAR] unit SINCE baseDate".
      • getCalendarPeriod

        public CalendarPeriod getCalendarPeriod()
        The period taken from the unit: "[CALENDAR] unit SINCE baseDate".
      • isCalendarField

        public boolean isCalendarField()
        Was CALENDAR specified? Only affects Period.Month, Period.Year.
      • makeCalendarDate

        public CalendarDate makeCalendarDate​(long value)
        Add the given integer (value * period) to the baseDateTime to make a new CalendarDate.
        Parameters:
        value - number of periods to add. May be negative.
      • makeOffsetFromRefDate

        public long makeOffsetFromRefDate​(CalendarDate date)
        Find the offset of date in integral units of this period from the baseDateTime. Inverse of makeCalendarDate. TODO not working when period is month, see TestCalendarDateUnit
      • makeFractionalCalendarDate

        public CalendarDate makeFractionalCalendarDate​(double value)
        Add the given (value * period) to the baseDateTime to make a new CalendarDate. Inverse of makeFractionalOffsetFromRefDate. This uses makeCalendarDate when its a calendar date or uses a non-ISO calendar, and rounds the value to a long.
        Parameters:
        value - number of (possibly non-integral) periods to add. May be negative.
      • makeFractionalOffsetFromRefDate

        public double makeFractionalOffsetFromRefDate​(CalendarDate date)
        Find the offset of date in fractional units of this period from the baseDateTime. Inverse of makeFractionalCalendarDate. This uses makeOffsetFromRefDate when its a calendar date or uses a non-ISO calendar, and rounds the value to a long.
        Returns:
        number of (possibly non-integral) periods since base date. May be negative.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object