Class TimeDuration

    • Constructor Summary

      Constructors 
      Constructor Description
      TimeDuration​(int years, int months, int days, int hours, int minutes, int seconds, int milliseconds)  
      TimeDuration​(com.ibm.icu.util.Calendar cal1, com.ibm.icu.util.Calendar cal2)
      Elapsed time constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.ibm.icu.util.Calendar addToCalendar​(com.ibm.icu.util.Calendar cal)
      Add this time duration to a Calendar instance.
      int compareTo​(TimeDuration arg0)  
      int days()
      Returns the days in this time duration.
      boolean equals​(java.lang.Object obj)  
      static TimeDuration fromLong​(long duration)
      Returns a TimeDuration instance derived from an encoded long value.
      static TimeDuration fromNumber​(java.lang.Number number)
      Returns a TimeDuration instance derived from a Number instance.
      int hashCode()  
      int hours()
      Returns the hours in this time duration.
      boolean isNegative()
      Returns true if this duration is negative.
      boolean isZero()
      Returns true if this duration is zero.
      int milliseconds()
      Returns the milliseconds in this time duration.
      int minutes()
      Returns the minutes in this time duration.
      int months()
      Returns the months in this time duration.
      static TimeDuration parseDuration​(java.lang.String duration)  
      int seconds()
      Returns the seconds in this time duration.
      static long toLong​(TimeDuration duration)
      Returns a long value derived from a TimeDuration instance.
      java.lang.String toString()
      Returns a String formatted as years:months:days:hours:minutes:seconds:millseconds.
      int years()
      Returns the years in this time duration.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ZeroTimeDuration

        public static final TimeDuration ZeroTimeDuration
        A TimeDuration instance that represents a zero time duration.
      • milliseconds

        protected final int milliseconds
      • seconds

        protected final int seconds
      • minutes

        protected final int minutes
      • hours

        protected final int hours
      • days

        protected final int days
      • months

        protected final int months
      • years

        protected final int years
    • Constructor Detail

      • TimeDuration

        public TimeDuration​(int years,
                            int months,
                            int days,
                            int hours,
                            int minutes,
                            int seconds,
                            int milliseconds)
        Parameters:
        years - The number of years in this duration
        months - The number of months in this duration
        days - The number of days in this duration
        hours - The number of hours in this duration
        minutes - The number of minutes in this duration
        seconds - The number of years in this duration
        milliseconds - The number of milliseconds in this duration
      • TimeDuration

        public TimeDuration​(com.ibm.icu.util.Calendar cal1,
                            com.ibm.icu.util.Calendar cal2)
        Elapsed time constructor. The time duration will be computed from the two Calendar instances.
        Parameters:
        cal1 -
        cal2 -
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a String formatted as years:months:days:hours:minutes:seconds:millseconds.
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(TimeDuration arg0)
        Specified by:
        compareTo in interface java.lang.Comparable<TimeDuration>
      • isNegative

        public boolean isNegative()
        Returns true if this duration is negative.
        Returns:
        true if this duration is negative
      • isZero

        public boolean isZero()
        Returns true if this duration is zero.
        Returns:
        true if this duration is zero
      • milliseconds

        public int milliseconds()
        Returns the milliseconds in this time duration.
      • seconds

        public int seconds()
        Returns the seconds in this time duration.
      • minutes

        public int minutes()
        Returns the minutes in this time duration.
      • hours

        public int hours()
        Returns the hours in this time duration.
      • days

        public int days()
        Returns the days in this time duration.
      • months

        public int months()
        Returns the months in this time duration.
      • years

        public int years()
        Returns the years in this time duration.
      • addToCalendar

        public com.ibm.icu.util.Calendar addToCalendar​(com.ibm.icu.util.Calendar cal)
        Add this time duration to a Calendar instance. Returns the original Calendar instance.
        Parameters:
        cal -
        Returns:
        cal
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • fromLong

        public static TimeDuration fromLong​(long duration)
        Returns a TimeDuration instance derived from an encoded long value. This method is intended to be used in tandem with the toLong method. Note: this method should not be used to calculate elapsed time - use the elapsed time constructor instead.
        Parameters:
        duration - An encoded duration
        Returns:
        A TimeDuration instance
      • fromNumber

        public static TimeDuration fromNumber​(java.lang.Number number)
        Returns a TimeDuration instance derived from a Number instance. If number is null, returns a zero TimeDuration.

        This is a convenience method intended to be used with entity engine fields. Some duration fields are stored as a Long, while others are stored as a Double. This method will decode both types.

        Parameters:
        number - A Number instance, can be null
        Returns:
        A TimeDuration instance
      • parseDuration

        public static TimeDuration parseDuration​(java.lang.String duration)
      • toLong

        public static long toLong​(TimeDuration duration)
        Returns a long value derived from a TimeDuration instance. This method is intended to be used in tandem with the fromLong method.
        Parameters:
        duration -
        Returns:
        the duration encoded as a long value