Package ucar.nc2.time

Class CalendarPeriod


  • @Immutable
    public class CalendarPeriod
    extends Object
    A CalendarPeriod is a logical duration of time, it requires a Calendar to convert to an actual duration of time. A CalendarField is expressed as {integer x Field}. Design follows joda Period class.
    Since:
    3/30/11
    • Method Detail

      • fromUnitString

        public static CalendarPeriod.Field fromUnitString​(String udunit)
        Convert a period string into a CalendarPeriod.Field.
        Parameters:
        udunit - period string
        Returns:
        CalendarPeriod.Field enum
        Throws:
        IllegalArgumentException - if not valid format
      • of

        public static CalendarPeriod of​(String udunit)
        Convert a udunit period string into a CalendarPeriod
        Parameters:
        udunit - period string : "[val] unit"
        Returns:
        CalendarPeriod or null if illegal
      • multiply

        public CalendarPeriod multiply​(int value)
        Multiply the period by an integer
        Parameters:
        value - multiply by this
        Returns:
        new period
      • getValue

        public int getValue()
      • subtract

        public int subtract​(CalendarDate start,
                            CalendarDate end)
        Subtract two dates, return difference in units of this period. If not even, will round to nearest int
        Parameters:
        start - start date
        end - end date
        Returns:
        difference in units of this period
      • getConvertFactor

        public double getConvertFactor​(CalendarPeriod from)
        Get the conversion factor of the other CalendarPeriod to this one
        Parameters:
        from - convert from this
        Returns:
        conversion factor, so that getConvertFactor(from) * from = this
      • getValueInMillisecs

        public double getValueInMillisecs()
        Deprecated.
        dont use because these are fixed length and thus approximate.
        Get the duration in milliseconds -+
        Returns:
        the duration in seconds
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object