\file TimeUnit .d \brief A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units. A TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts.

Written by Doug Lea with assistance from members of JCP JSR-166 Expert Group and released to the public domain, as explained at

http:
//creativecommons.org/licenses/publicdomain Ported to D by Ben Hinkle. Email comments and bug reports to ben.hinkle@gmail.com

revision 2.0

  • enum TimeUnit ;
  • \enum TimeOut A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units, and to perform timing and delay operations in these units. A TimeUnit does not maintain time information, but only helps organize and use time representations that may be maintained separately across various contexts.

    A TimeUnit is mainly used to inform time-based methods how a given timing parameter should be interpreted. For example,

      Lock lock = ...;
      if ( lock.tryLock(50L, MilliSeconds) ) ...
     
    while this code will timeout in 50 seconds:
      Lock lock = ...;
      if ( lock.tryLock(50L, Seconds) ) ...
     


    Note however, that there is no guarantee that a particular timeout implementation will be able to notice the passage of time at the same granularity as the given TimeUnit .


  • long convert (long duration, TimeUnit fromUnit, TimeUnit toUnit);
  • Convert the given time duration in the given unit to this unit. Conversions from finer to coarser granularities truncate, so lose precision. For example converting 999 milliseconds to seconds results in 0. Conversions from coarser to finer granularities with arguments that would numerically overflow saturate to long.min if negative or long.max if positive.

    \param duration the time duration in the given unit \param fromUnit the unit of the duration argument \param toUnit the unit of the result \return the converted duration or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

  • long toNanos (long duration, TimeUnit fromUnit);
  • Convert to nanoseconds. \param duration the duration \param fromUnit the unit of the duration argument \return the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

  • long toMicros (long duration, TimeUnit fromUnit);
  • Convert to microseconds. \param duration the duration \param fromUnit the unit of the duration argument \return the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

  • long toMillis (long duration, TimeUnit fromUnit);
  • Convert to milliseconds. \param duration the duration \param fromUnit the unit of the duration argument \return the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

  • long toSeconds (long duration, TimeUnit fromUnit);
  • Convert to seconds. \param duration the duration \param fromUnit the unit of the duration argument \return the converted duration.

    :: page rendered by CandyDoc