std.datetime
- Types to represent points in time: SysTime, Date, TimeOfDay, and DateTime.
- Types to represent intervals of time.
- Types to represent ranges over intervals of time.
- Types to represent time zones (used by SysTime).
- A platform-independent, high precision stopwatch type: StopWatch
- Benchmarking functions.
- Various helper functions.
datetime
is core.time,
and some of the time types used in std.datetime
come from there - such as
core.time.Duration, core.time.TickDuration, and
core.time.FracSec.
core.time is publically imported into std.datetime
, it isn't necessary
to import it separately.
Three of the main concepts used in this module are time points, time
durations, and time intervals.
A time point is a specific point in time. e.g. January 5th, 2010
or 5:00.
A time duration is a length of time with units. e.g. 5 days or 231 seconds.
A time interval indicates a period of time associated with a fixed point in
time. It is either two time points associated with each other,
indicating the time starting at the first point up to, but not including,
the second point - e.g. [January 5th, 2010 - March 10th, 2010) - or
it is a time point and a time duration associated with one another. e.g.
January 5th, 2010 and 5 days, indicating [January 5th, 2010 -
January 10th, 2010).
Various arithmetic operations are supported between time points and
durations (e.g. the difference between two time points is a time duration),
and ranges can be gotten from time intervals, so range-based operations may
be done on a series of time points.
The types that the typical user is most likely to be interested in are
Date (if they want dates but don't care about time), DateTime
(if they want dates and times but don't care about time zones), SysTime
(if they want the date and time from the OS and/or do care about time
zones), and StopWatch (a platform-independent, high precision stop watch).
Date and DateTime are optimized for calendar-based operations,
while SysTime is designed for dealing with time from the OS. Check out
their specific documentation for more details.
To get the current time, use Clock.currTime.
It will return the current
time as a SysTime. To print it, toString is
sufficient, but if using toISOString, toISOExtString, or
toSimpleString, use the corresponding fromISOString,
fromISOExtString, or fromSimpleString to create a
SysTime from the string.
auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtString(); auto restoredTime = SysTime.fromISOExtString(timeString);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 in core.time which take "nsecs", but because nothing in std.
datetime
has precision greater than hnsecs, and very little
in core.time does, no functions in std.datetime
accept "nsecs".
To remember which units are abbreviated and which aren't,
all units seconds and greater use their full names, and all
sub-second units are abbreviated (since they'd be rather long if they
weren't).
Note:
DateTimeException is an alias for core.time.TimeException,
so you don't need to worry about core.time functions and std.datetime
functions throwing different exception types (except in the rare case
that they throw something other than core.time.TimeException or
DateTimeException).
Source: std/datetime.d
- enum
Month
: ubyte; - Represents the 12 months of the Gregorian year (January is 1).
jan
feb
mar
apr
may
jun
jul
aug
sep
oct
nov
dec
- enum
DayOfWeek
: ubyte; - Represents the 7 days of the Gregorian week (Sunday is 0).
sun
mon
tue
wed
thu
fri
sat
- alias
AllowDayOverflow
= std.typecons.Flag!"allowDayOverflow".Flag; - In some date calculations, adding months or years can cause the date to fall on a day of the month which is not valid (e.g. February 29th 2001 or June 31st 2000). If overflow is allowed (as is the default), then the month will be incremented accordingly (so, February 29th 2001 would become March 1st 2001, and June 31st 2000 would become July 1st 2000). If overflow is not allowed, then the day will be adjusted to the last valid day in that month (so, February 29th 2001 would become February 28th 2001 and June 31st 2000 would become June 30th 2000).
AllowDayOverflow
only applies to calculations involving months or years. If set toAllowDayOverflow
.no, then day overflow is not allowed. Otherwise, if set toAllowDayOverflow
.yes, then day overflow is allowed. - enum
Direction
: int; - Indicates a direction in time. One example of its use is Interval's expand function which uses it to indicate whether the interval should be expanded backwards (into the past), forwards (into the future), or both.
bwd
- Backward.
fwd
- Forward.
both
- Both backward and forward.
- alias
PopFirst
= std.typecons.Flag!"popFirst".Flag; - Used to indicate whether popFront should be called immediately upon creating a range. The idea is that for some functions used to generate a range for an interval, front is not necessarily a time point which would ever be generated by the range. To get the first time point in the range to match what the function generates, then use
PopFirst
.yes to indicate that the range should have popFront called on it before the range is returned so that front is a time point which the function would generate.For instance, if the function used to generate a range of time points generated successive Easters (i.e. you're iterating over all of the Easters within the interval), the initial date probably isn't an Easter. UsingPopFirst
.yes would tell the function which returned the range that popFront was to be called so that front would then be an Easter - the next one generated by the function (which when iterating forward would be the Easter following the original front, while when iterating backward, it would be the Easter prior to the original front). IfPopFirst
.no were used, then front would remain the original time point and it would not necessarily be a time point which would be generated by the range-generating function (which in many cases is exactly what is desired - e.g. if iterating over every day starting at the beginning of the interval). If set toPopFirst
.no, then popFront is not called before returning the range. Otherwise, if set toPopFirst
.yes, then popFront is called before returning the range. - alias
AutoStart
= std.typecons.Flag!"autoStart".Flag; - Used by StopWatch to indicate whether it should start immediately upon construction.If set to
AutoStart
.no, then the stopwatch is not started when it is constructed. Otherwise, if set toAutoStart
.yes, then the stopwatch is started when it is constructed. - immutable string[]
timeStrings
; - Array of the strings representing time units, starting with the smallest unit and going to the largest. It does not include "nsecs".Includes "hnsecs" (hecto-nanoseconds (100 ns)), "usecs" (microseconds), "msecs" (milliseconds), "seconds", "minutes", "hours", "days", "weeks", "months", and "years"
- alias
DateTimeException
= core.time.TimeException; - Exception type used by std.datetime. It's an alias to core.time.TimeException. Either can be caught without concern about which module it came from.
- class
Clock
; - Effectively a namespace to make it clear that the methods it contains are getting the time from the system clock. It cannot be instantiated.
- @safe SysTime
currTime
(ClockType clockType = ClockType.normal)(immutable TimeZonetz
= LocalTime()); - Returns the current time in the given time zone.Parameters:
clockType The core.time.ClockType indicates which system clock to use to get the current time. Very few programs need to use anything other than the default. TimeZone tz
The time zone for the SysTime that's returned. Throws:DateTimeException if it fails to get the time. - @property @trusted long
currStdTime
(ClockType clockType = ClockType.normal)(); - Returns the number of hnsecs since midnight, January 1st, 1 A.D. for the current time.Parameters:
clockType The core.time.ClockType indicates which system clock to use to get the current time. Very few programs need to use anything other than the default. Throws:DateTimeException if it fails to get the time.
- struct
SysTime
; SysTime
is the type used to get the current time from the system or doing anything that involves time zones. Unlike DateTime, the time zone is an integral part ofSysTime
(though for local time applications, time zones can be ignored and it will work, since it defaults to using the local time zone). It holds its internal time in std time (hnsecs since midnight, January 1st, 1 A.D. UTC), so it interfaces well with the system time. However, that means that, unlike DateTime, it is not optimized for calendar-based operations, and getting individual units from it such as years or days is going to involve conversions and be less efficient.For calendar-based operations that don't care about time zones, then DateTime would be the type to use. For system time, useSysTime
. Clock.currTime will return the current time as aSysTime
. To convert aSysTime
to a Date or DateTime, simply cast it. To convert a Date or DateTime to aSysTime
, useSysTime
's constructor, and pass in the intended time zone with it (or don't pass in a TimeZone, and the local time zone will be used). Be aware, however, that converting from a DateTime to aSysTime
will not necessarily be 100% accurate due to DST (one hour of the year doesn't exist and another occurs twice). To not risk any conversion errors, keep times asSysTime
s. Aside from DST though, there shouldn't be any conversion problems. For using time zones other than local time or UTC, use PosixTimeZone on Posix systems (or on Windows, if providing the TZ Database files), and use WindowsTimeZone on Windows systems. The time inSysTime
is kept internally in hnsecs from midnight, January 1st, 1 A.D. UTC. Conversion error cannot happen when changing the time zone of aSysTime
. LocalTime is the TimeZone class which represents the local time, and UTC is the TimeZone class which represents UTC.SysTime
uses LocalTime if no TimeZone is provided. For more details on time zones, see the documentation for TimeZone, PosixTimeZone, and WindowsTimeZone.SysTime
's range is from approximately 29,000 B.C. to approximately 29,000 A.D.- nothrow @safe this(in DateTime
dateTime
, immutable TimeZonetz
= null); - Parameters:
- @safe this(in DateTime
dateTime
, in DurationfracSecs
, immutable TimeZonetz
= null); - Parameters:
DateTime dateTime
The DateTime to use to set this SysTime's internal std time. As DateTime has no concept of time zone, tz
is used as its time zone.Duration fracSecs
The fractional seconds portion of the time. TimeZone tz
The TimeZone to use for this SysTime. If null
, LocalTime will be used. The given DateTime is assumed to be in the given time zone.Throws:DateTimeException iffracSecs
is negative or if it's greater than or equal to one second. - nothrow @safe this(in Date
date
, immutable TimeZonetz
= null); - pure nothrow @safe this(long
stdTime
, immutable TimeZonetz
= null); Note: Whereas the other constructors take in the given date/time, assume that it's in the given time zone, and convert it to hnsecs in UTC since midnight, January 1st, 1 A.D. UTC - i.e. std time - this constructor takes a std time, which is specifically already in UTC, so no conversion takes place. Of course, the various getter properties and functions will use the given time zone's conversion function to convert the results to that time zone, but no conversion of the arguments to this constructor takes place.
- pure nothrow ref return @safe SysTime
opAssign
(ref const SysTimerhs
); - Parameters:
SysTime rhs
The SysTime to assign to this one. - pure nothrow ref return scope @safe SysTime
opAssign
(SysTimerhs
); - Parameters:
SysTime rhs
The SysTime to assign to this one. - const pure nothrow @safe bool
opEquals
(const SysTimerhs
);
const pure nothrow @safe boolopEquals
(ref const SysTimerhs
); -
Note that the time zone is ignored. Only the internal std times (which are in UTC) are compared.
- const pure nothrow @safe int
opCmp
(in SysTimerhs
); -
Time zone is irrelevant when comparing SysTimes.Returns:
this < rhs
< 0 this == rhs
0 this > rhs
> 0 - const pure nothrow @nogc @safe size_t
toHash
(); - Returns:A hash of the SysTime
- const nothrow @property @safe short
year
(); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
- @property @safe void
year
(intyear
); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.Parameters:
int year
The year
to set this SysTime'syear
to.Throws:DateTimeException if the newyear
is not a leapyear
and the resulting date would be on February 29th.Examples:writeln(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).year); // 1999 writeln(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).year); // 2010 writeln(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).year); // -7
- const @property @safe ushort
yearBC
(); - Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.Throws:Examples:
writeln(SysTime(DateTime(0, 1, 1, 12, 30, 33)).yearBC); // 1 writeln(SysTime(DateTime(-1, 1, 1, 10, 7, 2)).yearBC); // 2 writeln(SysTime(DateTime(-100, 1, 1, 4, 59, 0)).yearBC); // 101
- @property @safe void
yearBC
(intyear
); - Year B.C. of the Gregorian Calendar counting
year
0 as 1 B.C.Parameters:int year
The year
B.C. to set this SysTime'syear
to.Throws:DateTimeException if a non-positive value is given. - const nothrow @property @safe Month
month
(); - Month of a Gregorian Year.Examples:
writeln(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).month); // 7 writeln(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).month); // 10 writeln(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).month); // 4
- @property @safe void
month
(Monthmonth
); - Month of a Gregorian Year.Parameters:
Month month
The month
to set this SysTime'smonth
to.Throws: - const nothrow @property @safe ubyte
day
(); - Day of a Gregorian Month.Examples:
writeln(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).day); // 6 writeln(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).day); // 4 writeln(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).day); // 5
- @property @safe void
day
(intday
); - Day of a Gregorian Month.Parameters:
int day
The day
of the month to set this SysTime'sday
to.Throws: - const nothrow @property @safe ubyte
hour
(); - Hours past midnight.
- @property @safe void
hour
(inthour
); - Hours past midnight.Parameters:
int hour
The hours to set this SysTime's hour
to.Throws: - const nothrow @property @safe ubyte
minute
(); - Minutes past the current hour.
- @property @safe void
minute
(intminute
); - Minutes past the current hour.Parameters:
int minute
The minute
to set this SysTime'sminute
to.Throws: - const nothrow @property @safe ubyte
second
(); - Seconds past the current minute.
- @property @safe void
second
(intsecond
); - Seconds past the current minute.Parameters:
int second
The second
to set this SysTime'ssecond
to.Throws: - const nothrow @property @safe Duration
fracSecs
(); - Fractional seconds past the second (i.e. the portion of a SysTime which is less than a second).Examples:
auto dt = DateTime(1982, 4, 1, 20, 59, 22); writeln(SysTime(dt, msecs(213)).fracSecs); // msecs(213) writeln(SysTime(dt, usecs(5202)).fracSecs); // usecs(5202) writeln(SysTime(dt, hnsecs(1234567)).fracSecs); // hnsecs(1234567) // SysTime and Duration both have a precision of hnsecs (100 ns), // so nsecs are going to be truncated. writeln(SysTime(dt, nsecs(123456789)).fracSecs); // nsecs(123456700)
- @property @safe void
fracSecs
(DurationfracSecs
); - Fractional seconds past the second (i.e. the portion of a SysTime which is less than a second).Parameters:
Duration fracSecs
The duration to set this SysTime's fractional seconds to. Throws:DateTimeException if the given duration is negative or if it's greater than or equal to one second.Examples:auto st = SysTime(DateTime(1982, 4, 1, 20, 59, 22)); writeln(st.fracSecs); // Duration.zero st.fracSecs = msecs(213); writeln(st.fracSecs); // msecs(213) st.fracSecs = hnsecs(1234567); writeln(st.fracSecs); // hnsecs(1234567) // SysTime has a precision of hnsecs (100 ns), so nsecs are // going to be truncated. st.fracSecs = nsecs(123456789); writeln(st.fracSecs); // hnsecs(1234567)
- const pure nothrow @property @safe long
stdTime
(); - The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.
- pure nothrow @property @safe void
stdTime
(longstdTime
); - The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.Parameters:
long stdTime
The number of hnsecs since January 1st, 1 A.D. UTC. - const pure nothrow @property @safe immutable(TimeZone)
timezone
(); - pure nothrow @property @safe void
timezone
(immutable TimeZonetimezone
); - const nothrow @property @safe bool
dstInEffect
(); - Returns whether DST is in effect for this SysTime.
- const nothrow @property @safe Duration
utcOffset
(); - Returns what the offset from UTC is for this SysTime. It includes the DST offset in effect at that time (if any).
- const pure nothrow @safe SysTime
toLocalTime
(); - const pure nothrow @safe SysTime
toUTC
(); - Returns a SysTime with the same std time as this one, but with UTC as its time zone.
- const pure nothrow @safe SysTime
toOtherTZ
(immutable TimeZonetz
); - Returns a SysTime with the same std time as this one, but with given time zone as its time zone.
- const pure nothrow @safe T
toUnixTime
(T = time_t)()
if (is(T == int) || is(T == long)); - Converts this SysTime to unix time (i.e. seconds from midnight, January 1st, 1970 in UTC).The C standard does not specify the representation of time_t, so it is implementation defined. On POSIX systems, unix time is equivalent to time_t, but that's not necessarily
true
on other systems (e.g. it is nottrue
for the Digital Mars C runtime). So, be careful when using unix time with C functions on non-POSIX systems. By default, the return type is time_t (which is normally an alias for int on 32-bit systems and long on 64-bit systems), but if a different size is required than either int or long can be passed as a template argument to get the desired size. If the return type is int, and the result can't fit in an int, then the closest value that can be held in 32 bits will be used (so int.max if it goes over and int.min if it goes under). However, no attempt is made to deal with integer overflow if the return type is long.Parameters:T The return type (int or long). It defaults to time_t, which is normally 32 bits on a 32-bit system and 64 bits on a 64-bit system. Returns:A signed integer representing the unix time which is equivalent to this SysTime.Examples:writeln(SysTime(DateTime(1970, 1, 1), UTC()).toUnixTime()); // 0 auto pst = new immutable SimpleTimeZone(hours(-8)); writeln(SysTime(DateTime(1970, 1, 1), pst).toUnixTime()); // 28800 auto utc = SysTime(DateTime(2007, 12, 22, 8, 14, 45), UTC()); writeln(utc.toUnixTime()); // 1_198_311_285 auto ca = SysTime(DateTime(2007, 12, 22, 8, 14, 45), pst); writeln(ca.toUnixTime()); // 1_198_340_085
- static pure nothrow @safe SysTime
fromUnixTime
(longunixTime
, immutable TimeZonetz
= LocalTime()); - Converts from unix time (i.e. seconds from midnight, January 1st, 1970 in UTC) to a SysTime.The C standard does not specify the representation of time_t, so it is implementation defined. On POSIX systems, unix time is equivalent to time_t, but that's not necessarily
true
on other systems (e.g. it is nottrue
for the Digital Mars C runtime). So, be careful when using unix time with C functions on non-POSIX systems.Parameters:long unixTime
Seconds from midnight, January 1st, 1970 in UTC. TimeZone tz
The time zone for the SysTime that's returned. Examples:assert(SysTime.fromUnixTime(0) == SysTime(DateTime(1970, 1, 1), UTC())); auto pst = new immutable SimpleTimeZone(hours(-8)); assert(SysTime.fromUnixTime(28800) == SysTime(DateTime(1970, 1, 1), pst)); auto st1 = SysTime.fromUnixTime(1_198_311_285, UTC()); writeln(st1); // SysTime(DateTime(2007, 12, 22, 8, 14, 45), UTC()) assert(st1.timezone is UTC()); writeln(st1); // SysTime(DateTime(2007, 12, 22, 0, 14, 45), pst) auto st2 = SysTime.fromUnixTime(1_198_311_285, pst); writeln(st2); // SysTime(DateTime(2007, 12, 22, 8, 14, 45), UTC()) assert(st2.timezone is pst); writeln(st2); // SysTime(DateTime(2007, 12, 22, 0, 14, 45), pst)
- const pure nothrow @safe timeval
toTimeVal
(); - Returns a timeval which represents this SysTime.Note that like all conversions in std.datetime, this is a truncating conversion. If timeval.tv_sec is int, and the result can't fit in an int, then the closest value that can be held in 32 bits will be used for tv_sec. (so int.max if it goes over and int.min if it goes under).
- const pure nothrow @safe timespec
toTimeSpec
(); - Returns a timespec which represents this SysTime.This function is Posix-Only.
- const nothrow @safe tm
toTM
(); - Returns a tm which represents this SysTime.
- nothrow ref @safe SysTime
add
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years" || units == "months"); - Adds the given number of years or months to this SysTime. A negative number will subtract.Note that if day overflow is allowed, and the date with the adjusted year/month overflows the number of days in the new month, then the month will be incremented by one, and the day set to the number of days overflowed. (e.g. if the day were 31 and the new month were June, then the month would be incremented to July, and the new day would be 1). If day overflow is not allowed, then the day will be set to the last valid day in the month (e.g. June 31st would become June 30th).Parameters:
units The type of units to add
("years" or "months").long value
The number of months or years to add
to this SysTime.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow, causing the month to increment. - nothrow ref @safe SysTime
roll
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years"); - Adds the given number of years or months to this SysTime. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. Rolling a SysTime 12 months gets the exact same SysTime. However, the days can still be affected due to the differing number of days in each month. Because there are no units larger than years, there is no difference between adding and rolling years.Parameters:
units The type of units to add ("years" or "months"). long value
The number of months or years to add to this SysTime. AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow, causing the month to increment. Examples:import std.typecons : No; auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33)); st1.roll!"months"(1); writeln(st1); // SysTime(DateTime(2010, 2, 1, 12, 33, 33)) auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33)); st2.roll!"months"(-1); writeln(st2); // SysTime(DateTime(2010, 12, 1, 12, 33, 33)) auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33)); st3.roll!"months"(1); writeln(st3); // SysTime(DateTime(1999, 3, 1, 12, 33, 33)) auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33)); st4.roll!"months"(1, No.allowDayOverflow); writeln(st4); // SysTime(DateTime(1999, 2, 28, 12, 33, 33)) auto st5 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st5.roll!"years"(1); writeln(st5); // SysTime(DateTime(2001, 3, 1, 12, 30, 33)) auto st6 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st6.roll!"years"(1, No.allowDayOverflow); writeln(st6); // SysTime(DateTime(2001, 2, 28, 12, 30, 33))
- nothrow ref @safe SysTime
roll
(string units)(longvalue
)
if (units == "days"); - Adds the given number of units to this SysTime. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling a SysTime one year's worth of days gets the exact same SysTime. Accepted units are "days", "minutes", "hours", "minutes", "seconds", "msecs", "usecs", and "hnsecs". Note that when rolling msecs, usecs or hnsecs, they all add up to a second. So, for example, rolling 1000 msecs is exactly the same as rolling 100,000 usecs.Parameters:
units The units to add. long value
The number of units to add to this SysTime. Examples:auto st1 = SysTime(DateTime(2010, 1, 1, 11, 23, 12)); st1.roll!"days"(1); writeln(st1); // SysTime(DateTime(2010, 1, 2, 11, 23, 12)) st1.roll!"days"(365); writeln(st1); // SysTime(DateTime(2010, 1, 26, 11, 23, 12)) st1.roll!"days"(-32); writeln(st1); // SysTime(DateTime(2010, 1, 25, 11, 23, 12)) auto st2 = SysTime(DateTime(2010, 7, 4, 12, 0, 0)); st2.roll!"hours"(1); writeln(st2); // SysTime(DateTime(2010, 7, 4, 13, 0, 0)) auto st3 = SysTime(DateTime(2010, 2, 12, 12, 0, 0)); st3.roll!"hours"(-1); writeln(st3); // SysTime(DateTime(2010, 2, 12, 11, 0, 0)) auto st4 = SysTime(DateTime(2009, 12, 31, 0, 0, 0)); st4.roll!"minutes"(1); writeln(st4); // SysTime(DateTime(2009, 12, 31, 0, 1, 0)) auto st5 = SysTime(DateTime(2010, 1, 1, 0, 0, 0)); st5.roll!"minutes"(-1); writeln(st5); // SysTime(DateTime(2010, 1, 1, 0, 59, 0)) auto st6 = SysTime(DateTime(2009, 12, 31, 0, 0, 0)); st6.roll!"seconds"(1); writeln(st6); // SysTime(DateTime(2009, 12, 31, 0, 0, 1)) auto st7 = SysTime(DateTime(2010, 1, 1, 0, 0, 0)); st7.roll!"seconds"(-1); writeln(st7); // SysTime(DateTime(2010, 1, 1, 0, 0, 59)) auto dt = DateTime(2010, 1, 1, 0, 0, 0); auto st8 = SysTime(dt); st8.roll!"msecs"(1); writeln(st8); // SysTime(dt, msecs(1)) auto st9 = SysTime(dt); st9.roll!"msecs"(-1); writeln(st9); // SysTime(dt, msecs(999)) auto st10 = SysTime(dt); st10.roll!"hnsecs"(1); writeln(st10); // SysTime(dt, hnsecs(1)) auto st11 = SysTime(dt); st11.roll!"hnsecs"(-1); writeln(st11); // SysTime(dt, hnsecs(9_999_999))
- const pure nothrow @safe SysTime
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this SysTime.The legal types of arithmetic for SysTime using this operator are
SysTime + Duration --> SysTime SysTime - Duration --> SysTime Parameters:Duration duration
The core.time.Duration to add to or subtract from this SysTime. Examples:assert(SysTime(DateTime(2015, 12, 31, 23, 59, 59)) + seconds(1) == SysTime(DateTime(2016, 1, 1, 0, 0, 0))); assert(SysTime(DateTime(2015, 12, 31, 23, 59, 59)) + hours(1) == SysTime(DateTime(2016, 1, 1, 0, 59, 59))); assert(SysTime(DateTime(2016, 1, 1, 0, 0, 0)) - seconds(1) == SysTime(DateTime(2015, 12, 31, 23, 59, 59))); assert(SysTime(DateTime(2016, 1, 1, 0, 59, 59)) - hours(1) == SysTime(DateTime(2015, 12, 31, 23, 59, 59)));
- pure nothrow ref @safe SysTime
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this SysTime, as well as assigning the result to this SysTime.The legal types of arithmetic for SysTime using this operator are
SysTime + Duration --> SysTime SysTime - Duration --> SysTime Parameters:Duration duration
The core.time.Duration to add to or subtract from this SysTime. - const pure nothrow @safe Duration
opBinary
(string op)(in SysTimerhs
)
if (op == "-"); - Gives the difference between two SysTimes.The legal types of arithmetic for SysTime using this operator are
SysTime - SysTime --> duration - const nothrow @safe int
diffMonths
(in SysTimerhs
); - Returns the difference between the two SysTimes in months.To get the difference in years, subtract the year property of two SysTimes. To get the difference in days or weeks, subtract the SysTimes themselves and use the core.time.Duration that results. Because converting between months and smaller units requires a specific date (which core.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months. Note that the number of days in the months or how far into the month either date is is irrelevant. It is the difference in the month property combined with the difference in years * 12. So, for instance, December 31st and January 1st are one month apart just as December 1st and January 31st are one month apart.Parameters:
SysTime rhs
The SysTime to subtract from this one. Examples:assert(SysTime(Date(1999, 2, 1)).diffMonths( SysTime(Date(1999, 1, 31))) == 1); assert(SysTime(Date(1999, 1, 31)).diffMonths( SysTime(Date(1999, 2, 1))) == -1); assert(SysTime(Date(1999, 3, 1)).diffMonths( SysTime(Date(1999, 1, 1))) == 2); assert(SysTime(Date(1999, 1, 1)).diffMonths( SysTime(Date(1999, 3, 31))) == -2);
- const nothrow @property @safe bool
isLeapYear
(); - Whether this SysTime is in a leap year.
- const nothrow @property @safe DayOfWeek
dayOfWeek
(); - Day of the week this SysTime is on.
- const nothrow @property @safe ushort
dayOfYear
(); - Day of the year this SysTime is on.Examples:
writeln(SysTime(DateTime(1999, 1, 1, 12, 22, 7)).dayOfYear); // 1 writeln(SysTime(DateTime(1999, 12, 31, 7, 2, 59)).dayOfYear); // 365 writeln(SysTime(DateTime(2000, 12, 31, 21, 20, 0)).dayOfYear); // 366
- @property @safe void
dayOfYear
(intday
); - Day of the year.Parameters:
int day
The day
of the year to set whichday
of the year this SysTime is on. - const nothrow @property @safe int
dayOfGregorianCal
(); - The Xth day of the Gregorian Calendar that this SysTime is on.Examples:
writeln(SysTime(DateTime(1, 1, 1, 0, 0, 0)).dayOfGregorianCal); // 1 writeln(SysTime(DateTime(1, 12, 31, 23, 59, 59)).dayOfGregorianCal); // 365 writeln(SysTime(DateTime(2, 1, 1, 2, 2, 2)).dayOfGregorianCal); // 366 writeln(SysTime(DateTime(0, 12, 31, 7, 7, 7)).dayOfGregorianCal); // 0 writeln(SysTime(DateTime(0, 1, 1, 19, 30, 0)).dayOfGregorianCal); // -365 writeln(SysTime(DateTime(-1, 12, 31, 4, 7, 0)).dayOfGregorianCal); // -366 writeln(SysTime(DateTime(2000, 1, 1, 9, 30, 20)).dayOfGregorianCal); // 730_120 writeln(SysTime(DateTime(2010, 12, 31, 15, 45, 50)).dayOfGregorianCal); // 734_137
- nothrow @property @safe void
dayOfGregorianCal
(intdays
); - The Xth day of the Gregorian Calendar that this SysTime is on. Setting this property does not affect the time portion of SysTime.Parameters:
int days
The day of the Gregorian Calendar to set this SysTime to. Examples:auto st = SysTime(DateTime(0, 1, 1, 12, 0, 0)); st.dayOfGregorianCal = 1; writeln(st); // SysTime(DateTime(1, 1, 1, 12, 0, 0)) st.dayOfGregorianCal = 365; writeln(st); // SysTime(DateTime(1, 12, 31, 12, 0, 0)) st.dayOfGregorianCal = 366; writeln(st); // SysTime(DateTime(2, 1, 1, 12, 0, 0)) st.dayOfGregorianCal = 0; writeln(st); // SysTime(DateTime(0, 12, 31, 12, 0, 0)) st.dayOfGregorianCal = -365; writeln(st); // SysTime(DateTime(-0, 1, 1, 12, 0, 0)) st.dayOfGregorianCal = -366; writeln(st); // SysTime(DateTime(-1, 12, 31, 12, 0, 0)) st.dayOfGregorianCal = 730_120; writeln(st); // SysTime(DateTime(2000, 1, 1, 12, 0, 0)) st.dayOfGregorianCal = 734_137; writeln(st); // SysTime(DateTime(2010, 12, 31, 12, 0, 0))
- const nothrow @property @safe ubyte
isoWeek
(); - The ISO 8601 week of the year that this SysTime is in.See Also:
- const nothrow @property @safe SysTime
endOfMonth
(); - SysTime for the last day in the month that this Date is in. The time portion of
endOfMonth
is always 23:59:59.9999999.Examples:assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonth == SysTime(DateTime(1999, 1, 31, 23, 59, 59), hnsecs(9_999_999))); assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0), msecs(24)).endOfMonth == SysTime(DateTime(1999, 2, 28, 23, 59, 59), hnsecs(9_999_999))); assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27), usecs(5203)).endOfMonth == SysTime(DateTime(2000, 2, 29, 23, 59, 59), hnsecs(9_999_999))); assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9), hnsecs(12345)).endOfMonth == SysTime(DateTime(2000, 6, 30, 23, 59, 59), hnsecs(9_999_999)));
- const nothrow @property @safe ubyte
daysInMonth
(); - The last day in the month that this SysTime is in.Examples:
writeln(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).daysInMonth); // 31 writeln(SysTime(DateTime(1999, 2, 7, 19, 30, 0)).daysInMonth); // 28 writeln(SysTime(DateTime(2000, 2, 7, 5, 12, 27)).daysInMonth); // 29 writeln(SysTime(DateTime(2000, 6, 4, 12, 22, 9)).daysInMonth); // 30
- const nothrow @property @safe bool
isAD
(); - Whether the current year is a date in A.D.Examples:
assert(SysTime(DateTime(1, 1, 1, 12, 7, 0)).isAD); assert(SysTime(DateTime(2010, 12, 31, 0, 0, 0)).isAD); assert(!SysTime(DateTime(0, 12, 31, 23, 59, 59)).isAD); assert(!SysTime(DateTime(-2010, 1, 1, 2, 2, 2)).isAD);
- const nothrow @property @safe long
julianDay
(); - The Julian day for this SysTime at the given time. For example, prior to noon, 1996-03-31 would be the Julian day number 2_450_173, so this function returns 2_450_173, while from noon onward, the Julian day number would be 2_450_174, so this function returns 2_450_174.
- const nothrow @property @safe long
modJulianDay
(); - The modified Julian day for any time on this date (since, the modified Julian day changes at midnight).
- const nothrow @safe Date
opCast
(T)()
if (is(Unqual!T == Date)); - const nothrow @safe DateTime
opCast
(T)()
if (is(Unqual!T == DateTime)); - const nothrow @safe TimeOfDay
opCast
(T)()
if (is(Unqual!T == TimeOfDay)); - const nothrow @safe string
toISOString
(); - Converts this SysTime to a string with the format YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds and TZ is time zone).Note that the number of digits in the fractional seconds varies with the number of fractional seconds. It's a maximum of 7 (which would be hnsecs), but only has as many as are necessary to hold the correct value (so no trailing zeroes), and if there are no fractional seconds, then there is no decimal point. If this SysTime's time zone is LocalTime, then TZ is empty. If its time zone is UTC, then it is "Z". Otherwise, it is the offset from UTC (e.g. +0100 or -0700). Note that the offset from UTC is not enough to uniquely identify the time zone. Time zone offsets will be in the form +HHMM or -HHMM. Warning: Previously,
toISOString
did the same as toISOExtString and generated +HH:MM or -HH:MM for the time zone when it was not LocalTime or UTC, which is not in conformance with ISO 9601 for the non-extended string format. This has now been fixed. However, for now, fromISOString will continue to accept the extended format for the time zone so that any code which has been writing out the result oftoISOString
to read in later will continue to work.Examples:assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOString() == "20100704T070612"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(24)).toISOString() == "19981225T021500.024"); assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOString() == "00000105T230959"); assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOString() == "-00040105T000002.052092");
- const nothrow @safe string
toISOExtString
(); - Converts this SysTime to a string with the format YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone).Note that the number of digits in the fractional seconds varies with the number of fractional seconds. It's a maximum of 7 (which would be hnsecs), but only has as many as are necessary to hold the correct value (so no trailing zeroes), and if there are no fractional seconds, then there is no decimal point. If this SysTime's time zone is LocalTime, then TZ is empty. If its time zone is UTC, then it is "Z". Otherwise, it is the offset from UTC (e.g. +01:00 or -07:00). Note that the offset from UTC is not enough to uniquely identify the time zone. Time zone offsets will be in the form +HH:MM or -HH:MM.Examples:
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOExtString() == "2010-07-04T07:06:12"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(24)).toISOExtString() == "1998-12-25T02:15:00.024"); assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOExtString() == "0000-01-05T23:09:59"); assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toISOExtString() == "-0004-01-05T00:00:02.052092");
- const nothrow @safe string
toSimpleString
(); - Converts this SysTime to a string with the format YYYY-Mon-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds and TZ is the time zone).Note that the number of digits in the fractional seconds varies with the number of fractional seconds. It's a maximum of 7 (which would be hnsecs), but only has as many as are necessary to hold the correct value (so no trailing zeroes), and if there are no fractional seconds, then there is no decimal point. If this SysTime's time zone is LocalTime, then TZ is empty. If its time zone is UTC, then it is "Z". Otherwise, it is the offset from UTC (e.g. +01:00 or -07:00). Note that the offset from UTC is not enough to uniquely identify the time zone. Time zone offsets will be in the form +HH:MM or -HH:MM.Examples:
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), msecs(24)).toSimpleString() == "1998-Dec-25 02:15:00.024"); assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toSimpleString() == "0000-Jan-05 23:09:59"); assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), hnsecs(520_920)).toSimpleString() == "-0004-Jan-05 00:00:02.052092");
- const nothrow @safe string
toString
(); - Converts this SysTime to a string.
- @safe SysTime
fromISOString
(S)(in SisoString
, immutable TimeZonetz
= null)
if (isSomeString!S); - Creates a SysTime from a string with the format YYYYMMDDTHHMMSS.FFFFFFFTZ (where F is fractional seconds is the time zone). Whitespace is stripped from the given string.The exact format is exactly as described in toISOString except that trailing zeroes are permitted - including having fractional seconds with all zeroes. However, a decimal point with nothing following it is invalid. If there is no time zone in the string, then LocalTime is used. If the time zone is "Z", then UTC is used. Otherwise, a SimpleTimeZone which corresponds to the given offset from UTC is used. To get the returned SysTime to be a particular time zone, pass in that time zone and the SysTime to be returned will be converted to that time zone (though it will still be read in as whatever time zone is in its string). The accepted formats for time zone offsets are +HH, -HH, +HHMM, and -HHMM. Warning: Previously, toISOString did the same as toISOExtString and generated +HH:MM or -HH:MM for the time zone when it was not LocalTime or UTC, which is not in conformance with ISO 9601 for the non-extended string format. This has now been fixed. However, for now,
fromISOString
will continue to accept the extended format for the time zone so that any code which has been writing out the result of toISOString to read in later will continue to work.Parameters:S isoString
A string formatted in the ISO format for dates and times. TimeZone tz
The time zone to convert the given time to (no conversion occurs if null
).Throws:DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. - @safe SysTime
fromISOExtString
(S)(in SisoExtString
, immutable TimeZonetz
= null)
if (isSomeString!S); - Creates a SysTime from a string with the format YYYY-MM-DDTHH:MM:SS.FFFFFFFTZ (where F is fractional seconds is the time zone). Whitespace is stripped from the given string.The exact format is exactly as described in toISOExtString except that trailing zeroes are permitted - including having fractional seconds with all zeroes. However, a decimal point with nothing following it is invalid. If there is no time zone in the string, then LocalTime is used. If the time zone is "Z", then UTC is used. Otherwise, a SimpleTimeZone which corresponds to the given offset from UTC is used. To get the returned SysTime to be a particular time zone, pass in that time zone and the SysTime to be returned will be converted to that time zone (though it will still be read in as whatever time zone is in its string). The accepted formats for time zone offsets are +HH, -HH, +HH:MM, and
HH: MM.
Parameters:S isoExtString
A string formatted in the ISO Extended format for dates and times. TimeZone tz
The time zone to convert the given time to (no conversion occurs if null
).Throws:DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. - @safe SysTime
fromSimpleString
(S)(in SsimpleString
, immutable TimeZonetz
= null)
if (isSomeString!S); - Creates a SysTime from a string with the format YYYY-MM-DD HH:MM:SS.FFFFFFFTZ (where F is fractional seconds is the time zone). Whitespace is stripped from the given string.The exact format is exactly as described in toSimpleString except that trailing zeroes are permitted - including having fractional seconds with all zeroes. However, a decimal point with nothing following it is invalid. If there is no time zone in the string, then LocalTime is used. If the time zone is "Z", then UTC is used. Otherwise, a SimpleTimeZone which corresponds to the given offset from UTC is used. To get the returned SysTime to be a particular time zone, pass in that time zone and the SysTime to be returned will be converted to that time zone (though it will still be read in as whatever time zone is in its string). The accepted formats for time zone offsets are +HH, -HH, +HH:MM, and
HH: MM.
Parameters:S simpleString
A string formatted in the way that toSimpleString formats dates and times. TimeZone tz
The time zone to convert the given time to (no conversion occurs if null
).Throws:DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. - static pure nothrow @property @safe SysTime
min
(); -
The SysTime which is returned is in UTC.
- static pure nothrow @property @safe SysTime
max
(); -
The SysTime which is returned is in UTC.
- struct
Date
; - Represents a date in the Proleptic Gregorian Calendar ranging from 32,768 B.C. to 32,767 A.D. Positive years are A.D. Non-positive years are B.C.Year, month, and day are kept separately internally so that
Date
is optimized for calendar-based operations.Date
uses the Proleptic Gregorian Calendar, so it assumes the Gregorian leap year calculations for its entire length. As per ISO 8601, it treats 1 B.C. as year 0, i.e. 1 B.C. is 0, 2 B.C. is -1, etc. Use yearBC to use B.C. as a positive integer with 1 B.C. being the year prior to 1 A.D. Year 0 is a leap year.- pure @safe this(int
year
, intmonth
, intday
); - Throws:DateTimeException if the resulting Date would not be valid.Parameters:
int year
Year of the Gregorian Calendar. Positive values are A.D. Non-positive values are B.C. with year
0 being theyear
prior to 1 A.D.int month
Month of the year
.int day
Day of the month
. - pure nothrow @safe this(int
day
); - Parameters:
int day
The Xth day
of the Gregorian Calendar that the constructed Date will be for. - const pure nothrow @safe int
opCmp
(in Daterhs
); -
Returns:
this < rhs
< 0 this == rhs
0 this > rhs
> 0 - const pure nothrow @property @safe short
year
(); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.Examples:
writeln(Date(1999, 7, 6).year); // 1999 writeln(Date(2010, 10, 4).year); // 2010 writeln(Date(-7, 4, 5).year); // -7
- pure @property @safe void
year
(intyear
); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.Parameters:
int year
The year
to set this Date'syear
to.Throws:DateTimeException if the newyear
is not a leapyear
and the resulting date would be on February 29th.Examples:writeln(Date(1999, 7, 6).year); // 1999 writeln(Date(2010, 10, 4).year); // 2010 writeln(Date(-7, 4, 5).year); // -7
- const pure @property @safe ushort
yearBC
(); - Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.Throws:Examples:
writeln(Date(0, 1, 1).yearBC); // 1 writeln(Date(-1, 1, 1).yearBC); // 2 writeln(Date(-100, 1, 1).yearBC); // 101
- pure @property @safe void
yearBC
(intyear
); - Year B.C. of the Gregorian Calendar counting
year
0 as 1 B.C.Parameters:int year
The year
B.C. to set this Date'syear
to.Throws:DateTimeException if a non-positive value is given.Examples:auto date = Date(2010, 1, 1); date.yearBC = 1; writeln(date); // Date(0, 1, 1) date.yearBC = 10; writeln(date); // Date(-9, 1, 1)
- const pure nothrow @property @safe Month
month
(); - Month of a Gregorian Year.Examples:
writeln(Date(1999, 7, 6).month); // 7 writeln(Date(2010, 10, 4).month); // 10 writeln(Date(-7, 4, 5).month); // 4
- pure @property @safe void
month
(Monthmonth
); - Month of a Gregorian Year.Parameters:
Month month
The month
to set this Date'smonth
to.Throws:DateTimeException if the givenmonth
is not a validmonth
or if the current day would not be valid in the givenmonth
. - const pure nothrow @property @safe ubyte
day
(); - Day of a Gregorian Month.Examples:
writeln(Date(1999, 7, 6).day); // 6 writeln(Date(2010, 10, 4).day); // 4 writeln(Date(-7, 4, 5).day); // 5
- pure @property @safe void
day
(intday
); - Day of a Gregorian Month.Parameters:
int day
The day
of the month to set this Date'sday
to.Throws: - pure nothrow ref @safe Date
add
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years"); - Adds the given number of years or months to this Date. A negative number will subtract.Note that if day overflow is allowed, and the date with the adjusted year/month overflows the number of days in the new month, then the month will be incremented by one, and the day set to the number of days overflowed. (e.g. if the day were 31 and the new month were June, then the month would be incremented to July, and the new day would be 1). If day overflow is not allowed, then the day will be set to the last valid day in the month (e.g. June 31st would become June 30th).Parameters:
units The type of units to add
("years" or "months").long value
The number of months or years to add
to this Date.AllowDayOverflow allowOverflow
Whether the day should be allowed to overflow, causing the month to increment. Examples:import std.typecons : No; auto d1 = Date(2010, 1, 1); d1.add!"months"(11); writeln(d1); // Date(2010, 12, 1) auto d2 = Date(2010, 1, 1); d2.add!"months"(-11); writeln(d2); // Date(2009, 2, 1) auto d3 = Date(2000, 2, 29); d3.add!"years"(1); writeln(d3); // Date(2001, 3, 1) auto d4 = Date(2000, 2, 29); d4.add!"years"(1, No.allowDayOverflow); writeln(d4); // Date(2001, 2, 28)
- pure nothrow ref @safe Date
roll
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years"); - Adds the given number of years or months to this Date. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. Rolling a Date 12 months gets the exact same Date. However, the days can still be affected due to the differing number of days in each month. Because there are no units larger than years, there is no difference between adding and rolling years.Parameters:
units The type of units to add ("years" or "months"). long value
The number of months or years to add to this Date. AllowDayOverflow allowOverflow
Whether the day should be allowed to overflow, causing the month to increment. Examples:import std.typecons : No; auto d1 = Date(2010, 1, 1); d1.roll!"months"(1); writeln(d1); // Date(2010, 2, 1) auto d2 = Date(2010, 1, 1); d2.roll!"months"(-1); writeln(d2); // Date(2010, 12, 1) auto d3 = Date(1999, 1, 29); d3.roll!"months"(1); writeln(d3); // Date(1999, 3, 1) auto d4 = Date(1999, 1, 29); d4.roll!"months"(1, No.allowDayOverflow); writeln(d4); // Date(1999, 2, 28) auto d5 = Date(2000, 2, 29); d5.roll!"years"(1); writeln(d5); // Date(2001, 3, 1) auto d6 = Date(2000, 2, 29); d6.roll!"years"(1, No.allowDayOverflow); writeln(d6); // Date(2001, 2, 28)
- pure nothrow ref @safe Date
roll
(string units)(longdays
)
if (units == "days
"); - Adds the given number of units to this Date. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling a Date one year's worth of
days
gets the exact same Date. The only accepted units are "days
".Parameters:units The units to add. Must be " days
".long days
The number of days
to add to this Date.Examples:auto d = Date(2010, 1, 1); d.roll!"days"(1); writeln(d); // Date(2010, 1, 2) d.roll!"days"(365); writeln(d); // Date(2010, 1, 26) d.roll!"days"(-32); writeln(d); // Date(2010, 1, 25)
- const pure nothrow @safe Date
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration fromThe legal types of arithmetic for Date using this operator are
Date + Duration --> Date Date - Duration --> Date Parameters:Duration duration
The core.time.Duration to add to or subtract from this Date. Examples:writeln(Date(2015, 12, 31) + days(1)); // Date(2016, 1, 1) writeln(Date(2004, 2, 26) + days(4)); // Date(2004, 3, 1) writeln(Date(2016, 1, 1) - days(1)); // Date(2015, 12, 31) writeln(Date(2004, 3, 1) - days(4)); // Date(2004, 2, 26)
- pure nothrow ref @safe Date
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this Date, as well as assigning the result to this Date.The legal types of arithmetic for Date using this operator are
Date + Duration --> Date Date - Duration --> Date Parameters:Duration duration
The core.time.Duration to add to or subtract from this Date. - const pure nothrow @safe Duration
opBinary
(string op)(in Daterhs
)
if (op == "-"); - Gives the difference between two Dates.The legal types of arithmetic for Date using this operator are
Date - Date --> duration - const pure nothrow @safe int
diffMonths
(in Daterhs
); - Returns the difference between the two Dates in months.To get the difference in years, subtract the year property of two SysTimes. To get the difference in days or weeks, subtract the SysTimes themselves and use the core.time.Duration that results. Because converting between months and smaller units requires a specific date (which core.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months. Note that the number of days in the months or how far into the month either Date is is irrelevant. It is the difference in the month property combined with the difference in years * 12. So, for instance, December 31st and January 1st are one month apart just as December 1st and January 31st are one month apart.Parameters:
Date rhs
The Date to subtract from this one. Examples:writeln(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31))); // 1 writeln(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1))); // -1 writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); // 2 writeln(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31))); // -2
- const pure nothrow @property @safe bool
isLeapYear
(); - Whether this Date is in a leap year.
- const pure nothrow @property @safe DayOfWeek
dayOfWeek
(); - Day of the week this Date is on.
- const pure nothrow @property @safe ushort
dayOfYear
(); - Day of the year this Date is on.Examples:
writeln(Date(1999, 1, 1).dayOfYear); // 1 writeln(Date(1999, 12, 31).dayOfYear); // 365 writeln(Date(2000, 12, 31).dayOfYear); // 366
- pure @property @safe void
dayOfYear
(intday
); - Day of the year.Parameters:
int day
The day
of the year to set whichday
of the year this Date is on.Throws: - const pure nothrow @property @safe int
dayOfGregorianCal
(); - The Xth day of the Gregorian Calendar that this Date is on.Examples:
writeln(Date(1, 1, 1).dayOfGregorianCal); // 1 writeln(Date(1, 12, 31).dayOfGregorianCal); // 365 writeln(Date(2, 1, 1).dayOfGregorianCal); // 366 writeln(Date(0, 12, 31).dayOfGregorianCal); // 0 writeln(Date(0, 1, 1).dayOfGregorianCal); // -365 writeln(Date(-1, 12, 31).dayOfGregorianCal); // -366 writeln(Date(2000, 1, 1).dayOfGregorianCal); // 730_120 writeln(Date(2010, 12, 31).dayOfGregorianCal); // 734_137
- pure nothrow @property @safe void
dayOfGregorianCal
(intday
); - The Xth
day
of the Gregorian Calendar that this Date is on.Parameters:int day
The day
of the Gregorian Calendar to set this Date to.Examples:auto date = Date.init; date.dayOfGregorianCal = 1; writeln(date); // Date(1, 1, 1) date.dayOfGregorianCal = 365; writeln(date); // Date(1, 12, 31) date.dayOfGregorianCal = 366; writeln(date); // Date(2, 1, 1) date.dayOfGregorianCal = 0; writeln(date); // Date(0, 12, 31) date.dayOfGregorianCal = -365; writeln(date); // Date(-0, 1, 1) date.dayOfGregorianCal = -366; writeln(date); // Date(-1, 12, 31) date.dayOfGregorianCal = 730_120; writeln(date); // Date(2000, 1, 1) date.dayOfGregorianCal = 734_137; writeln(date); // Date(2010, 12, 31)
- const pure nothrow @property @safe ubyte
isoWeek
(); - The ISO 8601 week of the year that this Date is in.See Also:
- const pure nothrow @property @safe Date
endOfMonth
(); -
Examples:
writeln(Date(1999, 1, 6).endOfMonth); // Date(1999, 1, 31) writeln(Date(1999, 2, 7).endOfMonth); // Date(1999, 2, 28) writeln(Date(2000, 2, 7).endOfMonth); // Date(2000, 2, 29) writeln(Date(2000, 6, 4).endOfMonth); // Date(2000, 6, 30)
- const pure nothrow @property @safe ubyte
daysInMonth
(); - The last day in the month that this Date is in.Examples:
writeln(Date(1999, 1, 6).daysInMonth); // 31 writeln(Date(1999, 2, 7).daysInMonth); // 28 writeln(Date(2000, 2, 7).daysInMonth); // 29 writeln(Date(2000, 6, 4).daysInMonth); // 30
- const pure nothrow @property @safe bool
isAD
(); - Whether the current year is a date in A.D.Examples:
assert(Date(1, 1, 1).isAD); assert(Date(2010, 12, 31).isAD); assert(!Date(0, 12, 31).isAD); assert(!Date(-2010, 1, 1).isAD);
- const pure nothrow @property @safe long
julianDay
(); - The Julian day for this Date at noon (since the Julian day changes at noon).
- const pure nothrow @property @safe long
modJulianDay
(); - The modified Julian day for any time on this date (since, the modified Julian day changes at midnight).
- const pure nothrow @safe string
toISOString
(); - Converts this Date to a string with the format YYYYMMDD.Examples:
writeln(Date(2010, 7, 4).toISOString()); // "20100704" writeln(Date(1998, 12, 25).toISOString()); // "19981225" writeln(Date(0, 1, 5).toISOString()); // "00000105" writeln(Date(-4, 1, 5).toISOString()); // "-00040105"
- const pure nothrow @safe string
toISOExtString
(); - Converts this Date to a string with the format YYYY-MM-DD.Examples:
writeln(Date(2010, 7, 4).toISOExtString()); // "2010-07-04" writeln(Date(1998, 12, 25).toISOExtString()); // "1998-12-25" writeln(Date(0, 1, 5).toISOExtString()); // "0000-01-05" writeln(Date(-4, 1, 5).toISOExtString()); // "-0004-01-05"
- const pure nothrow @safe string
toSimpleString
(); - Converts this Date to a string with the format YYYY-Mon-DD.Examples:
writeln(Date(2010, 7, 4).toSimpleString()); // "2010-Jul-04" writeln(Date(1998, 12, 25).toSimpleString()); // "1998-Dec-25" writeln(Date(0, 1, 5).toSimpleString()); // "0000-Jan-05" writeln(Date(-4, 1, 5).toSimpleString()); // "-0004-Jan-05"
- const pure nothrow @safe string
toString
(); - Converts this Date to a string.
- pure @safe Date
fromISOString
(S)(in SisoString
)
if (isSomeString!S); - Creates a Date from a string with the format YYYYMMDD. Whitespace is stripped from the given string.Parameters:
S isoString
A string formatted in the ISO format for dates. Throws:DateTimeException if the given string is not in the ISO format or if the resulting Date would not be valid. - pure @safe Date
fromISOExtString
(S)(in SisoExtString
)
if (isSomeString!S); - Creates a Date from a string with the format YYYY-MM-DD. Whitespace is stripped from the given string.Parameters:
S isoExtString
A string formatted in the ISO Extended format for dates. Throws:DateTimeException if the given string is not in the ISO Extended format or if the resulting Date would not be valid. - pure @safe Date
fromSimpleString
(S)(in SsimpleString
)
if (isSomeString!S); - Creates a Date from a string with the format YYYY-Mon-DD. Whitespace is stripped from the given string.Parameters:
S simpleString
A string formatted in the way that toSimpleString formats dates. Throws:DateTimeException if the given string is not in the correct format or if the resulting Date would not be valid. - static pure nothrow @property @safe Date
min
(); - static pure nothrow @property @safe Date
max
();
- struct
TimeOfDay
; - Represents a time of day with hours, minutes, and seconds. It uses 24 hour time.
- pure @safe this(int
hour
, intminute
, intsecond
= 0); - Parameters:
int hour
Hour of the day [0 - 24). int minute
Minute of the hour
[0 - 60).int second
Second of the minute
[0 - 60).Throws:DateTimeException if the resulting TimeOfDay would be not be valid. - const pure nothrow @safe int
opCmp
(in TimeOfDayrhs
); -
Returns:
this < rhs
< 0 this == rhs
0 this > rhs
> 0 - const pure nothrow @property @safe ubyte
hour
(); - Hours past midnight.
- pure @property @safe void
hour
(inthour
); - Hours past midnight.Parameters:
int hour
The hour
of the day to set this TimeOfDay'shour
to.Throws: - const pure nothrow @property @safe ubyte
minute
(); - Minutes past the hour.
- pure @property @safe void
minute
(intminute
); - Minutes past the hour.Parameters:
int minute
The minute
to set this TimeOfDay'sminute
to.Throws: - const pure nothrow @property @safe ubyte
second
(); - Seconds past the minute.
- pure @property @safe void
second
(intsecond
); - Seconds past the minute.Parameters:
int second
The second
to set this TimeOfDay'ssecond
to.Throws: - pure nothrow ref @safe TimeOfDay
roll
(string units)(longvalue
)
if (units == "hours"); - Adds the given number of units to this TimeOfDay. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling a TimeOfDay one hours's worth of minutes gets the exact same TimeOfDay. Accepted units are "hours", "minutes", and "seconds".Parameters:
units The units to add. long value
The number of units to add to this TimeOfDay. Examples:auto tod1 = TimeOfDay(7, 12, 0); tod1.roll!"hours"(1); writeln(tod1); // TimeOfDay(8, 12, 0) auto tod2 = TimeOfDay(7, 12, 0); tod2.roll!"hours"(-1); writeln(tod2); // TimeOfDay(6, 12, 0) auto tod3 = TimeOfDay(23, 59, 0); tod3.roll!"minutes"(1); writeln(tod3); // TimeOfDay(23, 0, 0) auto tod4 = TimeOfDay(0, 0, 0); tod4.roll!"minutes"(-1); writeln(tod4); // TimeOfDay(0, 59, 0) auto tod5 = TimeOfDay(23, 59, 59); tod5.roll!"seconds"(1); writeln(tod5); // TimeOfDay(23, 59, 0) auto tod6 = TimeOfDay(0, 0, 0); tod6.roll!"seconds"(-1); writeln(tod6); // TimeOfDay(0, 0, 59)
- const pure nothrow @safe TimeOfDay
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this TimeOfDay.The legal types of arithmetic for TimeOfDay using this operator are
TimeOfDay + Duration --> TimeOfDay TimeOfDay - Duration --> TimeOfDay Parameters:Duration duration
The core.time.Duration to add to or subtract from this TimeOfDay. Examples:writeln(TimeOfDay(12, 12, 12) + seconds(1)); // TimeOfDay(12, 12, 13) writeln(TimeOfDay(12, 12, 12) + minutes(1)); // TimeOfDay(12, 13, 12) writeln(TimeOfDay(12, 12, 12) + hours(1)); // TimeOfDay(13, 12, 12) writeln(TimeOfDay(23, 59, 59) + seconds(1)); // TimeOfDay(0, 0, 0) writeln(TimeOfDay(12, 12, 12) - seconds(1)); // TimeOfDay(12, 12, 11) writeln(TimeOfDay(12, 12, 12) - minutes(1)); // TimeOfDay(12, 11, 12) writeln(TimeOfDay(12, 12, 12) - hours(1)); // TimeOfDay(11, 12, 12) writeln(TimeOfDay(0, 0, 0) - seconds(1)); // TimeOfDay(23, 59, 59)
- pure nothrow ref @safe TimeOfDay
opOpAssign
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this TimeOfDay, as well as assigning the result to this TimeOfDay.The legal types of arithmetic for TimeOfDay using this operator are
TimeOfDay + Duration --> TimeOfDay TimeOfDay - Duration --> TimeOfDay Parameters:Duration duration
The core.time.Duration to add to or subtract from this TimeOfDay. - const pure nothrow @safe Duration
opBinary
(string op)(in TimeOfDayrhs
)
if (op == "-"); - Gives the difference between two TimeOfDays.The legal types of arithmetic for TimeOfDay using this operator are
TimeOfDay - TimeOfDay --> duration Parameters:TimeOfDay rhs
The TimeOfDay to subtract from this one. - const pure nothrow @safe string
toISOString
(); - Converts this TimeOfDay to a string with the format HHMMSS.Examples:
writeln(TimeOfDay(0, 0, 0).toISOString()); // "000000" writeln(TimeOfDay(12, 30, 33).toISOString()); // "123033"
- const pure nothrow @safe string
toISOExtString
(); - Converts this TimeOfDay to a string with the format HH:MM:SS.Examples:
writeln(TimeOfDay(0, 0, 0).toISOExtString()); // "00:00:00" writeln(TimeOfDay(12, 30, 33).toISOExtString()); // "12:30:33"
- const pure nothrow @safe string
toString
(); - Converts this TimeOfDay to a string.
- pure @safe TimeOfDay
fromISOString
(S)(in SisoString
)
if (isSomeString!S); - Creates a TimeOfDay from a string with the format HHMMSS. Whitespace is stripped from the given string.Parameters:
S isoString
A string formatted in the ISO format for times. Throws:DateTimeException if the given string is not in the ISO format or if the resulting TimeOfDay would not be valid. - pure @safe TimeOfDay
fromISOExtString
(S)(in SisoExtString
)
if (isSomeString!S); - Creates a TimeOfDay from a string with the format HH:MM:SS. Whitespace is stripped from the given string.Parameters:
S isoExtString
A string formatted in the ISO Extended format for times. Throws:DateTimeException if the given string is not in the ISO Extended format or if the resulting TimeOfDay would not be valid. - static pure nothrow @property @safe TimeOfDay
min
(); - Returns midnight.
- static pure nothrow @property @safe TimeOfDay
max
(); - Returns one second short of midnight.
- struct
DateTime
; - Combines the Date and TimeOfDay structs to give an object which holds both the date and the time. It is optimized for calendar-based operations and has no concept of time zone. For an object which is optimized for time operations based on the system time, use SysTime. SysTime has a concept of time zone and has much higher precision (hnsecs).
DateTime
is intended primarily for calendar-based uses rather than precise time operations.- pure nothrow @safe this(in Date
date
, in TimeOfDaytod
= TimeOfDay.init); - pure @safe this(int
year
, intmonth
, intday
, inthour
= 0, intminute
= 0, intsecond
= 0); - Parameters:
int year
The year
portion of the date.int month
The month
portion of the date.int day
The day
portion of the date.int hour
The hour
portion of the time;int minute
The minute
portion of the time;int second
The second
portion of the time; - const pure nothrow @safe int
opCmp
(in DateTimerhs
); - Compares this DateTime with the given DateTime..Returns:
this < rhs
< 0 this == rhs
0 this > rhs
> 0 - const pure nothrow @property @safe Date
date
(); - The
date
portion of DateTime. - pure nothrow @property @safe void
date
(in Datedate
); - The
date
portion of DateTime.Parameters:Date date
The Date to set this DateTime's date
portion to. - const pure nothrow @property @safe TimeOfDay
timeOfDay
(); - The time portion of DateTime.
- pure nothrow @property @safe void
timeOfDay
(in TimeOfDaytod
); - The time portion of DateTime.
- const pure nothrow @property @safe short
year
(); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
- pure @property @safe void
year
(intyear
); - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.Parameters:
int year
The year
to set this DateTime'syear
to.Throws:DateTimeException if the newyear
is not a leapyear
and if the resulting date would be on February 29th.Examples:writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year); // 1999 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year); // 2010 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year); // -7
- const pure @property @safe short
yearBC
(); - Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.Throws:Examples:
writeln(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC); // 1 writeln(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC); // 2 writeln(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC); // 101
- pure @property @safe void
yearBC
(intyear
); - Year B.C. of the Gregorian Calendar counting
year
0 as 1 B.C.Parameters:int year
The year
B.C. to set this DateTime'syear
to.Throws:DateTimeException if a non-positive value is given.Examples:auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0)); dt.yearBC = 1; writeln(dt); // DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0)) dt.yearBC = 10; writeln(dt); // DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0))
- const pure nothrow @property @safe Month
month
(); - Month of a Gregorian Year.Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month); // 7 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month); // 10 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month); // 4
- pure @property @safe void
month
(Monthmonth
); - Month of a Gregorian Year.Parameters:
Month month
The month
to set this DateTime'smonth
to.Throws: - const pure nothrow @property @safe ubyte
day
(); - Day of a Gregorian Month.Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day); // 6 writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day); // 4 writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day); // 5
- pure @property @safe void
day
(intday
); - Day of a Gregorian Month.Parameters:
int day
The day
of the month to set this DateTime'sday
to.Throws: - const pure nothrow @property @safe ubyte
hour
(); - Hours past midnight.
- pure @property @safe void
hour
(inthour
); - Hours past midnight.Parameters:
int hour
The hour
of the day to set this DateTime'shour
to.Throws: - const pure nothrow @property @safe ubyte
minute
(); - Minutes past the hour.
- pure @property @safe void
minute
(intminute
); - Minutes past the hour.Parameters:
int minute
The minute
to set this DateTime'sminute
to.Throws: - const pure nothrow @property @safe ubyte
second
(); - Seconds past the minute.
- pure @property @safe void
second
(intsecond
); - Seconds past the minute.Parameters:
int second
The second
to set this DateTime'ssecond
to.Throws:DateTimeException if the given seconds would result in an invalid DateTime. - pure nothrow ref @safe DateTime
add
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years" || units == "months"); - Adds the given number of years or months to this DateTime. A negative number will subtract.Note that if day overflow is allowed, and the date with the adjusted year/month overflows the number of days in the new month, then the month will be incremented by one, and the day set to the number of days overflowed. (e.g. if the day were 31 and the new month were June, then the month would be incremented to July, and the new day would be 1). If day overflow is not allowed, then the day will be set to the last valid day in the month (e.g. June 31st would become June 30th).Parameters:
units The type of units to add
("years" or "months").long value
The number of months or years to add
to this DateTime.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow, causing the month to increment. Examples:import std.typecons : No; auto dt1 = DateTime(2010, 1, 1, 12, 30, 33); dt1.add!"months"(11); writeln(dt1); // DateTime(2010, 12, 1, 12, 30, 33) auto dt2 = DateTime(2010, 1, 1, 12, 30, 33); dt2.add!"months"(-11); writeln(dt2); // DateTime(2009, 2, 1, 12, 30, 33) auto dt3 = DateTime(2000, 2, 29, 12, 30, 33); dt3.add!"years"(1); writeln(dt3); // DateTime(2001, 3, 1, 12, 30, 33) auto dt4 = DateTime(2000, 2, 29, 12, 30, 33); dt4.add!"years"(1, No.allowDayOverflow); writeln(dt4); // DateTime(2001, 2, 28, 12, 30, 33)
- pure nothrow ref @safe DateTime
roll
(string units)(longvalue
, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (units == "years" || units == "months"); - Adds the given number of years or months to this DateTime. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. Rolling a DateTime 12 months gets the exact same DateTime. However, the days can still be affected due to the differing number of days in each month. Because there are no units larger than years, there is no difference between adding and rolling years.Parameters:
units The type of units to add ("years" or "months"). long value
The number of months or years to add to this DateTime. AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow, causing the month to increment. Examples:import std.typecons : No; auto dt1 = DateTime(2010, 1, 1, 12, 33, 33); dt1.roll!"months"(1); writeln(dt1); // DateTime(2010, 2, 1, 12, 33, 33) auto dt2 = DateTime(2010, 1, 1, 12, 33, 33); dt2.roll!"months"(-1); writeln(dt2); // DateTime(2010, 12, 1, 12, 33, 33) auto dt3 = DateTime(1999, 1, 29, 12, 33, 33); dt3.roll!"months"(1); writeln(dt3); // DateTime(1999, 3, 1, 12, 33, 33) auto dt4 = DateTime(1999, 1, 29, 12, 33, 33); dt4.roll!"months"(1, No.allowDayOverflow); writeln(dt4); // DateTime(1999, 2, 28, 12, 33, 33) auto dt5 = DateTime(2000, 2, 29, 12, 30, 33); dt5.roll!"years"(1); writeln(dt5); // DateTime(2001, 3, 1, 12, 30, 33) auto dt6 = DateTime(2000, 2, 29, 12, 30, 33); dt6.roll!"years"(1, No.allowDayOverflow); writeln(dt6); // DateTime(2001, 2, 28, 12, 30, 33)
- pure nothrow ref @safe DateTime
roll
(string units)(longvalue
)
if (units == "days"); - Adds the given number of units to this DateTime. A negative number will subtract.The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling a DateTime one year's worth of days gets the exact same DateTime. Accepted units are "days", "minutes", "hours", "minutes", and "seconds".Parameters:
units The units to add. long value
The number of units to add to this DateTime. Examples:auto dt1 = DateTime(2010, 1, 1, 11, 23, 12); dt1.roll!"days"(1); writeln(dt1); // DateTime(2010, 1, 2, 11, 23, 12) dt1.roll!"days"(365); writeln(dt1); // DateTime(2010, 1, 26, 11, 23, 12) dt1.roll!"days"(-32); writeln(dt1); // DateTime(2010, 1, 25, 11, 23, 12) auto dt2 = DateTime(2010, 7, 4, 12, 0, 0); dt2.roll!"hours"(1); writeln(dt2); // DateTime(2010, 7, 4, 13, 0, 0) auto dt3 = DateTime(2010, 1, 1, 0, 0, 0); dt3.roll!"seconds"(-1); writeln(dt3); // DateTime(2010, 1, 1, 0, 0, 59)
- const pure nothrow @safe DateTime
opBinary
(string op)(Durationduration
)
if (op == "+" || op == "-"); - Gives the result of adding or subtracting a core.time.Duration from this DateTime.The legal types of arithmetic for DateTime using this operator are
DateTime + Duration --> DateTime DateTime - Duration --> DateTime Parameters:Duration duration
The core.time.Duration to add to or subtract from this DateTime. Examples:assert(DateTime(2015, 12, 31, 23, 59, 59) + seconds(1) == DateTime(2016, 1, 1, 0, 0, 0)); assert(DateTime(2015, 12, 31, 23, 59, 59) + hours(1) == DateTime(2016, 1, 1, 0, 59, 59)); assert(DateTime(2016, 1, 1, 0, 0, 0) - seconds(1) == DateTime(2015, 12, 31, 23, 59, 59)); assert(DateTime(2016, 1, 1, 0, 59, 59) - hours(1) == DateTime(2015, 12, 31, 23, 59, 59));
- pure nothrow ref @safe DateTime
opOpAssign
(string op, D)(in Dduration
)
if ((op == "+" || op == "-") && (is(Unqual!D == Duration) || is(Unqual!D == TickDuration))); - Gives the result of adding or subtracting a
duration
from this DateTime, as well as assigning the result to this DateTime.The legal types of arithmetic for DateTime using this operator areDateTime + duration
--> DateTime DateTime - duration
--> DateTime Parameters:D duration
The duration
to add to or subtract from this DateTime. - const pure nothrow @safe Duration
opBinary
(string op)(in DateTimerhs
)
if (op == "-"); - Gives the difference between two DateTimes.The legal types of arithmetic for DateTime using this operator are
DateTime - DateTime --> duration - const pure nothrow @safe int
diffMonths
(in DateTimerhs
); - Returns the difference between the two DateTimes in months.To get the difference in years, subtract the year property of two SysTimes. To get the difference in days or weeks, subtract the SysTimes themselves and use the core.time.Duration that results. Because converting between months and smaller units requires a specific date (which core.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months. Note that the number of days in the months or how far into the month either date is is irrelevant. It is the difference in the month property combined with the difference in years * 12. So, for instance, December 31st and January 1st are one month apart just as December 1st and January 31st are one month apart.Parameters:
DateTime rhs
The DateTime to subtract from this one. Examples:assert(DateTime(1999, 2, 1, 12, 2, 3).diffMonths( DateTime(1999, 1, 31, 23, 59, 59)) == 1); assert(DateTime(1999, 1, 31, 0, 0, 0).diffMonths( DateTime(1999, 2, 1, 12, 3, 42)) == -1); assert(DateTime(1999, 3, 1, 5, 30, 0).diffMonths( DateTime(1999, 1, 1, 2, 4, 7)) == 2); assert(DateTime(1999, 1, 1, 7, 2, 4).diffMonths( DateTime(1999, 3, 31, 0, 30, 58)) == -2);
- const pure nothrow @property @safe bool
isLeapYear
(); - Whether this DateTime is in a leap year.
- const pure nothrow @property @safe DayOfWeek
dayOfWeek
(); - Day of the week this DateTime is on.
- const pure nothrow @property @safe ushort
dayOfYear
(); - Day of the year this DateTime is on.Examples:
writeln(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear); // 1 writeln(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear); // 365 writeln(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear); // 366
- pure @property @safe void
dayOfYear
(intday
); - Day of the year.Parameters:
int day
The day
of the year to set whichday
of the year this DateTime is on. - const pure nothrow @property @safe int
dayOfGregorianCal
(); - The Xth day of the Gregorian Calendar that this DateTime is on.Examples:
writeln(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal); // 1 writeln(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal); // 365 writeln(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal); // 366 writeln(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal); // 0 writeln(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal); // -365 writeln(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal); // -366 writeln(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal); // 730_120 writeln(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal); // 734_137
- pure nothrow @property @safe void
dayOfGregorianCal
(intdays
); - The Xth day of the Gregorian Calendar that this DateTime is on. Setting this property does not affect the time portion of DateTime.Parameters:
int days
The day of the Gregorian Calendar to set this DateTime to. Examples:auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0)); dt.dayOfGregorianCal = 1; writeln(dt); // DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 365; writeln(dt); // DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 366; writeln(dt); // DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 0; writeln(dt); // DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = -365; writeln(dt); // DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = -366; writeln(dt); // DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 730_120; writeln(dt); // DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0)) dt.dayOfGregorianCal = 734_137; writeln(dt); // DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0))
- const pure nothrow @property @safe ubyte
isoWeek
(); - The ISO 8601 week of the year that this DateTime is in.See Also:
- const pure nothrow @property @safe DateTime
endOfMonth
(); - DateTime for the last day in the month that this DateTime is in. The time portion of
endOfMonth
is always 23:59:59.Examples:assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonth == DateTime(Date(1999, 1, 31), TimeOfDay(23, 59, 59))); assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonth == DateTime(Date(1999, 2, 28), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonth == DateTime(Date(2000, 2, 29), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonth == DateTime(Date(2000, 6, 30), TimeOfDay(23, 59, 59)));
- const pure nothrow @property @safe ubyte
daysInMonth
(); - The last day in the month that this DateTime is in.Examples:
writeln(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth); // 31 writeln(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth); // 28 writeln(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth); // 29 writeln(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth); // 30
- const pure nothrow @property @safe bool
isAD
(); - Whether the current year is a date in A.D.Examples:
assert(DateTime(Date(1, 1, 1), TimeOfDay(12, 7, 0)).isAD); assert(DateTime(Date(2010, 12, 31), TimeOfDay(0, 0, 0)).isAD); assert(!DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)).isAD); assert(!DateTime(Date(-2010, 1, 1), TimeOfDay(2, 2, 2)).isAD);
- const pure nothrow @property @safe long
julianDay
(); - The Julian day for this DateTime at the given time. For example, prior to noon, 1996-03-31 would be the Julian day number 2_450_173, so this function returns 2_450_173, while from noon onward, the julian day number would be 2_450_174, so this function returns 2_450_174.
- const pure nothrow @property @safe long
modJulianDay
(); - The modified Julian day for any time on this date (since, the modified Julian day changes at midnight).
- const pure nothrow @safe string
toISOString
(); - Converts this DateTime to a string with the format YYYYMMDDTHHMMSS.Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOString() == "20100704T070612"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOString() == "19981225T021500"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOString() == "00000105T230959"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOString() == "-00040105T000002");
- const pure nothrow @safe string
toISOExtString
(); - Converts this DateTime to a string with the format YYYY-MM-DDTHH:MM:SS.Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtString() == "2010-07-04T07:06:12"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtString() == "1998-12-25T02:15:00"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtString() == "0000-01-05T23:09:59"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtString() == "-0004-01-05T00:00:02");
- const pure nothrow @safe string
toSimpleString
(); - Converts this DateTime to a string with the format YYYY-Mon-DD HH:MM:SS.Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() == "1998-Dec-25 02:15:00"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() == "0000-Jan-05 23:09:59"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() == "-0004-Jan-05 00:00:02");
- const pure nothrow @safe string
toString
(); - Converts this DateTime to a string.
- pure @safe DateTime
fromISOString
(S)(in SisoString
)
if (isSomeString!S); - Creates a DateTime from a string with the format YYYYMMDDTHHMMSS. Whitespace is stripped from the given string.Parameters:
S isoString
A string formatted in the ISO format for dates and times. Throws:DateTimeException if the given string is not in the ISO format or if the resulting DateTime would not be valid. - pure @safe DateTime
fromISOExtString
(S)(in SisoExtString
)
if (isSomeString!S); - Creates a DateTime from a string with the format YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.Parameters:
S isoExtString
A string formatted in the ISO Extended format for dates and times. Throws:DateTimeException if the given string is not in the ISO Extended format or if the resulting DateTime would not be valid. - pure @safe DateTime
fromSimpleString
(S)(in SsimpleString
)
if (isSomeString!S); - Creates a DateTime from a string with the format YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.Parameters:
S simpleString
A string formatted in the way that toSimpleString formats dates and times. Throws:DateTimeException if the given string is not in the correct format or if the resulting DateTime would not be valid. - static pure nothrow @property @safe DateTime
min
(); - static pure nothrow @property @safe DateTime
max
();
- struct
Interval
(TP); - Represents an interval of time.An
Interval
has a starting point and an end point. The interval of time is therefore the time starting at the starting point up to, but not including, the end point. e.g.
A range can be obtained from an[January 5th, 2010 - March 10th, 2010) [05:00:30 - 12:00:00) [1982-01-04T08:59:00 - 2010-07-04T12:00:00) Interval
, allowing iteration over that interval, with the exact time points which are iterated over depending on the function which generates the range.- pure this(U)(in TP
begin
, in Uend
)
if (is(Unqual!TP == Unqual!U)); - Parameters:
TP begin
The time point which begins the interval. U end
The time point which ends (but is not included in) the interval. Throws:Example:
Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
- pure this(D)(in TP
begin
, in Dduration
)
if (__traits(compiles,begin
+duration
)); - Parameters:
TP begin
The time point which begins the interval. D duration
The duration
from the starting point to the end point.Throws:Example:
assert(Interval!Date(Date(1996, 1, 2), dur!"days"(3)) == Interval!Date(Date(1996, 1, 2), Date(1996, 1, 5)));
- pure nothrow ref Interval
opAssign
(ref const Intervalrhs
); - Parameters:
Interval rhs
The Interval to assign to this one. - pure nothrow ref Interval
opAssign
(Intervalrhs
); - Parameters:
Interval rhs
The Interval to assign to this one. - const pure nothrow @property TP
begin
(); - The starting point of the interval. It is included in the interval.
Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).begin == Date(1996, 1, 2));
- pure @property void
begin
(TPtimePoint
); - The starting point of the interval. It is included in the interval.Parameters:
TP timePoint
The time point to set begin
to.Throws:DateTimeException if the resulting interval would be invalid. - const pure nothrow @property TP
end
(); - The
end
point of the interval. It is excluded from the interval.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).end == Date(2012, 3, 1));
- pure @property void
end
(TPtimePoint
); - The
end
point of the interval. It is excluded from the interval.Parameters:TP timePoint
The time point to set end
to.Throws:DateTimeException if the resulting interval would be invalid. - const pure nothrow @property auto
length
(); - Returns the duration between begin and end.
Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).length == dur!"days"(5903));
- const pure nothrow @property bool
empty
(); - Whether the interval's length is 0, that is, whether begin == end.
Example:
assert(Interval!Date(Date(1996, 1, 2), Date(1996, 1, 2)).empty); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).empty);
- const pure bool
contains
(in TPtimePoint
); - Whether the given time point is within this interval.Parameters:
TP timePoint
The time point to check for inclusion in this interval. Throws:DateTimeException if this interval is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Date(1994, 12, 24))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Date(2000, 1, 5))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Date(2012, 3, 1)));
- const pure bool
contains
(in Intervalinterval
); - Whether the given
interval
is completely within thisinterval
.Parameters:Interval interval
The interval
to check for inclusion in thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
- const pure bool
contains
(in PosInfInterval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Always returnsfalse
(unless thisinterval
is empty), because aninterval
going to positive infinity can never be contained in a finiteinterval
.Parameters:PosInfInterval!TP interval
The interval
to check for inclusion in thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( PosInfInterval!Date(Date(1999, 5, 4))));
- const pure bool
contains
(in NegInfInterval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Always returnsfalse
(unless thisinterval
is empty), because aninterval
beginning at negative infinity can never be contained in a finiteinterval
.Parameters:NegInfInterval!TP interval
The interval
to check for inclusion in thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains( NegInfInterval!Date(Date(1996, 5, 4))));
- const pure bool
isBefore
(in TPtimePoint
); - Whether this interval is before the given time point.Parameters:
TP timePoint
The time point to check whether this interval is before it. Throws:DateTimeException if this interval is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Date(1994, 12, 24))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Date(2000, 1, 5))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Date(2012, 3, 1)));
- const pure bool
isBefore
(in Intervalinterval
); - Whether this
interval
is before the giveninterval
and does not intersect with it.Parameters:Interval interval
The interval
to check for against thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( Interval!Date(Date(2012, 3, 1), Date(2013, 5, 1))));
- const pure bool
isBefore
(in PosInfInterval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect with it.Parameters:PosInfInterval!TP interval
The interval
to check for against thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( PosInfInterval!Date(Date(1999, 5, 4)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( PosInfInterval!Date(Date(2013, 3, 7))));
- const pure bool
isBefore
(in NegInfInterval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect with it.Always returnsfalse
(unless thisinterval
is empty) because a finiteinterval
can never be before aninterval
beginning at negative infinity.Parameters:NegInfInterval!TP interval
The interval
to check for against thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore( NegInfInterval!Date(Date(1996, 5, 4))));
- const pure bool
isAfter
(in TPtimePoint
); - Whether this interval is after the given time point.Parameters:
TP timePoint
The time point to check whether this interval is after it. Throws:DateTimeException if this interval is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Date(1994, 12, 24))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Date(2000, 1, 5))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Date(2012, 3, 1)));
- const pure bool
isAfter
(in Intervalinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Parameters:Interval interval
The interval
to check against thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
- const pure bool
isAfter
(in PosInfInterval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Always returnsfalse
(unless thisinterval
is empty) because a finiteinterval
can never be after aninterval
going to positive infinity.Parameters:PosInfInterval!TP interval
The interval
to check against thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( PosInfInterval!Date(Date(1999, 5, 4))));
- const pure bool
isAfter
(in NegInfInterval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Parameters:NegInfInterval!TP interval
The interval
to check against thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter( NegInfInterval!Date(Date(1996, 1, 2))));
- const pure bool
intersects
(in Intervalinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:Interval interval
The interval
to check for intersection with thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
- const pure bool
intersects
(in PosInfInterval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:PosInfInterval!TP interval
The interval
to check for intersection with thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( PosInfInterval!Date(Date(1999, 5, 4)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure bool
intersects
(in NegInfInterval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:NegInfInterval!TP interval
The interval
to check for intersection with thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( NegInfInterval!Date(Date(1996, 1, 2)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersects( NegInfInterval!Date(Date(2000, 1, 2))));
- const Interval
intersection
(in Intervalinterval
); - Returns the
intersection
of two intervalsParameters:Interval interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect or if eitherinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
- const Interval
intersection
(in PosInfInterval!TPinterval
); - Returns the
intersection
of two intervalsParameters:PosInfInterval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect or if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( PosInfInterval!Date(Date(1990, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( PosInfInterval!Date(Date(1999, 1, 12))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
- const Interval
intersection
(in NegInfInterval!TPinterval
); - Returns the
intersection
of two intervalsParameters:NegInfInterval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect or if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( NegInfInterval!Date(Date(1999, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).intersection( NegInfInterval!Date(Date(2013, 1, 12))) == Interval!Date(Date(1996, 1 , 2), Date(2012, 3, 1)));
- const pure bool
isAdjacent
(in Intervalinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:Interval interval
The interval
to check whether its adjecent to thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(1990, 7, 6), Date(1996, 1, 2)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(2012, 3, 1), Date(2013, 9, 17)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(1989, 3, 1), Date(2012, 3, 1))));
- const pure bool
isAdjacent
(in PosInfInterval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:PosInfInterval!TP interval
The interval
to check whether its adjecent to thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( PosInfInterval!Date(Date(1999, 5, 4)))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure bool
isAdjacent
(in NegInfInterval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:NegInfInterval!TP interval
The interval
to check whether its adjecent to thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( NegInfInterval!Date(Date(1996, 1, 2)))); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAdjacent( NegInfInterval!Date(Date(2000, 1, 2))));
- const Interval
merge
(in Intervalinterval
); - Returns the union of two intervalsParameters:
Interval interval
The interval
tomerge
with thisinterval
.Throws:DateTimeException if the two intervals do not intersect and are not adjacent or if eitherinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
- const PosInfInterval!TP
merge
(in PosInfInterval!TPinterval
); - Returns the union of two intervalsParameters:
PosInfInterval!TP interval
The interval
tomerge
with thisinterval
.Throws:DateTimeException if the two intervals do not intersect and are not adjacent or if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( PosInfInterval!Date(Date(2012, 3, 1))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- const NegInfInterval!TP
merge
(in NegInfInterval!TPinterval
); - Returns the union of two intervalsParameters:
NegInfInterval!TP interval
The interval
tomerge
with thisinterval
.Throws:DateTimeException if the two intervals do not intersect and are not adjacent or if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( NegInfInterval!Date(Date(1996, 1, 2))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).merge( NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
- const pure Interval
span
(in Intervalinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:Interval interval
The interval
to create aspan
together with thisinterval
.Throws:DateTimeException if eitherinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( Interval!Date(Date(1990, 7, 6), Date(1991, 1, 8))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( Interval!Date(Date(2012, 3, 1), Date(2013, 5, 7))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 5, 7)));
- const pure PosInfInterval!TP
span
(in PosInfInterval!TPinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:PosInfInterval!TP interval
The interval
to create aspan
together with thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( PosInfInterval!Date(Date(2050, 1, 1))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- const pure NegInfInterval!TP
span
(in NegInfInterval!TPinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:NegInfInterval!TP interval
The interval
to create aspan
together with thisinterval
.Throws:DateTimeException if thisinterval
is empty.Example:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( NegInfInterval!Date(Date(1602, 5, 21))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).span( NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
- pure void
shift
(D)(Dduration
)
if (__traits(compiles, begin +duration
)); - Shifts the interval forward or backwards in time by the given
duration
(a positiveduration
shifts the interval forward; a negativeduration
shifts it backward). Effectively, it does begin +=duration
and end +=duration
.Parameters:D duration
The duration
toshift
the interval by.Throws:DateTimeException this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5)); auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 4, 5)); interval1.shift(dur!"days"(50)); assert(interval1 == Interval!Date(Date(1996, 2, 21), Date(2012, 5, 25))); interval2.shift(dur!"days"(-50)); assert(interval2 == Interval!Date(Date(1995, 11, 13), Date(2012, 2, 15)));
- void
shift
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (isIntegral!T); - Shifts the interval forward or backwards in time by the given number of
years
and/ormonths
(a positive number ofyears
andmonths
shifts the interval forward; a negative number shifts it backward). It adds theyears
the givenyears
andmonths
to both begin and end. It effectively calls add!"years
"() and then add!"months
"() on begin and end with the given number ofyears
andmonths
.Parameters:T years
The number of years
toshift
the interval by.T months
The number of months
toshift
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on begin and end, causing their month to increment. Throws:DateTimeException if this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); interval1.shift(2); assert(interval1 == Interval!Date(Date(1998, 1, 2), Date(2014, 3, 1))); interval2.shift(-2); assert(interval2 == Interval!Date(Date(1994, 1, 2), Date(2010, 3, 1)));
- pure void
expand
(D)(Dduration
, Directiondir
= Direction.both)
if (__traits(compiles, begin +duration
)); - Expands the interval forwards and/or backwards in time. Effectively, it does begin -=
duration
and/or end +=duration
. Whether it expands forwards and/or backwards in time is determined bydir
.Parameters:D duration
The duration
toexpand
the interval by.Direction dir
The direction in time to expand
the interval.Throws:DateTimeException this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); interval1.expand(2); assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1))); interval2.expand(-2); assert(interval2 == Interval!Date(Date(1998, 1, 2), Date(2010, 3, 1)));
- void
expand
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow, Directiondir
= Direction.both)
if (isIntegral!T); - Expands the interval forwards and/or backwards in time. Effectively, it subtracts the given number of
months
/years
from begin and adds them to end. Whether it expands forwards and/or backwards in time is determined bydir
.Parameters:T years
The number of years
toexpand
the interval by.T months
The number of months
toexpand
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on begin and end, causing their month to increment. Direction dir
The direction in time to expand
the interval.Throws:DateTimeException if this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); auto interval2 = Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)); interval1.expand(2); assert(interval1 == Interval!Date(Date(1994, 1, 2), Date(2014, 3, 1))); interval2.expand(-2); assert(interval2 == Interval!Date(Date(1998, 1, 2), Date(2010, 3, 1)));
- const IntervalRange!(TP, Direction.fwd)
fwdRange
(TP delegate(in TP)func
, PopFirstpopFirst
= No.popFirst
); - Returns a range which iterates forward over the interval, starting at begin, using
func
to generate each successive time point.The range's front is the interval's begin.func
is used to generate the next front when popFront is called. IfpopFirst
is Yes.popFirst
, then popFront is called before the range is returned (so that front is a time point whichfunc
would generate). Iffunc
ever generates a time point less than or equal to the current front of the range, then a DateTimeException will be thrown. The range will be empty and iteration complete whenfunc
generates a time point equal to or beyond the end of the interval. There are helper functions in this module which generate common delegates to pass tofwdRange
. Their documentation starts with "Range-generating function," making them easily searchable.Parameters:TP delegate(in TP) func
The function used to generate the time points of the range over the interval. PopFirst popFirst
Whether popFront should be called on the range before returning it. Throws:DateTimeException if this interval is empty.Warning:
Iffunc
must be logically pure. Ideally,func
would be a function pointer to a pure function, but forcingfunc
to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass tofwdRange
,func
must be a delegate.func
retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. To avoid such bugs, don't pass a delegate which is not logically pure tofwdRange
. Iffunc
is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant if when creating a custom delegate.Example:
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9)); auto func = delegate (in Date date) //For iterating over even-numbered days. { if ((date.day & 1) == 0) return date + dur!"days"(2); return date + dur!"days"(1); }; auto range = interval.fwdRange(func); //An odd day. Using Yes.popFirst would have made this Date(2010, 9, 2). assert(range.front == Date(2010, 9, 1)); range.popFront(); assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2010, 9, 4)); range.popFront(); assert(range.front == Date(2010, 9, 6)); range.popFront(); assert(range.front == Date(2010, 9, 8)); range.popFront(); assert(range.empty);
- const IntervalRange!(TP, Direction.bwd)
bwdRange
(TP delegate(in TP)func
, PopFirstpopFirst
= No.popFirst
); - Returns a range which iterates backwards over the interval, starting at end, using
func
to generate each successive time point.The range's front is the interval's end.func
is used to generate the next front when popFront is called. IfpopFirst
is Yes.popFirst
, then popFront is called before the range is returned (so that front is a time point whichfunc
would generate). Iffunc
ever generates a time point greater than or equal to the current front of the range, then a DateTimeException will be thrown. The range will be empty and iteration complete whenfunc
generates a time point equal to or less than the begin of the interval. There are helper functions in this module which generate common delegates to pass tobwdRange
. Their documentation starts with "Range-generating function," making them easily searchable.Parameters:TP delegate(in TP) func
The function used to generate the time points of the range over the interval. PopFirst popFirst
Whether popFront should be called on the range before returning it. Throws:DateTimeException if this interval is empty.Warning:
Iffunc
must be logically pure. Ideally,func
would be a function pointer to a pure function, but forcingfunc
to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange,func
must be a delegate.func
retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. To avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. Iffunc
is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant for custom delegates.Example:
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9)); auto func = delegate (in Date date) //For iterating over even-numbered days. { if ((date.day & 1) == 0) return date - dur!"days"(2); return date - dur!"days"(1); }; auto range = interval.bwdRange(func); //An odd day. Using Yes.popFirst would have made this Date(2010, 9, 8). assert(range.front == Date(2010, 9, 9)); range.popFront(); assert(range.front == Date(2010, 9, 8)); range.popFront(); assert(range.front == Date(2010, 9, 6)); range.popFront(); assert(range.front == Date(2010, 9, 4)); range.popFront(); assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.empty);
- const nothrow string
toString
(); - Converts this interval to a string.
- struct
PosInfInterval
(TP); - Represents an interval of time which has positive infinity as its end point.Any ranges which iterate over a
PosInfInterval
are infinite. So, the main purpose of usingPosInfInterval
is to create an infinite range which starts at a fixed point in time and goes to positive infinity.- pure nothrow this(in TP
begin
); - Parameters:
TP begin
The time point which begins the interval. Example:
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
- pure nothrow ref PosInfInterval
opAssign
(ref const PosInfIntervalrhs
); - Parameters:
PosInfInterval rhs
The PosInfInterval to assign to this one. - pure nothrow ref PosInfInterval
opAssign
(PosInfIntervalrhs
); - Parameters:
PosInfInterval rhs
The PosInfInterval to assign to this one. - const pure nothrow @property TP
begin
(); - The starting point of the interval. It is included in the interval.
Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).begin == Date(1996, 1, 2));
- pure nothrow @property void
begin
(TPtimePoint
); - The starting point of the interval. It is included in the interval.Parameters:
TP timePoint
The time point to set begin
to. - enum bool
empty
; - Whether the interval's length is 0. Always returns
false
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).empty);
- const pure nothrow bool
contains
(TPtimePoint
); - Whether the given time point is within this interval.Parameters:
TP timePoint
The time point to check for inclusion in this interval. Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(1994, 12, 24))); assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(2000, 1, 5)));
- const pure bool
contains
(in Interval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Parameters:Interval!TP interval
The interval
to check for inclusion in thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).contains( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).contains( Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
- const pure nothrow bool
contains
(in PosInfIntervalinterval
); - Whether the given
interval
is completely within thisinterval
.Parameters:PosInfInterval interval
The interval
to check for inclusion in thisinterval
.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).contains( PosInfInterval!Date(Date(1999, 5, 4)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains( PosInfInterval!Date(Date(1995, 7, 2))));
- const pure nothrow bool
contains
(in NegInfInterval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Always returnsfalse
because aninterval
going to positive infinity can never contain aninterval
beginning at negative infinity.Parameters:NegInfInterval!TP interval
The interval
to check for inclusion in thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains( NegInfInterval!Date(Date(1996, 5, 4))));
- const pure nothrow bool
isBefore
(in TPtimePoint
); - Whether this interval is before the given time point.Always returns
false
because an interval going to positive infinity can never be before any time point.Parameters:TP timePoint
The time point to check whether this interval is before it. Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(1994, 12, 24))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(2000, 1, 5)));
- const pure bool
isBefore
(in Interval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Always returnsfalse
(unless the giveninterval
is empty) because aninterval
going to positive infinity can never be before any otherinterval
.Parameters:Interval!TP interval
The interval
to check for against thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
- const pure nothrow bool
isBefore
(in PosInfIntervalinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
going to positive infinity can never be before any otherinterval
.Parameters:PosInfInterval interval
The interval
to check for against thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore( PosInfInterval!Date(Date(1992, 5, 4)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore( PosInfInterval!Date(Date(2013, 3, 7))));
- const pure nothrow bool
isBefore
(in NegInfInterval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
going to positive infinity can never be before any otherinterval
.Parameters:NegInfInterval!TP interval
The interval
to check for against thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore( NegInfInterval!Date(Date(1996, 5, 4))));
- const pure nothrow bool
isAfter
(in TPtimePoint
); - Whether this interval is after the given time point.Parameters:
TP timePoint
The time point to check whether this interval is after it. Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(1994, 12, 24))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(2000, 1, 5)));
- const pure bool
isAfter
(in Interval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Parameters:Interval!TP interval
The interval
to check against thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter( Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
- const pure nothrow bool
isAfter
(in PosInfIntervalinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
going to positive infinity can never be after anotherinterval
going to positive infinity.Parameters:PosInfInterval interval
The interval
to check against thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter( PosInfInterval!Date(Date(1990, 1, 7)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter( PosInfInterval!Date(Date(1999, 5, 4))));
- const pure nothrow bool
isAfter
(in NegInfInterval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Parameters:NegInfInterval!TP interval
The interval
to check against thisinterval
.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter( NegInfInterval!Date(Date(1996, 1, 2)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter( NegInfInterval!Date(Date(2000, 7, 1))));
- const pure bool
intersects
(in Interval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:Interval!TP interval
The interval
to check for intersection with thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects( Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2))));
- const pure nothrow bool
intersects
(in PosInfIntervalinterval
); - Whether the given
interval
overlaps thisinterval
.Always returnstrue
because two intervals going to positive infinity always overlap.Parameters:PosInfInterval interval
The interval
to check for intersection with thisinterval
.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects( PosInfInterval!Date(Date(1990, 1, 7)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects( PosInfInterval!Date(Date(1999, 5, 4))));
- const pure nothrow bool
intersects
(in NegInfInterval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:NegInfInterval!TP interval
The interval
to check for intersection with thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).intersects( NegInfInterval!Date(Date(1996, 1, 2)))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersects( NegInfInterval!Date(Date(2000, 7, 1))));
- const Interval!TP
intersection
(in Interval!TPinterval
); - Returns the
intersection
of two intervalsParameters:Interval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect or if the giveninterval
is empty.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1996, 1 , 2), Date(2000, 8, 2))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == Interval!Date(Date(1999, 1 , 12), Date(2011, 9, 17)));
- const pure nothrow PosInfInterval
intersection
(in PosInfIntervalinterval
); - Returns the
intersection
of two intervalsParameters:PosInfInterval interval
The interval
to intersect with thisinterval
.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1996, 1 , 2))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1999, 1 , 12)));
- const Interval!TP
intersection
(in NegInfInterval!TPinterval
); - Returns the
intersection
of two intervalsParameters:NegInfInterval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( NegInfInterval!Date(Date(1999, 7, 6))) == Interval!Date(Date(1996, 1 , 2), Date(1999, 7, 6))); assert(PosInfInterval!Date(Date(1996, 1, 2)).intersection( NegInfInterval!Date(Date(2013, 1, 12))) == Interval!Date(Date(1996, 1 , 2), Date(2013, 1, 12)));
- const pure bool
isAdjacent
(in Interval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:Interval!TP interval
The interval
to check whether its adjecent to thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent( Interval!Date(Date(1989, 3, 1), Date(1996, 1, 2)))); assert(!PosInfInterval!Date(Date(1999, 1, 12)).isAdjacent( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))));
- const pure nothrow bool
isAdjacent
(in PosInfIntervalinterval
); - Whether the given
interval
is adjacent to thisinterval
.Always returnsfalse
because two intervals going to positive infinity can never be adjacent to one another.Parameters:PosInfInterval interval
The interval
to check whether its adjecent to thisinterval
.Example:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent( PosInfInterval!Date(Date(1990, 1, 7)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent( PosInfInterval!Date(Date(1996, 1, 2))));
- const pure nothrow bool
isAdjacent
(in NegInfInterval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:NegInfInterval!TP interval
The interval
to check whether its adjecent to thisinterval
.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent( NegInfInterval!Date(Date(1996, 1, 2)))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAdjacent( NegInfInterval!Date(Date(2000, 7, 1))));
- const PosInfInterval
merge
(in Interval!TPinterval
); - Returns the union of two intervalsParameters:
Interval!TP interval
The interval
tomerge
with thisinterval
.Throws:DateTimeException if the two intervals do not intersect and are not adjacent or if the giveninterval
is empty.Note: There is no overload for
merge
which takes a NegInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(PosInfInterval!Date(Date(1996, 1, 2)).merge( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- const pure nothrow PosInfInterval
merge
(in PosInfIntervalinterval
); - Returns the union of two intervalsParameters:
PosInfInterval interval
The interval
tomerge
with thisinterval
.Note: There is no overload for
merge
which takes a NegInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).merge( PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(PosInfInterval!Date(Date(1996, 1, 2)).merge( PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- const pure PosInfInterval
span
(in Interval!TPinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:Interval!TP interval
The interval
to create aspan
together with thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Note: There is no overload for
span
which takes a NegInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).span( Interval!Date(Date(500, 8, 9), Date(1602, 1, 31))) == PosInfInterval!Date(Date(500, 8, 9))); assert(PosInfInterval!Date(Date(1996, 1, 2)).span( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(PosInfInterval!Date(Date(1996, 1, 2)).span( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- const pure nothrow PosInfInterval
span
(in PosInfIntervalinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:PosInfInterval interval
The interval
to create aspan
together with thisinterval
.Note: There is no overload for
span
which takes a NegInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(PosInfInterval!Date(Date(1996, 1, 2)).span( PosInfInterval!Date(Date(1990, 7, 6))) == PosInfInterval!Date(Date(1990, 7 , 6))); assert(PosInfInterval!Date(Date(1996, 1, 2)).span( PosInfInterval!Date(Date(1999, 1, 12))) == PosInfInterval!Date(Date(1996, 1 , 2)));
- pure nothrow void
shift
(D)(Dduration
)
if (__traits(compiles, begin +duration
)); - Shifts the begin of this interval forward or backwards in time by the given
duration
(a positiveduration
shifts the interval forward; a negativeduration
shifts it backward). Effectively, it does begin +=duration
.Parameters:D duration
The duration
toshift
the interval by.Example:
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2)); auto interval2 = PosInfInterval!Date(Date(1996, 1, 2)); interval1.shift(dur!"days"(50)); assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21))); interval2.shift(dur!"days"(-50)); assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
- void
shift
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (isIntegral!T); - Shifts the begin of this interval forward or backwards in time by the given number of
years
and/ormonths
(a positive number ofyears
andmonths
shifts the interval forward; a negative number shifts it backward). It adds theyears
the givenyears
andmonths
to begin. It effectively calls add!"years
"() and then add!"months
"() on begin with the given number ofyears
andmonths
.Parameters:T years
The number of years
toshift
the interval by.T months
The number of months
toshift
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on begin, causing its month to increment. Throws:DateTimeException if this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2)); auto interval2 = PosInfInterval!Date(Date(1996, 1, 2)); interval1.shift(dur!"days"(50)); assert(interval1 == PosInfInterval!Date(Date(1996, 2, 21))); interval2.shift(dur!"days"(-50)); assert(interval2 == PosInfInterval!Date(Date(1995, 11, 13)));
- pure nothrow void
expand
(D)(Dduration
)
if (__traits(compiles, begin +duration
)); - Expands the interval backwards in time. Effectively, it does begin -=
duration
.Parameters:D duration
The duration
toexpand
the interval by.Example:
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2)); auto interval2 = PosInfInterval!Date(Date(1996, 1, 2)); interval1.expand(dur!"days"(2)); assert(interval1 == PosInfInterval!Date(Date(1995, 12, 31))); interval2.expand(dur!"days"(-2)); assert(interval2 == PosInfInterval!Date(Date(1996, 1, 4)));
- void
expand
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (isIntegral!T); - Expands the interval forwards and/or backwards in time. Effectively, it subtracts the given number of
months
/years
from begin.Parameters:T years
The number of years
toexpand
the interval by.T months
The number of months
toexpand
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on begin, causing its month to increment. Throws:DateTimeException if this interval is empty or if the resulting interval would be invalid.Example:
auto interval1 = PosInfInterval!Date(Date(1996, 1, 2)); auto interval2 = PosInfInterval!Date(Date(1996, 1, 2)); interval1.expand(2); assert(interval1 == PosInfInterval!Date(Date(1994, 1, 2))); interval2.expand(-2); assert(interval2 == PosInfInterval!Date(Date(1998, 1, 2)));
- const PosInfIntervalRange!TP
fwdRange
(TP delegate(in TP)func
, PopFirstpopFirst
= No.popFirst
); - Returns a range which iterates forward over the interval, starting at begin, using
func
to generate each successive time point.The range's front is the interval's begin.func
is used to generate the next front when popFront is called. IfpopFirst
is Yes.popFirst
, then popFront is called before the range is returned (so that front is a time point whichfunc
would generate). Iffunc
ever generates a time point less than or equal to the current front of the range, then a DateTimeException will be thrown. There are helper functions in this module which generate common delegates to pass tofwdRange
. Their documentation starts with "Range-generating function," to make them easily searchable.Parameters:TP delegate(in TP) func
The function used to generate the time points of the range over the interval. PopFirst popFirst
Whether popFront should be called on the range before returning it. Throws:DateTimeException if this interval is empty.Warning:
Iffunc
must be logically pure. Ideally,func
would be a function pointer to a pure function, but forcingfunc
to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass tofwdRange
,func
must be a delegate.func
retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. To avoid such bugs, don't pass a delegate which is not logically pure tofwdRange
. Iffunc
is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant for custom delegates.Example:
auto interval = PosInfInterval!Date(Date(2010, 9, 1)); auto func = delegate (in Date date) //For iterating over even-numbered days. { if ((date.day & 1) == 0) return date + dur!"days"(2); return date + dur!"days"(1); }; auto range = interval.fwdRange(func); //An odd day. Using Yes.popFirst would have made this Date(2010, 9, 2). assert(range.front == Date(2010, 9, 1)); range.popFront(); assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2010, 9, 4)); range.popFront(); assert(range.front == Date(2010, 9, 6)); range.popFront(); assert(range.front == Date(2010, 9, 8)); range.popFront(); assert(!range.empty);
- const nothrow string
toString
(); - Converts this interval to a string.
- struct
NegInfInterval
(TP); - Represents an interval of time which has negative infinity as its starting point.Any ranges which iterate over a
NegInfInterval
are infinite. So, the main purpose of usingNegInfInterval
is to create an infinite range which starts at negative infinity and goes to a fixed end point. Iterate over it in reverse.- pure nothrow this(in TP
end
); - Parameters:
TP end
The time point which ends the interval. Example:
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
- pure nothrow ref NegInfInterval
opAssign
(ref const NegInfIntervalrhs
); - Parameters:
NegInfInterval rhs
The NegInfInterval to assign to this one. - pure nothrow ref NegInfInterval
opAssign
(NegInfIntervalrhs
); - Parameters:
NegInfInterval rhs
The NegInfInterval to assign to this one. - const pure nothrow @property TP
end
(); - The
end
point of the interval. It is excluded from the interval.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).end == Date(2012, 3, 1));
- pure nothrow @property void
end
(TPtimePoint
); - The
end
point of the interval. It is excluded from the interval.Parameters:TP timePoint
The time point to set end
to. - enum bool
empty
; - Whether the interval's length is 0. Always returns
false
.Example:
assert(!NegInfInterval!Date(Date(1996, 1, 2)).empty);
- const pure nothrow bool
contains
(TPtimePoint
); - Whether the given time point is within this interval.Parameters:
TP timePoint
The time point to check for inclusion in this interval. Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(1994, 12, 24))); assert(NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2000, 1, 5))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(Date(2012, 3, 1)));
- const pure bool
contains
(in Interval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Parameters:Interval!TP interval
The interval
to check for inclusion in thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).contains( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains( Interval!Date(Date(1998, 2, 28), Date(2013, 5, 1))));
- const pure nothrow bool
contains
(in PosInfInterval!TPinterval
); - Whether the given
interval
is completely within thisinterval
.Always returnsfalse
because aninterval
beginning at negative infinity can never contain aninterval
going to positive infinity.Parameters:PosInfInterval!TP interval
The interval
to check for inclusion in thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains( PosInfInterval!Date(Date(1999, 5, 4))));
- const pure nothrow bool
contains
(in NegInfIntervalinterval
); - Whether the given
interval
is completely within thisinterval
.Parameters:NegInfInterval interval
The interval
to check for inclusion in thisinterval
.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).contains( NegInfInterval!Date(Date(1996, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains( NegInfInterval!Date(Date(2013, 7, 9))));
- const pure nothrow bool
isBefore
(in TPtimePoint
); - Whether this interval is before the given time point.Parameters:
TP timePoint
The time point to check whether this interval is before it. Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(1994, 12, 24))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2000, 1, 5))); assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore(Date(2012, 3, 1)));
- const pure bool
isBefore
(in Interval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Parameters:Interval!TP interval
The interval
to check for against thisinterval
.Throws:DateTimeException if the giveninterval
is emptyExample:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore( Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
- const pure nothrow bool
isBefore
(in PosInfInterval!TPinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Parameters:PosInfInterval!TP interval
The interval
to check for against thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore( PosInfInterval!Date(Date(1999, 5, 4)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).isBefore( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure nothrow bool
isBefore
(in NegInfIntervalinterval
); - Whether this
interval
is before the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
beginning at negative infinity can never be before anotherinterval
beginning at negative infinity.Parameters:NegInfInterval interval
The interval
to check for against thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore( NegInfInterval!Date(Date(1996, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isBefore( NegInfInterval!Date(Date(2013, 7, 9))));
- const pure nothrow bool
isAfter
(in TPtimePoint
); - Whether this interval is after the given time point.Always returns
false
because an interval beginning at negative infinity can never be after any time point.Parameters:TP timePoint
The time point to check whether this interval is after it. Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(1994, 12, 24))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2000, 1, 5))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter(Date(2012, 3, 1)));
- const pure bool
isAfter
(in Interval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Always returnsfalse
(unless the giveninterval
is empty) because aninterval
beginning at negative infinity can never be after any otherinterval
.Parameters:Interval!TP interval
The interval
to check against thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
- const pure nothrow bool
isAfter
(in PosInfInterval!TPinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
beginning at negative infinity can never be after any otherinterval
.Parameters:PosInfInterval!TP interval
The interval
to check against thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( PosInfInterval!Date(Date(1999, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure nothrow bool
isAfter
(in NegInfIntervalinterval
); - Whether this
interval
is after the giveninterval
and does not intersect it.Always returnsfalse
because aninterval
beginning at negative infinity can never be after any otherinterval
.Parameters:NegInfInterval interval
The interval
to check against thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( NegInfInterval!Date(Date(1996, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAfter( NegInfInterval!Date(Date(2013, 7, 9))));
- const pure bool
intersects
(in Interval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:Interval!TP interval
The interval
to check for intersection with thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects( Interval!Date(Date(1999, 1, 12), Date(2011, 9, 17)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects( Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
- const pure nothrow bool
intersects
(in PosInfInterval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Parameters:PosInfInterval!TP interval
The interval
to check for intersection with thisinterval
.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects( PosInfInterval!Date(Date(1999, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).intersects( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure nothrow bool
intersects
(in NegInfInterval!TPinterval
); - Whether the given
interval
overlaps thisinterval
.Always returnstrue
because two intervals beginning at negative infinity always overlap.Parameters:NegInfInterval!TP interval
The interval
to check for intersection with thisinterval
.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects( NegInfInterval!Date(Date(1996, 5, 4)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).intersects( NegInfInterval!Date(Date(2013, 7, 9))));
- const Interval!TP
intersection
(in Interval!TPinterval
); - Returns the
intersection
of two intervalsParameters:Interval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect or if the giveninterval
is empty.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == Interval!Date(Date(1990, 7 , 6), Date(2000, 8, 2))); assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
- const Interval!TP
intersection
(in PosInfInterval!TPinterval
); - Returns the
intersection
of two intervalsParameters:PosInfInterval!TP interval
The interval
to intersect with thisinterval
.Throws:DateTimeException if the two intervals do not intersect.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( PosInfInterval!Date(Date(1990, 7, 6))) == Interval!Date(Date(1990, 7 , 6), Date(2012, 3, 1))); assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( PosInfInterval!Date(Date(1999, 1, 12))) == Interval!Date(Date(1999, 1 , 12), Date(2012, 3, 1)));
- const nothrow NegInfInterval
intersection
(in NegInfIntervalinterval
); - Returns the
intersection
of two intervalsParameters:NegInfInterval interval
The interval
to intersect with thisinterval
.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(1999, 7 , 6))); assert(NegInfInterval!Date(Date(2012, 3, 1)).intersection( NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2012, 3 , 1)));
- const pure bool
isAdjacent
(in Interval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:Interval!TP interval
The interval
to check whether its adjecent to thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(1999, 1, 12), Date(2012, 3, 1)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(2012, 3, 1), Date(2019, 2, 2)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( Interval!Date(Date(2022, 10, 19), Date(2027, 6, 3))));
- const pure nothrow bool
isAdjacent
(in PosInfInterval!TPinterval
); - Whether the given
interval
is adjacent to thisinterval
.Parameters:PosInfInterval!TP interval
The interval
to check whether its adjecent to thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( PosInfInterval!Date(Date(1999, 5, 4)))); assert(NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( PosInfInterval!Date(Date(2012, 3, 1))));
- const pure nothrow bool
isAdjacent
(in NegInfIntervalinterval
); - Whether the given
interval
is adjacent to thisinterval
.Always returnsfalse
because two intervals beginning at negative infinity can never be adjacent to one another.Parameters:NegInfInterval interval
The interval
to check whether its adjecent to thisinterval
.Example:
assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( NegInfInterval!Date(Date(1996, 5, 4)))); assert(!NegInfInterval!Date(Date(2012, 3, 1)).isAdjacent( NegInfInterval!Date(Date(2012, 3, 1))));
- const NegInfInterval
merge
(in Interval!TPinterval
); - Returns the union of two intervalsParameters:
Interval!TP interval
The interval
tomerge
with thisinterval
.Throws:DateTimeException if the two intervals do not intersect and are not adjacent or if the giveninterval
is empty.Note: There is no overload for
merge
which takes a PosInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(NegInfInterval!Date(Date(2012, 3, 1)).merge( Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == NegInfInterval!Date(Date(2015, 9 , 2)));
- const pure nothrow NegInfInterval
merge
(in NegInfIntervalinterval
); - Returns the union of two intervalsParameters:
NegInfInterval interval
The interval
tomerge
with thisinterval
.Note: There is no overload for
merge
which takes a PosInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).merge( NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(NegInfInterval!Date(Date(2012, 3, 1)).merge( NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
- const pure NegInfInterval
span
(in Interval!TPinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:Interval!TP interval
The interval
to create aspan
together with thisinterval
.Throws:DateTimeException if the giveninterval
is empty.Note: There is no overload for
span
which takes a PosInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).span( Interval!Date(Date(1990, 7, 6), Date(2000, 8, 2))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(NegInfInterval!Date(Date(2012, 3, 1)).span( Interval!Date(Date(1999, 1, 12), Date(2015, 9, 2))) == NegInfInterval!Date(Date(2015, 9 , 2))); assert(NegInfInterval!Date(Date(1600, 1, 7)).span( Interval!Date(Date(2012, 3, 11), Date(2017, 7, 1))) == NegInfInterval!Date(Date(2017, 7 , 1)));
- const pure nothrow NegInfInterval
span
(in NegInfIntervalinterval
); - Returns an
interval
that covers from the earliest time point of two intervals up to (but not including) the latest time point of two intervals.Parameters:NegInfInterval interval
The interval
to create aspan
together with thisinterval
.Note: There is no overload for
span
which takes a PosInfInterval, because aninterval
going from negative infinity to positive infinity is not possible.Example:
assert(NegInfInterval!Date(Date(2012, 3, 1)).span( NegInfInterval!Date(Date(1999, 7, 6))) == NegInfInterval!Date(Date(2012, 3 , 1))); assert(NegInfInterval!Date(Date(2012, 3, 1)).span( NegInfInterval!Date(Date(2013, 1, 12))) == NegInfInterval!Date(Date(2013, 1 , 12)));
- pure nothrow void
shift
(D)(Dduration
)
if (__traits(compiles, end +duration
)); - Shifts the end of this interval forward or backwards in time by the given
duration
(a positiveduration
shifts the interval forward; a negativeduration
shifts it backward). Effectively, it does end +=duration
.Parameters:D duration
The duration
toshift
the interval by.Example:
auto interval1 = NegInfInterval!Date(Date(2012, 4, 5)); auto interval2 = NegInfInterval!Date(Date(2012, 4, 5)); interval1.shift(dur!"days"(50)); assert(interval1 == NegInfInterval!Date(Date(2012, 5, 25))); interval2.shift(dur!"days"(-50)); assert(interval2 == NegInfInterval!Date( Date(2012, 2, 15)));
- void
shift
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (isIntegral!T); - Shifts the end of this interval forward or backwards in time by the given number of
years
and/ormonths
(a positive number ofyears
andmonths
shifts the interval forward; a negative number shifts it backward). It adds theyears
the givenyears
andmonths
to end. It effectively calls add!"years
"() and then add!"months
"() on end with the given number ofyears
andmonths
.Parameters:T years
The number of years
toshift
the interval by.T months
The number of months
toshift
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on end, causing its month to increment. Throws:DateTimeException if empty istrue
or if the resulting interval would be invalid.Example:
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1)); auto interval2 = NegInfInterval!Date(Date(2012, 3, 1)); interval1.shift(2); assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1))); interval2.shift(-2); assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
- pure nothrow void
expand
(D)(Dduration
)
if (__traits(compiles, end +duration
)); - Expands the interval forwards in time. Effectively, it does end +=
duration
.Parameters:D duration
The duration
toexpand
the interval by.Example:
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1)); auto interval2 = NegInfInterval!Date(Date(2012, 3, 1)); interval1.expand(dur!"days"(2)); assert(interval1 == NegInfInterval!Date(Date(2012, 3, 3))); interval2.expand(dur!"days"(-2)); assert(interval2 == NegInfInterval!Date(Date(2012, 2, 28)));
- void
expand
(T)(Tyears
, Tmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow)
if (isIntegral!T); - Expands the interval forwards and/or backwards in time. Effectively, it adds the given number of
months
/years
to end.Parameters:T years
The number of years
toexpand
the interval by.T months
The number of months
toexpand
the interval by.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on end, causing their month to increment. Throws:DateTimeException if empty istrue
or if the resulting interval would be invalid.Example:
auto interval1 = NegInfInterval!Date(Date(2012, 3, 1)); auto interval2 = NegInfInterval!Date(Date(2012, 3, 1)); interval1.expand(2); assert(interval1 == NegInfInterval!Date(Date(2014, 3, 1))); interval2.expand(-2); assert(interval2 == NegInfInterval!Date(Date(2010, 3, 1)));
- const NegInfIntervalRange!TP
bwdRange
(TP delegate(in TP)func
, PopFirstpopFirst
= No.popFirst
); - Returns a range which iterates backwards over the interval, starting at end, using
func
to generate each successive time point.The range's front is the interval's end.func
is used to generate the next front when popFront is called. IfpopFirst
is Yes.popFirst
, then popFront is called before the range is returned (so that front is a time point whichfunc
would generate). Iffunc
ever generates a time point greater than or equal to the current front of the range, then a DateTimeException will be thrown. There are helper functions in this module which generate common delegates to pass tobwdRange
. Their documentation starts with "Range-generating function," to make them easily searchable.Parameters:TP delegate(in TP) func
The function used to generate the time points of the range over the interval. PopFirst popFirst
Whether popFront should be called on the range before returning it. Throws:DateTimeException if this interval is empty.Warning:
Iffunc
must be logically pure. Ideally,func
would be a function pointer to a pure function, but forcingfunc
to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange,func
must be a delegate.func
retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. To avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. Iffunc
is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant for custom delegates.Example:
auto interval = NegInfInterval!Date(Date(2010, 9, 9)); auto func = delegate (in Date date) //For iterating over even-numbered days. { if ((date.day & 1) == 0) return date - dur!"days"(2); return date - dur!"days"(1); }; auto range = interval.bwdRange(func); assert(range.front == Date(2010, 9, 9)); //An odd day. Using Yes.popFirst would have made this Date(2010, 9, 8). range.popFront(); assert(range.front == Date(2010, 9, 8)); range.popFront(); assert(range.front == Date(2010, 9, 6)); range.popFront(); assert(range.front == Date(2010, 9, 4)); range.popFront(); assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(!range.empty);
- const nothrow string
toString
(); - Converts this interval to a string.
- nothrow TP delegate(in TP)
everyDayOfWeek
(TP, Direction dir = Direction.fwd)(DayOfWeekdayOfWeek
)
if (isTimePoint!TP && (dir == Direction.fwd || dir == Direction.bwd) && __traits(hasMember, TP, "dayOfWeek
") && !__traits(isStaticFunction, TP.dayOfWeek
) && is(typeof(TP.dayOfWeek
) == DayOfWeek)); - Range-generating function.Returns a delegate which returns the next time point with the given DayOfWeek in a range. Using this delegate allows iteration over successive time points which are all the same day of the week. e.g. passing DayOfWeek.mon to
everyDayOfWeek
would result in a delegate which could be used to iterate over all of the Mondays in a range.Parameters:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. DayOfWeek dayOfWeek
The week that each time point in the range will be. - TP delegate(in TP)
everyMonth
(TP, Direction dir = Direction.fwd)(intmonth
)
if (isTimePoint!TP && (dir == Direction.fwd || dir == Direction.bwd) && __traits(hasMember, TP, "month
") && !__traits(isStaticFunction, TP.month
) && is(typeof(TP.month
) == Month)); - Range-generating function.Returns a delegate which returns the next time point with the given
month
which would be reached by adding months to the given time point. So, using this delegate allows iteration over successive time points which are in the samemonth
but different years. For example, iterate over each successive December 25th in an interval by starting with a date which had the 25th as its day and passed Month.dec toeveryMonth
to create the delegate. Since it wouldn't really make sense to be iterating over a specificmonth
and end up with some of the time points in the succeedingmonth
or two years after the previous time point, No.allowDayOverflow is always used when calculating the next time point.Parameters:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. int month
The month
that each time point in the range will be in. - nothrow TP delegate(in TP)
everyDuration
(TP, Direction dir = Direction.fwd, D)(Dduration
)
if (isTimePoint!TP && __traits(compiles, TP.init +duration
) && (dir == Direction.fwd || dir == Direction.bwd)); - Range-generating function.Returns a delegate which returns the next time point which is the given
duration
later. Using this delegate allows iteration over successive time points which are apart by the givenduration
e.g. passing dur!"days"(3) toeveryDuration
would result in a delegate which could be used to iterate over a range of days which are each 3 days apart.Parameters:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. D duration
The duration
which separates each successive time point in the range. - nothrow TP delegate(in TP)
everyDuration
(TP, Direction dir = Direction.fwd, D)(intyears
, intmonths
= 0, AllowDayOverflowallowOverflow
= Yes.allowDayOverflow, Dduration
= dur!"days"(0))
if (isTimePoint!TP && __traits(compiles, TP.init +duration
) && __traits(compiles, TP.init.add!"years
"(years
)) && __traits(compiles, TP.init.add!"months
"(months
)) && (dir == Direction.fwd || dir == Direction.bwd)); - Range-generating function.Returns a delegate which returns the next time point which is the given number of
years
, month, andduration
later. The difference between this version ofeveryDuration
and the version which just takes a core.time.Duration is that this one also takes the number ofyears
andmonths
(along with an AllowDayOverflow to indicate whether addingyears
andmonths
should allow the days to overflow). Note that if iterating forward, add!"years
"() is called on the given time point, then add!"months
"(), and finally theduration
is added to it. However, if iterating backwards, theduration
is added first, then add!"months
"() is called, and finally add!"years
"() is called. That way, going backwards generates close to the same time points that iterating forward does, but since addingyears
andmonths
is not entirely reversible (due to possible day overflow, regardless of whether Yes.allowDayOverflow or No.allowDayOverflow is used), it can't be guaranteed that iterating backwards will give the same time points as iterating forward would have (even assuming that the end of the range is a time point which would be returned by the delegate when iterating forward from begin).Parameters:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. int years
The number of years
to add to the time point passed to the delegate.int months
The number of months
to add to the time point passed to the delegate.AllowDayOverflow allowOverflow
Whether the days should be allowed to overflow on begin and end, causing their month to increment. D duration
The duration
to add to the time point passed to the delegate. - struct
IntervalRange
(TP, Direction dir) if (isTimePoint!TP && dir != Direction.both); - A range over an Interval.
IntervalRange
is only ever constructed by Interval. However, when it is constructed, it is given a function, func, which is used to generate the time points which are iterated over. func takes a time point and returns a time point of the same type. For instance, to iterate over all of the days in the interval Interval!Date, pass a function to Interval's fwdRange where that function took a Date and returned a Date which was one day later. That function would then be used byIntervalRange
's popFront to iterate over the Dates in the interval. If dir == Direction.fwd, then a range iterates forward in time, whereas if dir == Direction.bwd, then it iterates backwards in time. So, if dir == Direction.fwd then front == interval.begin, whereas if dir == Direction.bwd then front == interval.end. func must generate a time point going in the proper direction of iteration, or a DateTimeException will be thrown. So, to iterate forward in time, the time point that func generates must be later in time than the one passed to it. If it's either identical or earlier in time, then a DateTimeException will be thrown. To iterate backwards, then the generated time point must be before the time point which was passed in. If the generated time point is ever passed the edge of the range in the proper direction, then the edge of that range will be used instead. So, if iterating forward, and the generated time point is past the interval's end, then front becomes end. If iterating backwards, and the generated time point is before begin, then front becomes begin. In either case, the range would then be empty. Also note that while normally the begin of an interval is included in it and its end is excluded from it, if dir == Direction.bwd, then begin is treated as excluded and end is treated as included. This allows for the same behavior in both directions. This works because none of Interval's functions which care about whether begin or end is included or excluded are ever called byIntervalRange
. interval returns a normal interval, regardless of whether dir == Direction.fwd or if dir == Direction.bwd, so any Interval functions which are called on it which care about whether begin or end are included or excluded will treat begin as included and end as excluded.- pure nothrow ref IntervalRange
opAssign
(ref IntervalRangerhs
);
pure nothrow ref IntervalRangeopAssign
(IntervalRangerhs
); - Parameters:
IntervalRange rhs
The IntervalRange to assign to this one. - const pure nothrow @property bool
empty
(); - Whether this IntervalRange is
empty
. - const pure @property TP
front
(); - The first time point in the range.Throws:DateTimeException if the range is empty.
- void
popFront
(); - Pops front from the range, using func to generate the next time point in the range. If the generated time point is beyond the edge of the range, then front is set to that edge, and the range is then empty. So, if iterating forwards, and the generated time point is greater than the interval's end, then front is set to end. If iterating backwards, and the generated time point is less than the interval's begin, then front is set to begin.Throws:DateTimeException if the range is empty or if the generated time point is in the wrong direction (i.e. if iterating forward and the generated time point is before front, or if iterating backwards and the generated time point is after front).
- pure nothrow @property IntervalRange
save
(); - Returns a copy of this.
- const pure nothrow @property Interval!TP
interval
(); - The
interval
that this IntervalRange currently covers. - pure nothrow @property TP delegate(in TP)
func
(); - The function used to generate the next time point in the range.
- const pure nothrow @property Direction
direction
(); - The Direction that this range iterates in.
- struct
PosInfIntervalRange
(TP) if (isTimePoint!TP); - A range over a PosInfInterval. It is an infinite range.
PosInfIntervalRange
is only ever constructed by PosInfInterval. However, when it is constructed, it is given a function, func, which is used to generate the time points which are iterated over. func takes a time point and returns a time point of the same type. For instance, to iterate over all of the days in the interval PosInfInterval!Date, pass a function to PosInfInterval's fwdRange where that function took a Date and returned a Date which was one day later. That function would then be used byPosInfIntervalRange
's popFront to iterate over the Dates in the interval - though obviously, since the range is infinite, use a function such as std.range.take with it rather than iterating over all of the dates. As the interval goes to positive infinity, the range is always iterated over forwards, never backwards. func must generate a time point going in the proper direction of iteration, or a DateTimeException will be thrown. So, the time points that func generates must be later in time than the one passed to it. If it's either identical or earlier in time, then a DateTimeException will be thrown.- pure nothrow ref PosInfIntervalRange
opAssign
(ref PosInfIntervalRangerhs
);
pure nothrow ref PosInfIntervalRangeopAssign
(PosInfIntervalRangerhs
); - Parameters:
PosInfIntervalRange rhs
The PosInfIntervalRange to assign to this one. - enum bool
empty
; - This is an infinite range, so it is never
empty
. - const pure nothrow @property TP
front
(); - The first time point in the range.
- void
popFront
(); - Pops front from the range, using func to generate the next time point in the range.Throws:DateTimeException if the generated time point is less than front.
- pure nothrow @property PosInfIntervalRange
save
(); - Returns a copy of this.
- const pure nothrow @property PosInfInterval!TP
interval
(); - The
interval
that this range currently covers. - pure nothrow @property TP delegate(in TP)
func
(); - The function used to generate the next time point in the range.
- struct
NegInfIntervalRange
(TP) if (isTimePoint!TP); - A range over a NegInfInterval. It is an infinite range.
NegInfIntervalRange
is only ever constructed by NegInfInterval. However, when it is constructed, it is given a function, func, which is used to generate the time points which are iterated over. func takes a time point and returns a time point of the same type. For instance, to iterate over all of the days in the interval NegInfInterval!Date, pass a function to NegInfInterval's bwdRange where that function took a Date and returned a Date which was one day earlier. That function would then be used byNegInfIntervalRange
's popFront to iterate over the Dates in the interval - though obviously, since the range is infinite, use a function such as std.range.take with it rather than iterating over all of the dates. As the interval goes to negative infinity, the range is always iterated over backwards, never forwards. func must generate a time point going in the proper direction of iteration, or a DateTimeException will be thrown. So, the time points that func generates must be earlier in time than the one passed to it. If it's either identical or later in time, then a DateTimeException will be thrown. Also note that while normally the end of an interval is excluded from it,NegInfIntervalRange
treats it as if it were included. This allows for the same behavior as with PosInfIntervalRange. This works because none of NegInfInterval's functions which care about whether end is included or excluded are ever called byNegInfIntervalRange
. interval returns a normal interval, so any NegInfInterval functions which are called on it which care about whether end is included or excluded will treat end as excluded.- pure nothrow ref NegInfIntervalRange
opAssign
(ref NegInfIntervalRangerhs
);
pure nothrow ref NegInfIntervalRangeopAssign
(NegInfIntervalRangerhs
); - Parameters:
NegInfIntervalRange rhs
The NegInfIntervalRange to assign to this one. - enum bool
empty
; - This is an infinite range, so it is never
empty
. - const pure nothrow @property TP
front
(); - The first time point in the range.
- void
popFront
(); - Pops front from the range, using func to generate the next time point in the range.Throws:DateTimeException if the generated time point is greater than front.
- pure nothrow @property NegInfIntervalRange
save
(); - Returns a copy of this.
- const pure nothrow @property NegInfInterval!TP
interval
(); - The
interval
that this range currently covers. - pure nothrow @property TP delegate(in TP)
func
(); - The function used to generate the next time point in the range.
- abstract class
TimeZone
; -
- const nothrow @property @safe string
name
(); - The
name
of the time zone per the TZ Database. This is thename
used to get a TimeZone byname
with TimeZone.getTimeZone. - const nothrow @property @safe string
stdName
(); - Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is not in effect (e.g. PST). It is not necessarily unique.However, on Windows, it may be the unabbreviated name (e.g. Pacific Standard Time). Regardless, it is not the same as name.
- const nothrow @property @safe string
dstName
(); - Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.However, on Windows, it may be the unabbreviated name (e.g. Pacific Daylight Time). Regardless, it is not the same as name.
- abstract const nothrow @property @safe bool
hasDST
(); - Whether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return
true
forhasDST
because the time zone did at some point have DST. - abstract const nothrow @safe bool
dstInEffect
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is effect in this time zone at the given point in time.Parameters:
long stdTime
The UTC time that needs to be checked for DST in this time zone. - abstract const nothrow @safe long
utcToTZ
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. - abstract const nothrow @safe long
tzToUTC
(longadjTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).Parameters:
long adjTime
The time in this time zone that needs to be adjusted to UTC time. - const nothrow @safe Duration
utcOffsetAt
(longstdTime
); - Returns what the offset from UTC is at the given std time. It includes the DST offset in effect at that time (if any).Parameters:
long stdTime
The UTC time for which to get the offset from UTC for this time zone. - deprecated static @safe immutable(TimeZone)
getTimeZone
(stringname
); - Deprecated. Use either PosixTimeZone.
getTimeZone
or WindowsTimeZone.getTimeZone
. (parseTZConversions can be used to convert time zone names if necessary). Microsoft changes their time zones too often for us to compile the conversions into Phobos and have them be properly up-to-date. TimeZone.getTimeZone
will be removed in July 2017.Returns a TimeZone with the givename
per the TZ Database. This returns a PosixTimeZone on Posix systems and a WindowsTimeZone on Windows systems. For PosixTimeZone on Windows, call PosixTimeZone.getTimeZone
directly and give it the location of the TZ Database time zone files on disk. On Windows, the given TZ Databasename
is converted to the corresponding time zonename
on Windows prior to calling WindowsTimeZone.getTimeZone
. This function allows for the same time zone names on both Windows and Posix systems.See Also:Parameters:string name
The TZ Database name
of the desired time zoneThrows:DateTimeException if the given time zone could not be found.Examples:auto tz = TimeZone.getTimeZone("America/Los_Angeles");
- deprecated static @safe string[]
getInstalledTZNames
(stringsubName
= ""); - Deprecated. Use either PosixTimeZone.
getInstalledTZNames
or WindowsTimeZone.getInstalledTZNames
. (parseTZConversions can be used to convert time zone names if necessary). Microsoft changes their time zones too often for us to compile the conversions into Phobos and have them be properly up-to-date. TimeZone.getInstalledTZNames
will be removed in July 2017.Returns a list of the names of the time zones installed on the system. Providing a sub-name narrows down the list of time zones (which can number in the thousands). For example, passing in "America" as the sub-name returns only the time zones which begin with "America". On Windows, this function will convert the Windows time zone names to the corresponding TZ Database names with windowsTZNameToTZDatabaseName. To get the actual Windows time zone names, use WindowsTimeZone.getInstalledTZNames
directly.Parameters:string subName
The first part of the time zones desired. Throws:FileException on Posix systems if it fails to read from disk. DateTimeException on Windows systems if it fails to read the registry.
- class
LocalTime
: std.datetime.TimeZone; - A TimeZone which represents the current local time zone on the system running your program.This uses the underlying C calls to adjust the time rather than using specific D code based off of system settings to calculate the time such as PosixTimeZone and WindowsTimeZone do. That also means that it will use whatever the current time zone is on the system, even if the system's time zone changes while the program is running.
- static pure nothrow @trusted immutable(LocalTime)
opCall
(); - const nothrow @property @safe string
name
(); - The
name
of the time zone per the TZ Database. This is thename
used to get a TimeZone byname
with TimeZone.getTimeZone.Note that this always returns the empty string. This is because time zones cannot be uniquely identified by the attributes given by the OS (such as the stdName and dstName), and neither Posix systems nor Windows systems provide an easy way to get the TZ Databasename
of the local time zone. - const nothrow @property @trusted string
stdName
(); - Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is not in effect (e.g. PST). It is not necessarily unique.However, on Windows, it may be the unabbreviated name (e.g. Pacific Standard Time). Regardless, it is not the same as name. This property is overridden because the local time of the system could change while the program is running and we need to determine it dynamically rather than it being fixed like it would be with most time zones.
- const nothrow @property @trusted string
dstName
(); - Typically, the abbreviation (generally 3 or 4 letters) for the time zone when DST is in effect (e.g. PDT). It is not necessarily unique.However, on Windows, it may be the unabbreviated name (e.g. Pacific Daylight Time). Regardless, it is not the same as name. This property is overridden because the local time of the system could change while the program is running and we need to determine it dynamically rather than it being fixed like it would be with most time zones.
- const nothrow @property @trusted bool
hasDST
(); - Whether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return
true
forhasDST
because the time zone did at some point have DST. - const nothrow @trusted bool
dstInEffect
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is in effect in this time zone at the given point in time.Parameters:
long stdTime
The UTC time that needs to be checked for DST in this time zone. - const nothrow @trusted long
utcToTZ
(longstdTime
); - Returns hnsecs in the local time zone using the standard C function calls on Posix systems and the standard Windows system calls on Windows systems to adjust the time to the appropriate time zone from std time.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. See Also:TimeZone.utcToTZ
- const nothrow @trusted long
tzToUTC
(longadjTime
); - Returns std time using the standard C function calls on Posix systems and the standard Windows system calls on Windows systems to adjust the time to UTC from the appropriate time zone.See Also:TimeZone.
tzToUTC
Parameters:long adjTime
The time in this time zone that needs to be adjusted to UTC time.
- class
UTC
: std.datetime.TimeZone; - A TimeZone which represents
UTC
.- static pure nothrow @safe immutable(UTC)
opCall
(); - UTC is a singleton class. UTC returns its only instance.
- const nothrow @property @safe bool
hasDST
(); - Always returns
false
. - const nothrow @safe bool
dstInEffect
(longstdTime
); - Always returns
false
. - const nothrow @safe long
utcToTZ
(longstdTime
); - Returns the given hnsecs without changing them at all.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. See Also:TimeZone.utcToTZ
- const nothrow @safe long
tzToUTC
(longadjTime
); - Returns the given hnsecs without changing them at all.See Also:TimeZone.
tzToUTC
Parameters:long adjTime
The time in this time zone that needs to be adjusted to UTC time. - const nothrow @safe Duration
utcOffsetAt
(longstdTime
); - Returns a core.time.Duration of 0.Parameters:
long stdTime
The UTC time for which to get the offset from UTC for this time zone.
- class
SimpleTimeZone
: std.datetime.TimeZone; - Represents a time zone with an offset (in minutes, west is negative) from UTC but no DST.It's primarily used as the time zone in the result of SysTime's fromISOString, fromISOExtString, and fromSimpleString. name and dstName are always the empty string since this time zone has no DST, and while it may be meant to represent a time zone which is in the TZ Database, obviously it's not likely to be following the exact rules of any of the time zones in the TZ Database, so it makes no sense to set it.
- const nothrow @property @safe bool
hasDST
(); - Always returns
false
. - const nothrow @safe bool
dstInEffect
(longstdTime
); - Always returns
false
. - const nothrow @safe long
utcToTZ
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. - const nothrow @safe long
tzToUTC
(longadjTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).Parameters:
long adjTime
The time in this time zone that needs to be adjusted to UTC time. - const nothrow @safe Duration
utcOffsetAt
(longstdTime
); - Returns utcOffset as a core.time.Duration.Parameters:
long stdTime
The UTC time for which to get the offset from UTC for this time zone. - immutable pure @safe this(Duration
utcOffset
, stringstdName
= ""); - Parameters:
Duration utcOffset
This time zone's offset from UTC with west of UTC being negative (it is added to UTC to get the adjusted time). string stdName
The stdName
for this time zone. - const pure nothrow @property @safe Duration
utcOffset
(); - The amount of time the offset from UTC is (negative is west of UTC, positive is east).
- class
PosixTimeZone
: std.datetime.TimeZone; - Represents a time zone from a TZ Database time zone file. Files from the TZ Database are how Posix systems hold their time zone information. Unfortunately, Windows does not use the TZ Database. To use the TZ Database, use
PosixTimeZone
(which reads its information from the TZ Database files on disk) on Windows by providing the TZ Database files and tellingPosixTimeZone
.getTimeZone where the directory holding them is.To get aPosixTimeZone
, either callPosixTimeZone
.getTimeZone (which allows specifying the location the time zone files) or call TimeZone.getTimeZone (which will give aPosixTimeZone
on Posix systems and a WindowsTimeZone on Windows systems).Note: Unless your system's local time zone deals with leap seconds (which is highly unlikely), then the only way to get a time zone which takes leap seconds into account is to use
PosixTimeZone
with a time zone whose name starts with "right/". Those time zone files do include leap seconds, andPosixTimeZone
will take them into account (though posix systems which use a "right/" time zone as their local time zone will not take leap seconds into account even though they're in the file).- const nothrow @property @safe bool
hasDST
(); - Whether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return
true
forhasDST
because the time zone did at some point have DST. - const nothrow @safe bool
dstInEffect
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is in effect in this time zone at the given point in time.Parameters:
long stdTime
The UTC time that needs to be checked for DST in this time zone. - const nothrow @safe long
utcToTZ
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. - const nothrow @safe long
tzToUTC
(longadjTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).Parameters:
long adjTime
The time in this time zone that needs to be adjusted to UTC time. - enum string
defaultTZDatabaseDir
; - The default directory where the TZ Database files are. It's empty for Windows, since Windows doesn't have them.
- static @trusted immutable(PosixTimeZone)
getTimeZone
(stringname
, stringtzDatabaseDir
= defaultTZDatabaseDir); - Returns a TimeZone with the give
name
per the TZ Database. The time zone information is fetched from the TZ Database time zone files in the given directory.Parameters:string name
The TZ Database name
of the desired time zonestring tzDatabaseDir
The directory where the TZ Database files are located. Because these files are not located on Windows systems, provide them and give their location here to use PosixTimeZones. Throws:DateTimeException if the given time zone could not be found or FileException if the TZ Database file could not be opened.Examples:version(Posix) { auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles"); writeln(tz.name); // "America/Los_Angeles" writeln(tz.stdName); // "PST" writeln(tz.dstName); // "PDT" }
- static @trusted string[]
getInstalledTZNames
(stringsubName
= "", stringtzDatabaseDir
= defaultTZDatabaseDir); - Returns a list of the names of the time zones installed on the system.Providing a sub-name narrows down the list of time zones (which can number in the thousands). For example, passing in "America" as the sub-name returns only the time zones which begin with "America".Parameters:
string subName
The first part of the desired time zones. string tzDatabaseDir
The directory where the TZ Database files are located. Throws:FileException if it fails to read from disk.
- class
WindowsTimeZone
: std.datetime.TimeZone; - This class is Windows-Only.Represents a time zone from the Windows registry. Unfortunately, Windows does not use the TZ Database. To use the TZ Database, use PosixTimeZone (which reads its information from the TZ Database files on disk) on Windows by providing the TZ Database files and telling PosixTimeZone.getTimeZone where the directory holding them is. The TZ Database files and Windows' time zone information frequently do not match. Windows has many errors with regards to when DST switches occur (especially for historical dates). Also, the TZ Database files include far more time zones than Windows does. So, for accurate time zone information, use the TZ Database files with PosixTimeZone rather than
WindowsTimeZone
. However, becauseWindowsTimeZone
uses Windows system calls to deal with the time, it's far more likely to match the behavior of other Windows programs. Be aware of the differences when selecting a method.WindowsTimeZone
does not exist on Posix systems. To get aWindowsTimeZone
, either callWindowsTimeZone
.getTimeZone or call TimeZone.getTimeZone (which will give a PosixTimeZone on Posix systems and aWindowsTimeZone
on Windows systems).See Also:- const nothrow @property @safe bool
hasDST
(); - Whether this time zone has Daylight Savings Time at any point in time. Note that for some time zone types it may not have DST for current dates but will still return
true
forhasDST
because the time zone did at some point have DST. - const nothrow @safe bool
dstInEffect
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and returns whether DST is in effect in this time zone at the given point in time.Parameters:
long stdTime
The UTC time that needs to be checked for DST in this time zone. - const nothrow @safe long
utcToTZ
(longstdTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in UTC time (i.e. std time) and converts it to this time zone's time.Parameters:
long stdTime
The UTC time that needs to be adjusted to this time zone's time. - const nothrow @safe long
tzToUTC
(longadjTime
); - Takes the number of hnsecs (100 ns) since midnight, January 1st, 1 A.D. in this time zone's time and converts it to UTC (i.e. std time).Parameters:
long adjTime
The time in this time zone that needs to be adjusted to UTC time. - static @safe immutable(WindowsTimeZone)
getTimeZone
(stringname
); - Returns a TimeZone with the given
name
per the Windows time zone names. The time zone information is fetched from the Windows registry.Parameters:string name
The TZ Database name
of the desired time zone.Throws:DateTimeException if the given time zone could not be found.Example:
auto tz = WindowsTimeZone.getTimeZone("Pacific Standard Time");
- static @safe string[]
getInstalledTZNames
(); - Returns a list of the names of the time zones installed on the system. The list returned by WindowsTimeZone contains the Windows TZ names, not the TZ Database names. However, TimeZone.getinstalledTZNames will return the TZ Database names which are equivalent to the Windows TZ names.
- nothrow @safe void
setTZEnvVar
(stringtzDatabaseName
); - This function is Posix-Only.Sets the local time zone on Posix systems with the TZ Database name by setting the TZ environment variable. Unfortunately, there is no way to do it on Windows using the TZ Database name, so this function only exists on Posix systems.
- nothrow @safe void
clearTZEnvVar
(); - This function is Posix-Only.Clears the TZ environment variable.
- struct
TZConversions
;
pure @safe TZConversionsparseTZConversions
(stringwindowsZonesXMLText
); - Provides the conversions between the IANA time zone database time zone names (which POSIX systems use) and the time zone names that Windows uses.Windows uses a different set of time zone names than the IANA time zone database does, and how they correspond to one another changes over time (particularly when Microsoft updates Windows). windowsZones.xml provides the current conversions (which may or may not match up with what's on a particular Windows box depending on how up-to-date it is), and
parseTZConversions
reads in those conversions from windowsZones.xml so that a D program can use those conversions. However, it should be noted that the time zone information on Windows is frequently less accurate than that in the IANA time zone database, and if someone really wants accurate time zone information, they should use the IANA time zone database files with PosixTimeZone on Windows rather than WindowsTimeZone, whereas WindowsTimeZone makes more sense when trying to match what Windows will think the time is in a specific time zone. Also, the IANA time zone database has a lot more time zones than Windows does.Parameters:Throws:Exception if there is an error while parsing the given XML.// Parse the conversions from a local file. auto text = std.file.readText("path/to/windowsZones.xml"); auto conversions = parseTZConversions(text); // Alternatively, grab the XML file from the web at runtime // and parse it so that it's guaranteed to be up-to-date, though // that has the downside that the code needs to worry about the // site being down or unicode.org changing the URL. auto url = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml"; auto conversions2 = parseTZConversions(std.net.curl.get(url));
- string[][string]
toWindows
; - The key is the Windows time zone name, and the value is a list of IANA TZ database names which are close (currently only ever one, but it allows for multiple in case it's ever necessary).
- string[][string]
fromWindows
; - The key is the IANA time zone database name, and the value is a list of Windows time zone names which are close (usually only one, but it could be multiple).
- deprecated pure nothrow @nogc @safe string
tzDatabaseNameToWindowsTZName
(stringtzName
); - Deprecated. Use parseTZConversions instead. Microsoft changes their time zones too often for us to compile the conversions into Phobos and have them be properly up-to-date.
tzDatabaseNameToWindowsTZName
will be removed in July 2017.Converts the given TZ Database name to the corresponding Windows time zone name. Note that in a few cases, a TZ Dabatase name corresponds to two different Windows time zone names. So, while in most cases converting from one to the other and back again will result in the same time zone name started with, in a few case, it'll get a different name. Also, there are far more TZ Database names than Windows time zones, so some of the more exotic TZ Database names don't have corresponding Windows time zone names. Returnsnull
if the given time zone name cannot be converted.Parameters:string tzName
The TZ Database name to convert. - deprecated pure nothrow @nogc @safe string
windowsTZNameToTZDatabaseName
(stringtzName
); - Deprecated. Use parseTZConversions instead. Microsoft changes their time zones too often for us to compile the conversions into Phobos and have them be properly up-to-date.
windowsTZNameToTZDatabaseName
will be removed in July 2017.Converts the given Windows time zone name to a corresponding TZ Database name. Returnsnull
if the given time zone name cannot be converted.Parameters:string tzName
The TZ Database name to convert. - struct
StopWatch
; StopWatch
measures time as precisely as possible.This class uses a high-performance counter. On Windows systems, it uses QueryPerformanceCounter, and on Posix systems, it uses clock_gettime if available, and gettimeofday otherwise. But the precision ofStopWatch
differs from system to system. It is impossible to for it to be the same from system to system since the precision of the system clock varies from system to system, and other system-dependent and situation-dependent stuff (such as the overhead of a context switch between threads) can also affectStopWatch
's accuracy.Examples:void writeln(S...)(S args){} static void bar() {} StopWatch sw; enum n = 100; TickDuration[n] times; TickDuration last = TickDuration.from!"seconds"(0); foreach (i; 0 .. n) { sw.start(); //start/resume mesuring. foreach (unused; 0 .. 1_000_000) bar(); sw.stop(); //stop/pause measuring. //Return value of peek() after having stopped are the always same. writeln((i + 1) * 1_000_000, " times done, lap time: ", sw.peek().msecs, "[ms]"); times[i] = sw.peek() - last; last = sw.peek(); } real sum = 0; // To get the number of seconds, // use properties of TickDuration. // (seconds, msecs, usecs, hnsecs) foreach (t; times) sum += t.hnsecs; writeln("Average time: ", sum/n, " hnsecs");
- @nogc @safe this(AutoStart
autostart
); - Auto start with constructor.
- const pure nothrow @nogc @safe bool
opEquals
(const StopWatchrhs
);
const pure nothrow @nogc @safe boolopEquals
(ref const StopWatchrhs
); - @nogc @safe void
reset
(); - Resets the stop watch.Examples:
StopWatch sw; sw.start(); sw.stop(); sw.reset(); writeln(sw.peek().to!("seconds", real)()); // 0
- @nogc @safe void
start
(); - Starts the stop watch.
- @nogc @safe void
stop
(); - Stops the
stop
watch. - const @nogc @safe TickDuration
peek
(); - Peek at the amount of time which has passed since the stop watch was started.
- @nogc @safe void
setMeasured
(TickDurationd
); - Set the amount of time which has been measured since the stop watch was started.
- const pure nothrow @nogc @property @safe bool
running
(); - Confirm whether this stopwatch is measuring time.
- TickDuration[fun.length]
benchmark
(fun...)(uintn
); - Benchmarks code for speed assessment and comparison.Parameters:
fun aliases of callable objects (e.g. function names). Each should take no arguments. uint n
The number of times each function is to be executed. Returns:The amount of time (as a core.time.TickDuration) that it took to call each functionn
times. The first value is the length of time that it took to call fun[0]n
times. The second value is the length of time it took to call fun[1]n
times. Etc. Note that casting the TickDurations to core.time.Durations will make the results easier to deal with (and it may change in the future thatbenchmark
will return an array of Durations rather than TickDurations).See Also:Examples:import std.conv : to; int a; void f0() {} void f1() {auto b = a;} void f2() {auto b = to!string(a);} auto r = benchmark!(f0, f1, f2)(10_000); auto f0Result = to!Duration(r[0]); // time f0 took to run 10,000 times auto f1Result = to!Duration(r[1]); // time f1 took to run 10,000 times auto f2Result = to!Duration(r[2]); // time f2 took to run 10,000 times
- struct
ComparingBenchmarkResult
; - Return value of benchmark with two functions comparing.
- const pure nothrow @property @safe real
point
(); - Evaluation valueThis returns the evaluation value of performance as the ratio of baseFunc's time over targetFunc's time. If performance is high, this returns a high value.
- const pure nothrow @property @safe TickDuration
baseTime
(); - The time required of the base function
- const pure nothrow @property @safe TickDuration
targetTime
(); - The time required of the target function
- ComparingBenchmarkResult
comparingBenchmark
(alias baseFunc, alias targetFunc, int times = 4095)(); - Benchmark with two functions comparing.Parameters:
baseFunc The function to become the base of the speed. targetFunc The function that wants to measure speed. times The number of times each function is to be executed. Examples:void f1x() {} void f2x() {} @safe void f1o() {} @safe void f2o() {} auto b1 = comparingBenchmark!(f1o, f2o, 1)(); // OK //writeln(b1.point);
- enum auto
isTimePoint
(T); - Whether the given type defines all of the necessary functions for it to function as a time point.1. T must define a static property named min which is the smallest value of T as . 2. T must define a static property named max which is the largest value of T as . 3. T must define an opBinary for addition and subtraction that accepts core.time.Duration and returns Unqual!T. 4. T must define an opOpAssign for addition and subtraction that accepts core.time.Duration and returns ref Unqual!T. 5. T must define a opBinary for subtraction which accepts T and returns returns core.time.Duration.Examples:
static assert(isTimePoint!Date); static assert(isTimePoint!DateTime); static assert(isTimePoint!SysTime); static assert(isTimePoint!TimeOfDay); static assert(!isTimePoint!int); static assert(!isTimePoint!Duration); static assert(!isTimePoint!(Interval!SysTime));
- static pure nothrow @safe bool
yearIsLeapYear
(intyear
); - Whether the given Gregorian Year is a leap
year
.Parameters:int year
The year
to to be tested. - pure nothrow @safe long
unixTimeToStdTime
(longunixTime
); - Converts from unix time (which uses midnight, January 1st, 1970 UTC as its epoch and seconds as its units) to "std time" (which uses midnight, January 1st, 1 A.D. UTC and hnsecs as its units).The C standard does not specify the representation of time_t, so it is implementation defined. On POSIX systems, unix time is equivalent to time_t, but that's not necessarily
true
on other systems (e.g. it is nottrue
for the Digital Mars C runtime). So, be careful when using unix time with C functions on non-POSIX systems. "std time"'s epoch is based on the Proleptic Gregorian Calendar per ISO 8601 and is what SysTime uses internally. However, holding the time as an integer in hnescs since that epoch technically isn't actually part of the standard, much as it's based on it, so the name "std time" isn't particularly good, but there isn't an official name for it. C# uses "ticks" for the same thing, but they aren't actually clock ticks, and the term "ticks" is used for actual clock ticks for core.time.MonoTime, so it didn't make sense to use the term ticks here. So, for better or worse, std.datetime uses the term "std time" for this.Parameters:long unixTime
The unix time to convert. See Also:SysTime.fromUnixTimeExamples:// Midnight, January 1st, 1970 writeln(unixTimeToStdTime(0)); // 621_355_968_000_000_000L assert(SysTime(unixTimeToStdTime(0)) == SysTime(DateTime(1970, 1, 1), UTC())); writeln(unixTimeToStdTime(int.max)); // 642_830_804_470_000_000L assert(SysTime(unixTimeToStdTime(int.max)) == SysTime(DateTime(2038, 1, 19, 3, 14, 07), UTC())); writeln(unixTimeToStdTime(-127_127)); // 621_354_696_730_000_000L assert(SysTime(unixTimeToStdTime(-127_127)) == SysTime(DateTime(1969, 12, 30, 12, 41, 13), UTC()));
- pure nothrow @safe T
stdTimeToUnixTime
(T = time_t)(longstdTime
)
if (is(T == int) || is(T == long)); - Converts std time (which uses midnight, January 1st, 1 A.D. UTC as its epoch and hnsecs as its units) to unix time (which uses midnight, January 1st, 1970 UTC as its epoch and seconds as its units).The C standard does not specify the representation of time_t, so it is implementation defined. On POSIX systems, unix time is equivalent to time_t, but that's not necessarily
true
on other systems (e.g. it is nottrue
for the Digital Mars C runtime). So, be careful when using unix time with C functions on non-POSIX systems. "std time"'s epoch is based on the Proleptic Gregorian Calendar per ISO 8601 and is what SysTime uses internally. However, holding the time as an integer in hnescs since that epoch technically isn't actually part of the standard, much as it's based on it, so the name "std time" isn't particularly good, but there isn't an official name for it. C# uses "ticks" for the same thing, but they aren't actually clock ticks, and the term "ticks" is used for actual clock ticks for core.time.MonoTime, so it didn't make sense to use the term ticks here. So, for better or worse, std.datetime uses the term "std time" for this. By default, the return type is time_t (which is normally an alias for int on 32-bit systems and long on 64-bit systems), but if a different size is required than either int or long can be passed as a template argument to get the desired size. If the return type is int, and the result can't fit in an int, then the closest value that can be held in 32 bits will be used (so int.max if it goes over and int.min if it goes under). However, no attempt is made to deal with integer overflow if the return type is long.Parameters:T The return type (int or long). It defaults to time_t, which is normally 32 bits on a 32-bit system and 64 bits on a 64-bit system. long stdTime
The std time to convert. Returns:A signed integer representing the unix time which is equivalent to the given std time.See Also:SysTime.toUnixTimeExamples:// Midnight, January 1st, 1970 UTC writeln(stdTimeToUnixTime(621_355_968_000_000_000L)); // 0 // 2038-01-19 03:14:07 UTC writeln(stdTimeToUnixTime(642_830_804_470_000_000L)); // int.max
- @safe SysTime
SYSTEMTIMEToSysTime
(const SYSTEMTIME*st
, immutable TimeZonetz
= LocalTime()); - This function is Windows-Only.Converts a SYSTEMTIME struct to a SysTime.Parameters:
SYSTEMTIME* st
The SYSTEMTIME struct to convert. TimeZone tz
The time zone that the time in the SYSTEMTIME struct is assumed to be (if the SYSTEMTIME was supplied by a Windows system call, the SYSTEMTIME will either be in local time or UTC, depending on the call). Throws:DateTimeException if the given SYSTEMTIME will not fit in a SysTime, which is highly unlikely to happen given that SysTime.max is in 29,228 A.D. and the maximum SYSTEMTIME is in 30,827 A.D. - @safe SYSTEMTIME
SysTimeToSYSTEMTIME
(in SysTimesysTime
); - This function is Windows-Only.Converts a SysTime to a SYSTEMTIME struct. The SYSTEMTIME which is returned will be set using the given SysTime's time zone, so to get the SYSTEMTIME in UTC, set the SysTime's time zone to UTC.Parameters:
SysTime sysTime
The SysTime to convert. Throws:DateTimeException if the given SysTime will not fit in a SYSTEMTIME. This will only happen if the SysTime's date is prior to 1601 A.D. - @safe long
FILETIMEToStdTime
(scope const FILETIME*ft
); - This function is Windows-Only.Converts a FILETIME struct to the number of hnsecs since midnight, January 1st, 1 A.D.Parameters:
FILETIME* ft
The FILETIME struct to convert. Throws:DateTimeException if the given FILETIME cannot be represented as the return value. - @safe SysTime
FILETIMEToSysTime
(scope const FILETIME*ft
, immutable TimeZonetz
= LocalTime()); - This function is Windows-Only.Converts a FILETIME struct to a SysTime.Parameters:
FILETIME* ft
The FILETIME struct to convert. TimeZone tz
The time zone that the SysTime will be in (FILETIMEs are in UTC). Throws: - @safe FILETIME
stdTimeToFILETIME
(longstdTime
); - This function is Windows-Only.Converts a number of hnsecs since midnight, January 1st, 1 A.D. to a FILETIME struct.Parameters:
long stdTime
The number of hnsecs since midnight, January 1st, 1 A.D. UTC. Throws:DateTimeException if the given value will not fit in a FILETIME. - @safe FILETIME
SysTimeToFILETIME
(SysTimesysTime
); - This function is Windows-Only.Parameters:
SysTime sysTime
The SysTime to convert. Throws: - alias
DosFileTime
= uint; - Type representing the DOS file date/time format.
- @safe SysTime
DosFileTimeToSysTime
(DosFileTimedft
, immutable TimeZonetz
= LocalTime()); - Converts from DOS file date/time to SysTime.Parameters:
DosFileTime dft
The DOS file time to convert. TimeZone tz
The time zone which the DOS file time is assumed to be in. Throws:DateTimeException if the DosFileTime is invalid. - @safe DosFileTime
SysTimeToDosFileTime
(SysTimesysTime
); - Converts from SysTime to DOS file date/time.Parameters:
SysTime sysTime
The SysTime to convert. Throws: - @safe SysTime
parseRFC822DateTime
()(in char[]value
);
@safe SysTimeparseRFC822DateTime
(R)(Rvalue
)
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && (is(Unqual!(ElementType!R) == char) || is(Unqual!(ElementType!R) == ubyte))); - The given array of char or random-access range of char or ubyte is expected to be in the format specified in RFC 5322 section 3.3 with the grammar rule date-time. It is the date-time format commonly used in internet messages such as e-mail and HTTP. The corresponding SysTime will be returned.RFC 822 was the original spec (hence the function's name), whereas RFC 5322 is the current spec. The day of the week is ignored beyond verifying that it's a valid day of the week, as the day of the week can be inferred from the date. It is not checked whether the given day of the week matches the actual day of the week of the given date (though it is technically invalid per the spec if the day of the week doesn't match the actual day of the week of the given date). If the time zone is "-0000" (or considered to be equivalent to "-0000" by section 4.3 of the spec), a SimpleTimeZone with a utc offset of 0 is used rather than UTC, whereas "+0000" uses UTC. Note that because SysTime does not currently support having a second
value
of 60 (as is sometimes done for leap seconds), if the date-timevalue
does have avalue
of 60 for the seconds, it is treated as 59. The one area in which this function violates RFC 5322 is that it accepts "\n" in folding whitespace in the place of "\r\n", because the HTTP spec requires it.Throws:DateTimeException if the given string doesn't follow the grammar for a date-time field or if the resulting SysTime is invalid.Examples:import std.exception : assertThrown; auto tz = new immutable SimpleTimeZone(hours(-8)); assert(parseRFC822DateTime("Sat, 6 Jan 1990 12:14:19 -0800") == SysTime(DateTime(1990, 1, 6, 12, 14, 19), tz)); assert(parseRFC822DateTime("9 Jul 2002 13:11 +0000") == SysTime(DateTime(2002, 7, 9, 13, 11, 0), UTC())); auto badStr = "29 Feb 2001 12:17:16 +0200"; assertThrown!DateTimeException(parseRFC822DateTime(badStr));
- pure nothrow @safe bool
validTimeUnits
(string[]units
...); - Whether all of the given strings are valid
units
of time."nsecs" is not considered a valid unit of time. Nothing in std.datetime can handle precision greater than hnsecs, and the few functions in core.time which deal with "nsecs" deal with it explicitly. - pure @safe int
cmpTimeUnits
(stringlhs
, stringrhs
); - Compares two time unit strings. "years" are the largest units and "hnsecs" are the smallest.Returns:
this < rhs
< 0 this == rhs
0 this > rhs
> 0 Throws:DateTimeException if either of the given strings is not a valid time unit string. - template
CmpTimeUnits
(string lhs, string rhs) if (validTimeUnits(lhs, rhs)) - Compares two time unit strings at compile time. "years" are the largest units and "hnsecs" are the smallest.This template is used instead of cmpTimeUnits because exceptions can't be thrown at compile time and cmpTimeUnits must enforce that the strings it's given are valid time unit strings. This template uses a template constraint instead.Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 - pure nothrow @safe bool
valid
(string units)(intvalue
)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds"); - Returns whether the given
value
isvalid
for the given unit type when in a time point. Naturally, a duration is not held to a particular range, but the values in a time point are (e.g. a month must be in the range of 1 - 12 inclusive).Parameters:units The units of time to validate. int value
The number to validate. Examples:assert(valid!"hours"(12)); assert(!valid!"hours"(32)); assert(valid!"months"(12)); assert(!valid!"months"(13));
- pure nothrow @safe bool
valid
(string units)(intyear
, intmonth
, intday
)
if (units == "days"); - Returns whether the given
day
isvalid
for the givenyear
andmonth
.Parameters:units The units of time to validate. int year
The year
of theday
to validate.int month
The month
of theday
to validate.int day
The day
to validate. - pure @safe void
enforceValid
(string units)(intvalue
, stringfile
= __FILE__, size_tline
= __LINE__)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds"); - Parameters:
units The units of time to validate. int value
The number to validate. string file
The file
that the DateTimeException will list if thrown.size_t line
The line
number that the DateTimeException will list if thrown.Throws: - pure @safe void
enforceValid
(string units)(intyear
, Monthmonth
, intday
, stringfile
= __FILE__, size_tline
= __LINE__)
if (units == "days"); - Parameters:
units The units of time to validate. int year
The year
of theday
to validate.Month month
The month
of theday
to validate.int day
The day
to validate.string file
The file
that the DateTimeException will list if thrown.size_t line
The line
number that the DateTimeException will list if thrown.Throws: - static pure @safe int
monthsToMonth
(intcurrMonth
, intmonth
); - Returns the number of months from the current months of the year to the given
month
of the year. If they are the same, then the result is 0.Parameters:int currMonth
The current month
of the year.int month
The month
of the year to get the number of months to. - static pure nothrow @safe int
daysToDayOfWeek
(DayOfWeekcurrDoW
, DayOfWeekdow
); - Returns the number of days from the current day of the week to the given day of the week. If they are the same, then the result is 0.Parameters:
DayOfWeek currDoW
The current day of the week. DayOfWeek dow
The day of the week to get the number of days to. - @safe auto
measureTime
(alias func)()
if (isSafe!(() { StopWatch sw; unaryFun!func(sw.peek()); } )); - Function for starting to a stop watch time when the function is called and stopping it when its return value goes out of scope and is destroyed.When the value that is returned by this function is destroyed, func will run. func is a unary function that takes a core.time.TickDuration.
Example:
{ auto mt = measureTime!((TickDuration a) { /+ do something when the scope is exited +/ }); // do something that needs to be timed }
which is functionally equivalent to{ auto sw = StopWatch(Yes.autoStart); scope(exit) { TickDuration a = sw.peek(); /+ do something when the scope is exited +/ } // do something that needs to be timed }
See Also: