Class SbTime

  • All Implemented Interfaces:
    java.lang.Comparable

    public class SbTime
    extends Inventor
    implements java.lang.Comparable
    Class for representation of a time. This class represents and performs operations on time. Operations may be done in seconds, seconds and microseconds, or using a struct timeval (defined in time.h ).

    See Also:
    SbElapsedTime
    • Constructor Summary

      Constructors 
      Constructor Description
      SbTime()
      Default constructor.
      SbTime​(double sec)
      Constructor taking seconds.
      SbTime​(long sec, long usec)
      Constructor taking seconds and microseconds.
      SbTime​(SbTime copyFrom)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(SbTime tm)
      Addition of two times which modifies the time structure.
      int compareTo​(java.lang.Object obj)  
      void divide​(double s)
      Destructive division by scalar.
      boolean equals​(java.lang.Object obj)  
      java.lang.String format()
      Calls format("%S.%i").
      java.lang.String format​(java.lang.String fmt)
      Convert to a string.
      java.lang.String formatDate()
      Calls formatDate(DEFAULT_FORMAT_DATE).
      java.lang.String formatDate​(java.lang.String fmt)
      Convert to a date string, interpreting the time as seconds since Jan 1, 1970.
      double getDoubleValue()
      Get time in seconds as a double.
      long getMsecValue()
      Get time in milliseconds (for Xt).
      static SbTime getTimeOfDay()
      Get the current time (seconds since Jan 1, 1970).
      SbTime.TimeVal getValue()
      Get time in seconds and microseconds.
      static SbTime maxTime()
      Get a time far, far into the future.
      SbTime minus​(SbTime t1)
      Subtraction of two times.
      void multiply​(double s)
      Destructive multiplication by scalar.
      SbTime over​(double s)
      Division by scalar.
      double over​(SbTime tm)
      Division by another time.
      SbTime plus​(SbTime t1)
      Addition of two times.
      SbTime remainder​(SbTime tm)
      Modulus for two times (remainder when time1 is divided by time2).
      void setMsecValue​(long msec)
      Set time from milliseconds.
      void setToTimeOfDay()
      Set to the current time (seconds since Jan 1, 1970).
      void setValue​(double sec)
      Set time from a double (in seconds).
      void setValue​(long sec, long usec)
      Set time from seconds + microseconds.
      void setValue​(SbTime copyFrom)  
      static void sleep​(int msec)
      Sleep for specified time (in msec).
      void substract​(SbTime tm)
      Subtraction of two times which modifies the time structure.
      SbTime times​(double s)
      Multiplication by scalar.
      static SbTime[] toArray​(long nativeArray, long length)  
      static void usleep​(long usec)
      Sleep for specified time (in microsec).
      static SbTime zero()
      Get a zero time.
      • Methods inherited from class java.lang.Object

        getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_FORMAT_DATE

        public static final java.lang.String DEFAULT_FORMAT_DATE
        See Also:
        Constant Field Values
    • Constructor Detail

      • SbTime

        public SbTime​(SbTime copyFrom)
      • SbTime

        public SbTime​(long sec,
                      long usec)
        Constructor taking seconds and microseconds.
      • SbTime

        public SbTime()
        Default constructor. The time value is not initialized.
      • SbTime

        public SbTime​(double sec)
        Constructor taking seconds. NOTE that an integer parameter will not automatically cast to a double to invoke the constructor taking seconds; that is, SbTime(1) will result in a compilation error. SbTime(1.0) must be used instead. This is to avoid errors in upgrading from an earlier release, in which SbTime(1) had different semantics. In future releases, this distinction will be eliminated, and the effect of SbTime(1.0) and that of SbTime(1) will be identical.
    • Method Detail

      • formatDate

        public java.lang.String formatDate()
        Calls formatDate(DEFAULT_FORMAT_DATE).
      • format

        public java.lang.String format()
        Calls format("%S.%i").
      • compareTo

        public int compareTo​(java.lang.Object obj)
        Specified by:
        compareTo in interface java.lang.Comparable
      • zero

        public static SbTime zero()
        Get a zero time.
      • getValue

        public SbTime.TimeVal getValue()
        Get time in seconds and microseconds.
      • sleep

        public static void sleep​(int msec)
        Sleep for specified time (in msec).
      • setValue

        public void setValue​(SbTime copyFrom)
      • format

        public java.lang.String format​(java.lang.String fmt)
        Convert to a string. The default format is seconds with 3 digits of fraction precision. fmt is a character string that consists of field descriptors and text characters, in a manner analogous to printf(). Each field descriptor consists of a % character followed by another character which specifies the replacement for the field descriptor. All other characters are copied from fmt into the result. The following field descriptors are supported:
          \%  the `\%' character
          D  total number of days
          H  total number of hours
          M  total number of minutes
          S  total number of seconds
          I  total number of milliseconds
          U  total number of microseconds
          h  hours remaining after the days (00-23)
          m  minutes remaining after the hours (00-59)
          s  seconds remaining after the minutes (00-59)
          i  milliseconds remaining after the seconds (000-999)
          u  microseconds remaining after the seconds (000000-999999)
        
        The uppercase descriptors are formatted with a leading `-' for negative times; the lowercase descriptors are formatted fixed width, with leading zeros. For example, a reasonable format string might be "elapsed time: \%M minutes, \%s seconds". The default value of fmt, "\%S.\%i", formats the time as seconds with 3 digits of fractional precision.
      • getMsecValue

        public long getMsecValue()
        Get time in milliseconds (for Xt).
      • toArray

        public static SbTime[] toArray​(long nativeArray,
                                       long length)
      • usleep

        public static void usleep​(long usec)
        Sleep for specified time (in microsec).
      • maxTime

        public static SbTime maxTime()
        Get a time far, far into the future. Replace the deprecated SbTime.max() method.
      • formatDate

        public java.lang.String formatDate​(java.lang.String fmt)
        Convert to a date string, interpreting the time as seconds since Jan 1, 1970. The default format gives "Tuesday, 01/26/93 11:23:41 AM". See the strftime() reference page for explanation of the format string.
      • setValue

        public void setValue​(long sec,
                             long usec)
        Set time from seconds + microseconds.
      • over

        public SbTime over​(double s)
        Division by scalar.
      • getDoubleValue

        public double getDoubleValue()
        Get time in seconds as a double.
      • divide

        public void divide​(double s)
        Destructive division by scalar.
      • times

        public SbTime times​(double s)
        Multiplication by scalar.
      • setMsecValue

        public void setMsecValue​(long msec)
        Set time from milliseconds.
      • add

        public void add​(SbTime tm)
        Addition of two times which modifies the time structure.
      • multiply

        public void multiply​(double s)
        Destructive multiplication by scalar.
      • over

        public double over​(SbTime tm)
        Division by another time.
      • substract

        public void substract​(SbTime tm)
        Subtraction of two times which modifies the time structure.
      • setToTimeOfDay

        public void setToTimeOfDay()
        Set to the current time (seconds since Jan 1, 1970).
      • getTimeOfDay

        public static SbTime getTimeOfDay()
        Get the current time (seconds since Jan 1, 1970).
      • plus

        public SbTime plus​(SbTime t1)
        Addition of two times.
      • remainder

        public SbTime remainder​(SbTime tm)
        Modulus for two times (remainder when time1 is divided by time2).
      • setValue

        public void setValue​(double sec)
        Set time from a double (in seconds).
      • equals

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

        public SbTime minus​(SbTime t1)
        Subtraction of two times.