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

days
long days()

Convert to days

hours
long hours()

Convert to hours

interval
double interval()

Convert to a floating point interval representing seconds.

micros
long micros()

Convert to microseconds

millis
long millis()

Convert to milliseconds

minutes
long minutes()

Convert to minutes

nanos
long nanos()

Convert to nanoseconds

opAdd
TimeSpan opAdd(TimeSpan t)

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

opAddAssign
TimeSpan opAddAssign(TimeSpan t)

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

opDiv
TimeSpan opDiv(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.

opDiv
long opDiv(TimeSpan t)

Perform integer division with the given time span.

opDivAssign
TimeSpan opDivAssign(long v)

Divides this TimeSpan and assigns the result to this instance.

opEquals
equals_t opEquals(TimeSpan t)

Determines whether two TimeSpan values are equal

opMul
TimeSpan opMul(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.

opMulAssign
TimeSpan opMulAssign(long v)

Scales this TimeSpan and assigns the result to this instance.

opNeg
TimeSpan opNeg()

Negate a time span

opSub
TimeSpan opSub(TimeSpan t)

Subtract the specified TimeSpan from this TimeSpan.

opSubAssign
TimeSpan opSubAssign(TimeSpan t)

Subtract the specified TimeSpan from this TimeSpan and assign the

seconds
long seconds()

Convert to seconds

ticks
long ticks()

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

time
TimeOfDay time()

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

ocean.core.Thread, ocean.time.Clock

Meta