core.time

Module containing core time functionality, such as Duration (which represents a duration of time) or MonoTime (which represents a timestamp of the system's monotonic clock).

Various functions take a string (or strings) to represent a unit of time (e.g. convert!("days", "hours")(numDays)). The valid strings to use with such functions are "years", "months", "weeks", "days", "hours", "minutes", "seconds", "msecs" (milliseconds), "usecs" (microseconds), "hnsecs" (hecto-nanoseconds - i.e. 100 ns) or some subset thereof. There are a few functions that also allow "nsecs", but very little actually has precision greater than hnsecs.

Cheat Sheet
SymbolDescription
Types
DurationRepresents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).
TickDurationDEPRECATED Represents a duration of time in system clock ticks, using the highest precision that the system provides.
MonoTimeRepresents a monotonic timestamp in system clock ticks, using the highest precision that the system provides.
Functions
convertGeneric way of converting between two time units.
durAllows constructing a Duration from the given time units with the given length.
weeks days hours
minutes seconds msecs
usecs hnsecs nsecs
Convenience aliases for dur.
absReturns the absolute value of a duration.
Conversions
From DurationFrom TickDurationFrom units
To Duration-tickDuration..to!Duration()dur!"msecs"(5) or 5.msecs()
To TickDurationduration..to!TickDuration()-TickDuration.from!"msecs"(msecs)
To unitsduration.total!"days"tickDuration.msecsconvert!("days", "msecs")(msecs)

Public Imports

core.sys.darwin.mach.kern_return
public import core.sys.darwin.mach.kern_return;
Undocumented in source.

Members

Aliases

MonoTime
alias MonoTime = MonoTimeImpl!(ClockType.normal)

alias for MonoTimeImpl instantiated with ClockType.normal. This is what most programs should use. It's also what much of MonoTimeImpl uses in its documentation (particularly in the examples), because that's what's going to be used in most code.

days
alias days = dur!"days"
Undocumented in source.
hnsecs
alias hnsecs = dur!"hnsecs"
Undocumented in source.
hours
alias hours = dur!"hours"
Undocumented in source.
mach_timebase_info_t
alias mach_timebase_info_t = mach_timebase_info_data_t*
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
minutes
alias minutes = dur!"minutes"
Undocumented in source.
msecs
alias msecs = dur!"msecs"
Undocumented in source.
nsecs
alias nsecs = dur!"nsecs"
Undocumented in source.
seconds
alias seconds = dur!"seconds"
Undocumented in source.
usecs
alias usecs = dur!"usecs"
Undocumented in source.
weeks
alias weeks = dur!"weeks"
Undocumented in source.

Classes

TimeException
class TimeException

Exception type used by core.time.

Enums

ClockType
enum ClockType

What type of clock to use with MonoTime / MonoTimeImpl or std.datetime.Clock.currTime. They default to ClockType.normal, and most programs do not need to ever deal with the others.

ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.
ClockType
enum ClockType
Undocumented in source.

Functions

_d_initMonoTime
void _d_initMonoTime()
Undocumented in source. Be warned that the author may not have intended to support it.
abs
Duration abs(Duration duration)
deprecated TickDuration abs(TickDuration duration)

Returns the absolute value of a duration.

convClockFreq
long convClockFreq(long ticks, long srcTicksPerSecond, long dstTicksPerSecond)

Converts the given time from one clock frequency/resolution to another.

convert
long convert(long value)

Generic way of converting between two time units. Conversions to smaller units use truncating division. Years and months can be converted to each other, small units can be converted to each other, but years and months cannot be converted to or from smaller units (due to the varying number of days in a month or year).

dur
Duration dur(long length)

These allow you to construct a Duration from the given time units with the given length.

mach_absolute_time
ulong mach_absolute_time()
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
mach_timebase_info
kern_return_t mach_timebase_info(mach_timebase_info_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
nsecsToTicks
long nsecsToTicks(long ticks)

The reverse of ticksToNSecs.

ticksToNSecs
long ticksToNSecs(long ticks)

Convenience wrapper around convClockFreq which converts ticks at a clock frequency of MonoTime.ticksPerSecond to nanoseconds.

to
deprecated T to(D td)

TickDuration is DEPRECATED

Structs

Duration
struct Duration

Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).

MonoTimeImpl
struct MonoTimeImpl(ClockType clockType)

Represents a timestamp of the system's monotonic clock.

TickDuration
deprecated struct TickDuration

Warning: TickDuration is deprecated. Please use MonoTime for the cases where a monotonic timestamp is needed and Duration when a duration is needed, rather than using TickDuration.

mach_timebase_info_data_t
struct mach_timebase_info_data_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Meta

Authors

Jonathan M Davis and Kato Shoichi