Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

TimeUnit.d File Reference

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. More...

Go to the source code of this file.

Enumerations

enum  TimeUnit { NanoSeconds = 0, MicroSeconds, MilliSeconds, Seconds }

Functions

static long doConvert (int delta, long duration)
long convert (long duration, TimeUnit fromUnit, TimeUnit toUnit)
long toNanos (long duration, TimeUnit fromUnit)
long toMicros (long duration, TimeUnit fromUnit)
long toMillis (long duration, TimeUnit fromUnit)
long toSeconds (long duration, TimeUnit fromUnit)

Variables

module mango locks TimeUnit
const int[TimeUnit.max+1] multipliers
const long[TimeUnit.max+1] overflows


Detailed Description

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

Definition in file TimeUnit.d.


Enumeration Type Documentation

enum TimeUnit
 

Enumeration values:
NanoSeconds 
MicroSeconds 
MilliSeconds 
Seconds 

Definition at line 44 of file TimeUnit.d.


Function Documentation

static long doConvert int  delta,
long  duration
[static, private]
 

Perform conversion based on given delta representing the difference between units

Parameters:
delta the difference in index values of source and target units
duration the duration
Returns:
converted duration or saturated value

Definition at line 78 of file TimeUnit.d.

References multipliers, and overflows.

Referenced by convert(), toMicros(), toMillis(), toNanos(), and toSeconds().

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.

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

Definition at line 107 of file TimeUnit.d.

References doConvert().

long toNanos long  duration,
TimeUnit  fromUnit
 

Convert to nanoseconds.

Parameters:
duration the duration
fromUnit the unit of the duration argument
Returns:
the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

Definition at line 119 of file TimeUnit.d.

References doConvert().

Referenced by Exchanger(), Semaphore::tryAcquire(), ReentrantLock::tryLock(), ReentrantReadWriteLock::WriteLock::tryLock(), ReentrantReadWriteLock::ReadLock::tryLock(), AbstractLock::ConditionObject::wait(), CyclicBarrier::wait(), and CountDownLatch::wait().

long toMicros long  duration,
TimeUnit  fromUnit
 

Convert to microseconds.

Parameters:
duration the duration
fromUnit the unit of the duration argument
Returns:
the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

Definition at line 131 of file TimeUnit.d.

References doConvert(), and TimeUnit.

long toMillis long  duration,
TimeUnit  fromUnit
 

Convert to milliseconds.

Parameters:
duration the duration
fromUnit the unit of the duration argument
Returns:
the converted duration, or long.min if conversion would negatively overflow, or long.max if it would positively overflow.

Definition at line 143 of file TimeUnit.d.

References doConvert(), and TimeUnit.

long toSeconds long  duration,
TimeUnit  fromUnit
 

Convert to seconds.

Parameters:
duration the duration
fromUnit the unit of the duration argument
Returns:
the converted duration.

Definition at line 153 of file TimeUnit.d.

References doConvert(), and TimeUnit.


Variable Documentation

module mango locks TimeUnit
 

Definition at line 18 of file TimeUnit.d.

const int [TimeUnit.max+1] multipliers
 

Initial value:

 [ 
  1, 
  1000, 
  1000_000, 
  1000_000_000 
]
Lookup table for conversion factors

Definition at line 52 of file TimeUnit.d.

Referenced by doConvert().

const long [TimeUnit.max+1] overflows
 

Initial value:

 [ 
  0, 
  long.max / 1000,
  long.max / 1000_000,
  long.max / 1000_000_000 
]
Lookup table to check saturation. Note that because we are dividing these down, we don't have to deal with asymmetry of MIN/MAX values.

Definition at line 64 of file TimeUnit.d.

Referenced by doConvert().


Generated on Mon Nov 14 10:59:46 2005 for Mango by  doxygen 1.4.0