View source code Display the source code in core/time.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Module 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
Symbol Description
    Types
Duration Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).
TickDuration Represents a duration of time in system clock ticks, using the highest precision that the system provides.
MonoTime Represents a monotonic timestamp in system clock ticks, using the highest precision that the system provides.
FracSec Represents fractional seconds (portions of time smaller than a second).
    Functions
convert Generic way of converting between two time units.
dur Allows 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.
abs Returns the absolute value of a duration.

Conversions
From Duration From TickDuration From FracSec From units
To Duration - tickDuration.to!Duration() - dur!"msecs"(5) or 5.msecs()
To TickDuration duration.to!TickDuration() - - TickDuration.from!"msecs"(msecs)
To FracSec duration.fracSec - - FracSec.from!"msecs"(msecs)
To units duration.total!"days" tickDuration.msecs fracSec.msecs convert!("days", "msecs")(msecs)

Functions

Name Description
abs Returns the absolute value of a duration.
convClockFreq Converts the given time from one clock frequency/resolution to another.
convert 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 These allow you to construct a Duration from the given time units with the given length.
nsecsToTicks The reverse of ticksToNSecs.
ticksToNSecs Convenience wrapper around convClockFreq which converts ticks at a clock frequency of MonoTime.ticksPerSecond to nanoseconds.
to Converts a TickDuration to the given units as either an integral value or a floating point value.

Classes

Name Description
TimeException Exception type used by core.time.

Structs

Name Description
Duration Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).
FracSec Represents fractional seconds.
MonoTimeImpl Represents a timestamp of the system's monotonic clock.
TickDuration Warning: TickDuration will be deprecated in the near future (once all uses of it in Phobos have been deprecated). Please use MonoTime for the cases where a monotonic timestamp is needed and Duration when a duration is needed, rather than using TickDuration. It has been decided that TickDuration is too confusing (e.g. it conflates a monotonic timestamp and a duration in monotonic clock ticks) and that having multiple duration types is too awkward and confusing.

Enums

Name Description
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.

Aliases

Name Type Description
days These allow you to construct a Duration from the given time units with the given length.
hnsecs These allow you to construct a Duration from the given time units with the given length.
hours These allow you to construct a Duration from the given time units with the given length.
minutes These allow you to construct a Duration from the given time units with the given length.
MonoTime MonoTimeImpl!(0) 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.
msecs These allow you to construct a Duration from the given time units with the given length.
nsecs These allow you to construct a Duration from the given time units with the given length.
seconds These allow you to construct a Duration from the given time units with the given length.
usecs These allow you to construct a Duration from the given time units with the given length.
weeks These allow you to construct a Duration from the given time units with the given length.

Authors

Jonathan M Davis and Kato Shoichi

License

Boost License 1.0.

Comments