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

Constructors

this
this(long ticks)

Compatibility constructors

this
this(Duration dur)

Alias This

duration

Allow implicit conversion from TimeSpan to Duration

Members

Enums

NanosecondsPerTick
anonymousenum NanosecondsPerTick
Undocumented in source.

Functions

days
long days()

Convert to days

duration
Duration duration()

Convenience function (older compilers don't allow public alias to package)

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

opBinary
TimeSpan opBinary(TimeSpan t)

Add or subtract the TimeSpan given to this TimeSpan returning a new 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. Returns a new TimeSpan.

opBinary
long opBinary(TimeSpan t)

Perform integer division with the given time span.

opCmp
int opCmp(typeof(this) rhs)

Compares this object against another TimeSpan value.

opEquals
equals_t opEquals(TimeSpan t)

Determines whether two TimeSpan values are equal

opOpAssign
TimeSpan opOpAssign(TimeSpan t)

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

opOpAssign
TimeSpan opOpAssign(long v)

Scales this TimeSpan and assigns the result to this instance.

opUnary
TimeSpan opUnary()

Negate a time span. Returns a new TimeSpan.

seconds
long seconds()

Convert to seconds

ticks
long ticks()

Get the number of ticks that this timespan represents.

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

duration_
Duration duration_;
Undocumented in source.
max
enum TimeSpan max;

Maximum TimeSpan

min
enum TimeSpan min;

Minimum TimeSpan

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