TimeSpan

This struct represents a length of time. The underlying representation is in units of 100ns. This allows the length of time to span to roughly +/- 10000 years.

Notably missing from this is a representation of weeks, months and years. This is because weeks, months, and years vary according to local calendars. Use tango.time.chrono.* to deal with these concepts.

Note: nobody should change this struct without really good reason as it is required to be a part of some interfaces. It should be treated as a builtin type. Also note that there is deliberately no opCall constructor here, since it tends to produce too much overhead. If you wish to build a TimeSpan struct from a ticks value, use D's builtin ability to create a struct with given member values (See the description of ticks() for an example of how to do this).

Members

Enums

NanosecondsPerTick
anonymousenum NanosecondsPerTick
Undocumented in source.

Functions

opBinary
TimeSpan opBinary(const(TimeSpan) t)

Add the TimeSpan given to this TimeSpan returning a new TimeSpan.

opBinary
TimeSpan opBinary(const(TimeSpan) t)

Subtract the specified TimeSpan from this TimeSpan.

opBinary
TimeSpan opBinary(long v)

Scale the TimeSpan by the specified amount. This should not be used to convert to a different unit. Use the unit accessors instead. This should only be used as a scaling mechanism. For example, if you have a timeout and you want to sleep for twice the timeout, you would use timeout * 2.

opBinary
TimeSpan opBinary(long v)

Divide the TimeSpan by the specified amount. This should not be used to convert to a different unit. Use the unit accessors instead. This should only be used as a scaling mechanism. For example, if you have a timeout and you want to sleep for half the timeout, you would use timeout / 2.

opBinary
long opBinary(const(TimeSpan) t)

Perform integer division with the given time span.

opCmp
int opCmp(TimeSpan t)

Compares this object against another TimeSpan value.

opCmp
int opCmp(TimeSpan t)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(const(TimeSpan) t)

Determines whether two TimeSpan values are equal

opOpAssign
TimeSpan opOpAssign(const(TimeSpan) t)

Add the specified TimeSpan to this TimeSpan, assigning the result to this instance.

opOpAssign
TimeSpan opOpAssign(const(TimeSpan) t)

Subtract the specified TimeSpan from this TimeSpan and assign the

opOpAssign
TimeSpan opOpAssign(long v)

Scales this TimeSpan and assigns the result to this instance.

opOpAssign
TimeSpan opOpAssign(long v)

Divides this TimeSpan and assigns the result to this instance.

opUnary
TimeSpan opUnary()

Negate a time span

Properties

days
long days [@property getter]

Convert to days

hours
long hours [@property getter]

Convert to hours

interval
double interval [@property getter]

Convert to a floating point interval representing seconds.

micros
long micros [@property getter]

Convert to microseconds

millis
long millis [@property getter]

Convert to milliseconds

minutes
long minutes [@property getter]

Convert to minutes

nanos
long nanos [@property getter]

Convert to nanoseconds

seconds
long seconds [@property getter]

Convert to seconds

ticks
long ticks [@property getter]

Get the number of ticks that this timespan represents. This can be used to construct another TimeSpan:

time
TimeOfDay time [@property getter]

Convert to TimeOfDay

Static functions

fromDays
TimeSpan fromDays(long value)

Construct a TimeSpan from the given number of days

fromHours
TimeSpan fromHours(long value)

Construct a TimeSpan from the given number of hours

fromInterval
TimeSpan fromInterval(double sec)

Construct a TimeSpan from the given interval. The interval represents seconds as a double. This allows both whole and fractional seconds to be passed in.

fromMicros
TimeSpan fromMicros(long value)

Construct a TimeSpan from the given number of microseconds

fromMillis
TimeSpan fromMillis(long value)

Construct a TimeSpan from the given number of milliseconds

fromMinutes
TimeSpan fromMinutes(long value)

Construct a TimeSpan from the given number of minutes

fromNanos
TimeSpan fromNanos(long value)

Construct a TimeSpan from the given number of nanoseconds

fromSeconds
TimeSpan fromSeconds(long value)

Construct a TimeSpan from the given number of seconds

Variables

max
enum TimeSpan max;

Maximum TimeSpan

min
enum TimeSpan min;

Minimum TimeSpan

ticks_
long ticks_;
Undocumented in source.
zero
enum TimeSpan zero;

Zero TimeSpan. Useful for comparisons.

Examples

Time start = Clock.now;
Thread.sleep(0.150);
Stdout.formatln("slept for {} ms", (Clock.now-start).millis);

See Also

tango.core.Thread, tango.time.Clock

Meta