Package ucar.nc2.time

Class CalendarPeriod

java.lang.Object
ucar.nc2.time.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
  • Field Details

  • Method Details

    • 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(int value, CalendarPeriod.Field field)
    • 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
    • of

      public static CalendarPeriod of(TimeDuration td)
    • multiply

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

      public int getValue()
    • getField

      public CalendarPeriod.Field getField()
    • 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
    • getOffset

      public int getOffset(CalendarDate start, CalendarDate end)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object