Module containing Date/Time functionality.
This module provides:
auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtString(); auto restoredTime = SysTime.fromISOExtString(timeString);
Represents the 12 months of the Gregorian year (January is 1).
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.
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.
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. Using PopFirst.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). If PopFirst.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).
Used by StopWatch to indicate whether it should start immediately upon construction.
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"
Exception type used by std.datetime. It's an alias to TimeException, which is what core.time uses. Either can be caught without concern about which module it came from.
Effectively a namespace to make it clear that the methods it contains are getting the time from the system clock. It cannot be instantiated.
Returns the current time in the given time zone.
Returns the number of hnsecs since midnight, January 1st, 1 A.D. for the current time.
The current system tick. The number of ticks per second varies from system to system. currSystemTick uses a monotonic clock, so it's intended for precision timing by comparing relative time values, not for getting the current system time.
The current number of system ticks since the application started. The number of ticks per second varies from system to system. This uses a monotonic clock.
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 of SysTime (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, use SysTime.
Clock.currTime will return the current time as a SysTime.
To convert a SysTime to a Date or DateTime, simply cast
it. To convert a Date or DateTime to a
SysTime, use SysTime'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 a SysTime 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 as
SysTimes. 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 in SysTime is kept internally in hnsecs from midnight,
January 1st, 1 A.D. UTC. Conversion error cannot happen when changing
the time zone of a SysTime. 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.
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. |
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. |
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. |
FracSec fracSec | 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. |
Date date | The Date to use to set this SysTime's internal std time. As Date has no concept of time zone, tz is used as its time zone. |
TimeZone tz | The TimeZone to use for this SysTime. If null, LocalTime will be used. The given Date is assumed to be in the given time zone. |
long stdTime | The number of hnsecs since midnight, January 1st, 1 A.D. UTC. |
TimeZone tz | The TimeZone to use for this SysTime. If null, LocalTime will be used. |
SysTime rhs | The SysTime to assign to this one. |
SysTime rhs | The SysTime to assign to this one. |
Checks for equality between this SysTime and the given SysTime.
Note that the time zone is ignored. Only the internal std times (which are in UTC) are compared.
Compares this SysTime with the given SysTime.
Time zone is irrelevant when comparing SysTimes.
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
int year | The year to set this SysTime's year to. |
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).year == 1999); assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).year == 2010); assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).year == -7);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
assert(SysTime(DateTime(0, 1, 1, 12, 30, 33)).yearBC == 1); assert(SysTime(DateTime(-1, 1, 1, 10, 7, 2)).yearBC == 2); assert(SysTime(DateTime(-100, 1, 1, 4, 59, 0)).yearBC == 101);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
int year | The year B.C. to set this SysTime's year to. |
auto st = SysTime(DateTime(2010, 1, 1, 7, 30, 0)); st.yearBC = 1; assert(st == SysTime(DateTime(0, 1, 1, 7, 30, 0))); st.yearBC = 10; assert(st == SysTime(DateTime(-9, 1, 1, 7, 30, 0)));
Month of a Gregorian Year.
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).month == 7); assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).month == 10); assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).month == 4);
Day of a Gregorian Month.
assert(SysTime(DateTime(1999, 7, 6, 9, 7, 5)).day == 6); assert(SysTime(DateTime(2010, 10, 4, 0, 0, 30)).day == 4); assert(SysTime(DateTime(-7, 4, 5, 7, 45, 2)).day == 5);
Hours past midnight.
Minutes past the current hour.
Seconds past the current minute.
Fractional seconds passed the second.
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.
The total hnsecs from midnight, January 1st, 1 A.D. UTC. This is the internal representation of SysTime.
long stdTime | The number of hnsecs since January 1st, 1 A.D. UTC. |
The current time zone of this SysTime. Its internal time is always kept in UTC, so there are no conversion issues between time zones due to DST. Functions which return all or part of the time - such as hours - adjust the time to this SysTime's time zone before returning.
The current time zone of this SysTime. It's internal time is always kept in UTC, so there are no conversion issues between time zones due to DST. Functions which return all or part of the time - such as hours - adjust the time to this SysTime's time zone before returning.
tz | The TimeZone to set this SysTime's time zone to. |
Returns whether DST is in effect for this SysTime.
Returns what the offset from UTC is for this SysTime. It includes the DST offset in effect at that time (if any).
Returns a SysTime with the same std time as this one, but with LocalTime as its time zone.
Returns a SysTime with the same std time as this one, but with UTC as its time zone.
Returns a SysTime with the same std time as this one, but with given time zone as its time zone.
Returns a time_t which represents the same time as this SysTime.
Note that like all conversions in std.datetime, this is a truncating
conversion.
If time_t is 32 bits, rather than 64, and the result can't fit in a
32-bit value, then the closest value that can be held in 32 bits will be
used (so time_t.max if it goes over and time_t.min if it goes
under).
Returns a timeval which represents this SysTime.
Note that like all conversions in std.datetime, this is a truncating
conversion.
If time_t is 32 bits, rather than 64, and the result can't fit in a
32-bit value, then the closest value that can be held in 32 bits will be
used for tv_sec. (so time_t.max if it goes over and
time_t.min if it goes under).
Returns a tm which represents this SysTime.
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).
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. |
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 30, 33)); st1.add!"months"(11); assert(st1 == SysTime(DateTime(2010, 12, 1, 12, 30, 33))); auto st2 = SysTime(DateTime(2010, 1, 1, 12, 30, 33)); st2.add!"months"(-11); assert(st2 == SysTime(DateTime(2009, 2, 1, 12, 30, 33))); auto st3 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st3.add!"years"(1); assert(st3 == SysTime(DateTime(2001, 3, 1, 12, 30, 33))); auto st4 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st4.add!"years"(1, AllowDayOverflow.no); assert(st4 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
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.
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. |
auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33)); st1.roll!"months"(1); assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33))); auto st2 = SysTime(DateTime(2010, 1, 1, 12, 33, 33)); st2.roll!"months"(-1); assert(st2 == SysTime(DateTime(2010, 12, 1, 12, 33, 33))); auto st3 = SysTime(DateTime(1999, 1, 29, 12, 33, 33)); st3.roll!"months"(1); assert(st3 == SysTime(DateTime(1999, 3, 1, 12, 33, 33))); auto st4 = SysTime(DateTime(1999, 1, 29, 12, 33, 33)); st4.roll!"months"(1, AllowDayOverflow.no); assert(st4 == SysTime(DateTime(1999, 2, 28, 12, 33, 33))); auto st5 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st5.roll!"years"(1); assert(st5 == SysTime(DateTime(2001, 3, 1, 12, 30, 33))); auto st6 = SysTime(DateTime(2000, 2, 29, 12, 30, 33)); st6.roll!"years"(1, AllowDayOverflow.no); assert(st6 == SysTime(DateTime(2001, 2, 28, 12, 30, 33)));
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.
units | The units to add. |
long value | The number of units to add to this SysTime. |
auto st1 = SysTime(DateTime(2010, 1, 1, 11, 23, 12)); st1.roll!"days"(1); assert(st1 == SysTime(DateTime(2010, 1, 2, 11, 23, 12))); st1.roll!"days"(365); assert(st1 == SysTime(DateTime(2010, 1, 26, 11, 23, 12))); st1.roll!"days"(-32); assert(st1 == SysTime(DateTime(2010, 1, 25, 11, 23, 12))); auto st2 = SysTime(DateTime(2010, 7, 4, 12, 0, 0)); st2.roll!"hours"(1); assert(st2 == SysTime(DateTime(2010, 7, 4, 13, 0, 0))); auto st3 = SysTime(DateTime(2010, 1, 1, 0, 0, 0)); st3.roll!"seconds"(-1); assert(st3 == SysTime(DateTime(2010, 1, 1, 0, 0, 59))); auto st4 = SysTime(DateTime(2010, 1, 1, 0, 0, 0), FracSec.from!"usecs"(2_400)); st4.roll!"usecs"(-1_200_000); assert(st4 == SysTime(DateTime(2010, 1, 1, 0, 0, 0), FracSec.from!"usecs"(802_400)));
Gives the result of adding or subtracting a duration from this SysTime.
The legal types of arithmetic for SysTime using this operator are
SysTime | + | duration | --> | SysTime |
SysTime | - | duration | --> | SysTime |
D duration | The duration to add to or subtract from this SysTime. |
Gives the result of adding or subtracting a 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 |
D duration | The duration to add to or subtract from this SysTime. |
Gives the difference between two SysTimes.
The legal types of arithmetic for SysTime using this operator are
SysTime | - | SysTime | --> | duration |
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 Duration
that results. Because converting between months and smaller
units requires a specific date (which 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.
SysTime rhs | The SysTime to subtract from this one. |
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);
Whether this SysTime is in a leap year.
Day of the week this SysTime is on.
Day of the year this SysTime is on.
assert(SysTime(DateTime(1999, 1, 1, 12, 22, 7)).dayOfYear == 1); assert(SysTime(DateTime(1999, 12, 31, 7, 2, 59)).dayOfYear == 365); assert(SysTime(DateTime(2000, 12, 31, 21, 20, 0)).dayOfYear == 366);
Day of the year.
int day | The day of the year to set which day of the year this SysTime is on. |
The Xth day of the Gregorian Calendar that this SysTime is on.
assert(SysTime(DateTime(1, 1, 1, 0, 0, 0)).dayOfGregorianCal == 1); assert(SysTime(DateTime(1, 12, 31, 23, 59, 59)).dayOfGregorianCal == 365); assert(SysTime(DateTime(2, 1, 1, 2, 2, 2)).dayOfGregorianCal == 366); assert(SysTime(DateTime(0, 12, 31, 7, 7, 7)).dayOfGregorianCal == 0); assert(SysTime(DateTime(0, 1, 1, 19, 30, 0)).dayOfGregorianCal == -365); assert(SysTime(DateTime(-1, 12, 31, 4, 7, 0)).dayOfGregorianCal == -366); assert(SysTime(DateTime(2000, 1, 1, 9, 30, 20)).dayOfGregorianCal == 730_120); assert(SysTime(DateTime(2010, 12, 31, 15, 45, 50)).dayOfGregorianCal == 734_137);
The Xth day of the Gregorian Calendar that this SysTime is on. Setting this property does not affect the time portion of SysTime.
int days | The day of the Gregorian Calendar to set this SysTime to. |
auto st = SysTime(DateTime(0, 0, 0, 12, 0, 0)); st.dayOfGregorianCal = 1; assert(st == SysTime(DateTime(1, 1, 1, 12, 0, 0))); st.dayOfGregorianCal = 365; assert(st == SysTime(DateTime(1, 12, 31, 12, 0, 0))); st.dayOfGregorianCal = 366; assert(st == SysTime(DateTime(2, 1, 1, 12, 0, 0))); st.dayOfGregorianCal = 0; assert(st == SysTime(DateTime(0, 12, 31, 12, 0, 0))); st.dayOfGregorianCal = -365; assert(st == SysTime(DateTime(-0, 1, 1, 12, 0, 0))); st.dayOfGregorianCal = -366; assert(st == SysTime(DateTime(-1, 12, 31, 12, 0, 0))); st.dayOfGregorianCal = 730_120; assert(st == SysTime(DateTime(2000, 1, 1, 12, 0, 0))); st.dayOfGregorianCal = 734_137; assert(st == SysTime(DateTime(2010, 12, 31, 12, 0, 0)));
The ISO 8601 week of the year that this SysTime is in.
SysTime for the last day in the month that this Date is in. The time portion of endOfMonth is always 23:59:59.9999999.
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonth == SysTime(DateTime(1999, 1, 31, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999))); assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0), FracSec.from!"msecs"(24)).endOfMonth == SysTime(DateTime(1999, 2, 28, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999))); assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27), FracSec.from!"usecs"(5203)).endOfMonth == SysTime(DateTime(2000, 2, 29, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999))); assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9), FracSec.from!"hnsecs"(12345)).endOfMonth == SysTime(DateTime(2000, 6, 30, 23, 59, 59), FracSec.from!"hnsecs"(9_999_999)));
The last day in the month that this SysTime is in.
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).daysInMonth == 31); assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0)).daysInMonth == 28); assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27)).daysInMonth == 29); assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9)).daysInMonth == 30);
Whether the current year is a date in A.D.
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);
The julian day for this SysTime at the given time. For example, prior to noon, 1996-03-31 would be the julian day number 2450_173, so this function returns 2450_173, while from noon onward, the julian day number would be 2450_174, so this function returns 2450_174.
The modified julian day for any time on this date (since, the modified julian day changes at midnight).
Returns a Date equivalent to this SysTime.
Returns a DateTime equivalent to this SysTime.
Returns a TimeOfDay equivalent to this SysTime.
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. +1:00 or -7: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.
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOString() == "20100704T070612"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"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), FracSec.from!"hnsecs"(520_920)).toISOString() == "-00040105T000002.052092");
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. +1:00 or -7: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.
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOExtString() == "2010-07-04T07:06:12"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"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), FracSec.from!"hnsecs"(520_920)).toISOExtString() == "-0004-01-05T00:00:02.052092");
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. +1:00 or -7: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.
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), FracSec.from!"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), FracSec.from!"hnsecs"(520_920)).toSimpleString() == "-0004-Jan-05 00:00:02.052092");
Converts this SysTime to a string.
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 +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
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). |
assert(SysTime.fromISOString("20100704T070612") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOString("19981225T021500.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7))); assert(SysTime.fromISOString("00000105T230959.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20))); assert(SysTime.fromISOString("-00040105T000002") == SysTime(DateTime(-4, 1, 5, 0, 0, 2))); assert(SysTime.fromISOString(" 20100704T070612 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOString("20100704T070612Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC())); assert(SysTime.fromISOString("20100704T070612-8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8)))); assert(SysTime.fromISOString("20100704T070612+8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
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 +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
isoString | 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). |
assert(SysTime.fromISOExtString("2010-07-04T07:06:12") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOExtString("1998-12-25T02:15:00.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7))); assert(SysTime.fromISOExtString("0000-01-05T23:09:59.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20))); assert(SysTime.fromISOExtString("-0004-01-05T00:00:02") == SysTime(DateTime(-4, 1, 5, 0, 0, 2))); assert(SysTime.fromISOExtString(" 2010-07-04T07:06:12 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOExtString("2010-07-04T07:06:12Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC())); assert(SysTime.fromISOExtString("2010-07-04T07:06:12-8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8)))); assert(SysTime.fromISOExtString("2010-07-04T07:06:12+8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
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 +H, -H, +HH, -HH, +H:MM, -H:MM, +HH:MM, and -HH:MM.
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). |
assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromSimpleString("1998-Dec-25 02:15:00.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7))); assert(SysTime.fromSimpleString("0000-Jan-05 23:09:59.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20))); assert(SysTime.fromSimpleString("-0004-Jan-05 00:00:02") == SysTime(DateTime(-4, 1, 5, 0, 0, 2))); assert(SysTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC())); assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12-8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(-8)))); assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(dur!"hours"(8))));
Returns the SysTime farthest in the past which is representable by SysTime.
The SysTime which is returned is in UTC.
Returns the SysTime farthest in the future which is representable by SysTime.
The SysTime which is returned is in UTC.
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. And, as per
ISO 8601, it also treats 1 B.C. as
year 0. So, 1 B.C. is 0, 2 B.C. is -1, etc. Use yearBC if want B.C. as
a positive integer with 1 B.C. being the year prior to 1 A.D.
Year 0 is a leap year.
int year | Year of the Gregorian Calendar. Positive values are A.D. Non-positive values are B.C. with year 0 being the year prior to 1 A.D. |
int month | Month of the year. |
int day | Day of the month. |
int day | The Xth day of the Gregorian Calendar that the constructed Date will be for. |
Compares this Date with the given Date.
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
assert(Date(1999, 7, 6).year == 1999); assert(Date(2010, 10, 4).year == 2010); assert(Date(-7, 4, 5).year == -7);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
assert(Date(0, 1, 1).yearBC == 1); assert(Date(-1, 1, 1).yearBC == 2); assert(Date(-100, 1, 1).yearBC == 101);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
int year | The year B.C. to set this Date's year to. |
auto date = Date(2010, 1, 1); date.yearBC = 1; assert(date == Date(0, 1, 1)); date.yearBC = 10; assert(date == Date(-9, 1, 1));
Month of a Gregorian Year.
assert(Date(1999, 7, 6).month == 7); assert(Date(2010, 10, 4).month == 10); assert(Date(-7, 4, 5).month == 4);
Day of a Gregorian Month.
assert(Date(1999, 7, 6).day == 6); assert(Date(2010, 10, 4).day == 4); assert(Date(-7, 4, 5).day == 5);
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).
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. |
auto d1 = Date(2010, 1, 1); d1.add!"months"(11); assert(d1 == Date(2010, 12, 1)); auto d2 = Date(2010, 1, 1); d2.add!"months"(-11); assert(d2 == Date(2009, 2, 1)); auto d3 = Date(2000, 2, 29); d3.add!"years"(1); assert(d3 == Date(2001, 3, 1)); auto d4 = Date(2000, 2, 29); d4.add!"years"(1, AllowDayOverflow.no); assert(d4 == Date(2001, 2, 28));
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.
units | The type of units to add ("years" or "months"). |
long value | The number of months or years to add to this Date. |
auto d1 = Date(2010, 1, 1); d1.roll!"months"(1); assert(d1 == Date(2010, 2, 1)); auto d2 = Date(2010, 1, 1); d2.roll!"months"(-1); assert(d2 == Date(2010, 12, 1)); auto d3 = Date(1999, 1, 29); d3.roll!"months"(1); assert(d3 == Date(1999, 3, 1)); auto d4 = Date(1999, 1, 29); d4.roll!"months"(1, AllowDayOverflow.no); assert(d4 == Date(1999, 2, 28)); auto d5 = Date(2000, 2, 29); d5.roll!"years"(1); assert(d5 == Date(2001, 3, 1)); auto d6 = Date(2000, 2, 29); d6.roll!"years"(1, AllowDayOverflow.no); assert(d6 == Date(2001, 2, 28));
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".
units | The units to add. Must be "days". |
value | The number of days to add to this Date. |
auto d = Date(2010, 1, 1); d.roll!"days"(1); assert(d == Date(2010, 1, 2)); d.roll!"days"(365); assert(d == Date(2010, 1, 26)); d.roll!"days"(-32); assert(d == Date(2010, 1, 25));
Gives the result of adding or subtracting a duration from this Date.
The legal types of arithmetic for Date using this operator are
Date | + | duration | --> | Date |
Date | - | duration | --> | Date |
D duration | The duration to add to or subtract from this Date. |
Gives the result of adding or subtracting a 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 |
D duration | The duration to add to or subtract from this Date. |
Gives the difference between two Dates.
The legal types of arithmetic for Date using this operator are
Date | - | Date | --> | duration |
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 Duration
that results. Because converting between months and smaller
units requires a specific date (which 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.
Date rhs | The Date to subtract from this one. |
assert(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31)) == 1); assert(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1)) == -1); assert(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1)) == 2); assert(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31)) == -2);
Whether this Date is in a leap year.
Day of the week this Date is on.
Day of the year this Date is on.
assert(Date(1999, 1, 1).dayOfYear == 1); assert(Date(1999, 12, 31).dayOfYear == 365); assert(Date(2000, 12, 31).dayOfYear == 366);
Day of the year.
int day | The day of the year to set which day of the year this Date is on. |
The Xth day of the Gregorian Calendar that this Date is on.
assert(Date(1, 1, 1).dayOfGregorianCal == 1); assert(Date(1, 12, 31).dayOfGregorianCal == 365); assert(Date(2, 1, 1).dayOfGregorianCal == 366); assert(Date(0, 12, 31).dayOfGregorianCal == 0); assert(Date(0, 1, 1).dayOfGregorianCal == -365); assert(Date(-1, 12, 31).dayOfGregorianCal == -366); assert(Date(2000, 1, 1).dayOfGregorianCal == 730_120); assert(Date(2010, 12, 31).dayOfGregorianCal == 734_137);
The Xth day of the Gregorian Calendar that this Date is on.
int day | The day of the Gregorian Calendar to set this Date to. |
auto date = Date.init; date.dayOfGregorianCal = 1; assert(date == Date(1, 1, 1)); date.dayOfGregorianCal = 365; assert(date == Date(1, 12, 31)); date.dayOfGregorianCal = 366; assert(date == Date(2, 1, 1)); date.dayOfGregorianCal = 0; assert(date == Date(0, 12, 31)); date.dayOfGregorianCal = -365; assert(date == Date(-0, 1, 1)); date.dayOfGregorianCal = -366; assert(date == Date(-1, 12, 31)); date.dayOfGregorianCal = 730_120; assert(date == Date(2000, 1, 1)); date.dayOfGregorianCal = 734_137; assert(date == Date(2010, 12, 31));
The ISO 8601 week of the year that this Date is in.
Date for the last day in the month that this Date is in.
assert(Date(1999, 1, 6).endOfMonth == Date(1999, 1, 31)); assert(Date(1999, 2, 7).endOfMonth == Date(1999, 2, 28)); assert(Date(2000, 2, 7).endOfMonth == Date(1999, 2, 29)); assert(Date(2000, 6, 4).endOfMonth == Date(1999, 6, 30));
The last day in the month that this Date is in.
assert(Date(1999, 1, 6).daysInMonth == 31); assert(Date(1999, 2, 7).daysInMonth == 28); assert(Date(2000, 2, 7).daysInMonth == 29); assert(Date(2000, 6, 4).daysInMonth == 30);
Whether the current year is a date in A.D.
assert(Date(1, 1, 1).isAD); assert(Date(2010, 12, 31).isAD); assert(!Date(0, 12, 31).isAD); assert(!Date(-2010, 1, 1).isAD);
The julian day for this Date at noon (since the julian day changes at noon).
The modified julian day for any time on this date (since, the modified julian day changes at midnight).
Converts this Date to a string with the format YYYYMMDD.
assert(Date(2010, 7, 4).toISOString() == "20100704"); assert(Date(1998, 12, 25).toISOString() == "19981225"); assert(Date(0, 1, 5).toISOString() == "00000105"); assert(Date(-4, 1, 5).toISOString() == "-00040105");
Converts this Date to a string with the format YYYY-MM-DD.
assert(Date(2010, 7, 4).toISOExtString() == "2010-07-04"); assert(Date(1998, 12, 25).toISOExtString() == "1998-12-25"); assert(Date(0, 1, 5).toISOExtString() == "0000-01-05"); assert(Date(-4, 1, 5).toISOExtString() == "-0004-01-05");
Converts this Date to a string with the format YYYY-Mon-DD.
assert(Date(2010, 7, 4).toSimpleString() == "2010-Jul-04"); assert(Date(1998, 12, 25).toSimpleString() == "1998-Dec-25"); assert(Date(0, 1, 5).toSimpleString() == "0000-Jan-05"); assert(Date(-4, 1, 5).toSimpleString() == "-0004-Jan-05");
Converts this Date to a string.
Creates a Date from a string with the format YYYYMMDD. Whitespace is stripped from the given string.
S isoString | A string formatted in the ISO format for dates. |
assert(Date.fromISOString("20100704") == Date(2010, 7, 4)); assert(Date.fromISOString("19981225") == Date(1998, 12, 25)); assert(Date.fromISOString("00000105") == Date(0, 1, 5)); assert(Date.fromISOString("-00040105") == Date(-4, 1, 5)); assert(Date.fromISOString(" 20100704 ") == Date(2010, 7, 4));
Creates a Date from a string with the format YYYY-MM-DD. Whitespace is stripped from the given string.
S isoExtString | A string formatted in the ISO Extended format for dates. |
assert(Date.fromISOExtString("2010-07-04") == Date(2010, 7, 4)); assert(Date.fromISOExtString("1998-12-25") == Date(1998, 12, 25)); assert(Date.fromISOExtString("0000-01-05") == Date(0, 1, 5)); assert(Date.fromISOExtString("-0004-01-05") == Date(-4, 1, 5)); assert(Date.fromISOExtString(" 2010-07-04 ") == Date(2010, 7, 4));
Creates a Date from a string with the format YYYY-Mon-DD. Whitespace is stripped from the given string.
S simpleString | A string formatted in the way that toSimpleString formats dates. |
assert(Date.fromSimpleString("2010-Jul-04") == Date(2010, 7, 4)); assert(Date.fromSimpleString("1998-Dec-25") == Date(1998, 12, 25)); assert(Date.fromSimpleString("0000-Jan-05") == Date(0, 1, 5)); assert(Date.fromSimpleString("-0004-Jan-05") == Date(-4, 1, 5)); assert(Date.fromSimpleString(" 2010-Jul-04 ") == Date(2010, 7, 4));
Returns the Date farthest in the past which is representable by Date.
Returns the Date farthest in the future which is representable by Date.
Represents a time of day with hours, minutes, and seconds. It uses 24 hour time.
int hour | Hour of the day [0 - 24). |
int minute | Minute of the hour [0 - 60). |
int second | Second of the minute [0 - 60). |
Compares this TimeOfDay with the given TimeOfDay.
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Hours passed midnight.
Minutes passed the hour.
Seconds passed the minute.
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".
units | The units to add. |
long value | The number of units to add to this TimeOfDay. |
auto tod1 = TimeOfDay(7, 12, 0); tod1.roll!"hours"(1); assert(tod1 == TimeOfDay(8, 12, 0)); auto tod2 = TimeOfDay(7, 12, 0); tod2.roll!"hours"(-1); assert(tod2 == TimeOfDay(6, 12, 0)); auto tod3 = TimeOfDay(23, 59, 0); tod3.roll!"minutes"(1); assert(tod3 == TimeOfDay(23, 0, 0)); auto tod4 = TimeOfDay(0, 0, 0); tod4.roll!"minutes"(-1); assert(tod4 == TimeOfDay(0, 59, 0)); auto tod5 = TimeOfDay(23, 59, 59); tod5.roll!"seconds"(1); assert(tod5 == TimeOfDay(23, 59, 0)); auto tod6 = TimeOfDay(0, 0, 0); tod6.roll!"seconds"(-1); assert(tod6 == TimeOfDay(0, 0, 59));
Gives the result of adding or subtracting a duration from this TimeOfDay.
The legal types of arithmetic for TimeOfDay using this operator are
TimeOfDay | + | duration | --> | TimeOfDay |
TimeOfDay | - | duration | --> | TimeOfDay |
D duration | The duration to add to or subtract from this TimeOfDay. |
Gives the result of adding or subtracting a 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 |
D duration | The duration to add to or subtract from this TimeOfDay. |
Gives the difference between two TimeOfDays.
The legal types of arithmetic for TimeOfDay using this operator are
TimeOfDay | - | TimeOfDay | --> | duration |
TimeOfDay rhs | The TimeOfDay to subtract from this one. |
Converts this TimeOfDay to a string with the format HHMMSS.
assert(TimeOfDay(0, 0, 0).toISOString() == "000000"); assert(TimeOfDay(12, 30, 33).toISOString() == "123033");
Converts this TimeOfDay to a string with the format HH:MM:SS.
assert(TimeOfDay(0, 0, 0).toISOExtString() == "000000"); assert(TimeOfDay(12, 30, 33).toISOExtString() == "123033");
Converts this TimeOfDay to a string.
Creates a TimeOfDay from a string with the format HHMMSS. Whitespace is stripped from the given string.
S isoString | A string formatted in the ISO format for times. |
assert(TimeOfDay.fromISOString("000000") == TimeOfDay(0, 0, 0)); assert(TimeOfDay.fromISOString("123033") == TimeOfDay(12, 30, 33)); assert(TimeOfDay.fromISOString(" 123033 ") == TimeOfDay(12, 30, 33));
Creates a TimeOfDay from a string with the format HH:MM:SS. Whitespace is stripped from the given string.
isoString | A string formatted in the ISO Extended format for times. |
assert(TimeOfDay.fromISOExtString("00:00:00") == TimeOfDay(0, 0, 0)); assert(TimeOfDay.fromISOExtString("12:30:33") == TimeOfDay(12, 30, 33)); assert(TimeOfDay.fromISOExtString(" 12:30:33 ") == TimeOfDay(12, 30, 33));
Returns midnight.
Returns one second short of midnight.
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.
Date date | The date portion of DateTime. |
TimeOfDay tod | The time portion of DateTime. |
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; |
Compares this DateTime with the given DateTime..
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
The date portion of DateTime.
The time portion of DateTime.
The time portion of DateTime.
TimeOfDay tod | The TimeOfDay to set this DateTime's time portion to. |
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
int year | The year to set this DateTime's year to. |
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year == 1999); assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year == 2010); assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year == -7);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
assert(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC == 1); assert(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC == 2); assert(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC == 101);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
int year | The year B.C. to set this DateTime's year to. |
auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0)); dt.yearBC = 1; assert(dt == DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0))); dt.yearBC = 10; assert(dt == DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0)));
Month of a Gregorian Year.
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month == 7); assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month == 10); assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month == 4);
Day of a Gregorian Month.
assert(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day == 6); assert(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day == 4); assert(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day == 5);
Hours passed midnight.
Minutes passed the hour.
Seconds passed the minute.
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).
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. |
auto dt1 = DateTime(2010, 1, 1, 12, 30, 33); dt1.add!"months"(11); assert(dt1 == DateTime(2010, 12, 1, 12, 30, 33)); auto dt2 = DateTime(2010, 1, 1, 12, 30, 33); dt2.add!"months"(-11); assert(dt2 == DateTime(2009, 2, 1, 12, 30, 33)); auto dt3 = DateTime(2000, 2, 29, 12, 30, 33); dt3.add!"years"(1); assert(dt3 == DateTime(2001, 3, 1, 12, 30, 33)); auto dt4 = DateTime(2000, 2, 29, 12, 30, 33); dt4.add!"years"(1, AllowDayOverflow.no); assert(dt4 == DateTime(2001, 2, 28, 12, 30, 33));
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.
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. |
auto dt1 = DateTime(2010, 1, 1, 12, 33, 33); dt1.roll!"months"(1); assert(dt1 == DateTime(2010, 2, 1, 12, 33, 33)); auto dt2 = DateTime(2010, 1, 1, 12, 33, 33); dt2.roll!"months"(-1); assert(dt2 == DateTime(2010, 12, 1, 12, 33, 33)); auto dt3 = DateTime(1999, 1, 29, 12, 33, 33); dt3.roll!"months"(1); assert(dt3 == DateTime(1999, 3, 1, 12, 33, 33)); auto dt4 = DateTime(1999, 1, 29, 12, 33, 33); dt4.roll!"months"(1, AllowDayOverflow.no); assert(dt4 == DateTime(1999, 2, 28, 12, 33, 33)); auto dt5 = DateTime(2000, 2, 29, 12, 30, 33); dt5.roll!"years"(1); assert(dt5 == DateTime(2001, 3, 1, 12, 30, 33)); auto dt6 = DateTime(2000, 2, 29, 12, 30, 33); dt6.roll!"years"(1, AllowDayOverflow.no); assert(dt6 == DateTime(2001, 2, 28, 12, 30, 33));
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".
units | The units to add. |
value | The number of units to add to this DateTime. |
auto dt1 = DateTime(2010, 1, 1, 11, 23, 12); dt1.roll!"days"(1); assert(dt1 == DateTime(2010, 1, 2, 11, 23, 12)); dt1.roll!"days"(365); assert(dt1 == DateTime(2010, 1, 26, 11, 23, 12)); dt1.roll!"days"(-32); assert(dt1 == DateTime(2010, 1, 25, 11, 23, 12)); auto dt2 = DateTime(2010, 7, 4, 12, 0, 0); dt2.roll!"hours"(1); assert(dt2 == DateTime(2010, 7, 4, 13, 0, 0)); auto dt3 = DateTime(2010, 1, 1, 0, 0, 0); dt3.roll!"seconds"(-1); assert(dt3 == DateTime(2010, 1, 1, 0, 0, 59));
Gives the result of adding or subtracting a duration from this DateTime.
The legal types of arithmetic for DateTime using this operator are
DateTime | + | duration | --> | DateTime |
DateTime | - | duration | --> | DateTime |
D duration | The duration to add to or subtract from this DateTime. |
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 are
DateTime | + | duration | --> | DateTime |
DateTime | - | duration | --> | DateTime |
D duration | The duration to add to or subtract from this DateTime. |
Gives the difference between two DateTimes.
The legal types of arithmetic for DateTime using this operator are
DateTime | - | DateTime | --> | duration |
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 Duration
that results. Because converting between months and smaller
units requires a specific date (which 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.
DateTime rhs | The DateTime to subtract from this one. |
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);
Whether this DateTime is in a leap year.
Day of the week this DateTime is on.
Day of the year this DateTime is on.
assert(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear == 1); assert(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear == 365); assert(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear == 366);
Day of the year.
int day | The day of the year to set which day of the year this DateTime is on. |
The Xth day of the Gregorian Calendar that this DateTime is on.
assert(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal == 1); assert(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal == 365); assert(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal == 366); assert(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal == 0); assert(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal == -365); assert(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal == -366); assert(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal == 730_120); assert(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal == 734_137);
The Xth day of the Gregorian Calendar that this DateTime is on. Setting this property does not affect the time portion of DateTime.
int days | The day of the Gregorian Calendar to set this DateTime to. |
auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0)); dt.dayOfGregorianCal = 1; assert(dt == DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = 365; assert(dt == DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = 366; assert(dt == DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = 0; assert(dt == DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = -365; assert(dt == DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = -366; assert(dt == DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = 730_120; assert(dt == DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0))); dt.dayOfGregorianCal = 734_137; assert(dt == DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0)));
The ISO 8601 week of the year that this DateTime is in.
DateTime for the last day in the month that this DateTime is in. The time portion of endOfMonth is always 23:59:59.
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)));
The last day in the month that this DateTime is in.
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth == 31); assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth == 28); assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth == 29); assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth == 30);
Whether the current year is a date in A.D.
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);
The julian day for this DateTime at the given time. For example, prior to noon, 1996-03-31 would be the julian day number 2450_173, so this function returns 2450_173, while from noon onward, the julian day number would be 2450_174, so this function returns 2450_174.
The modified julian day for any time on this date (since, the modified julian day changes at midnight).
Converts this DateTime to a string with the format YYYYMMDDTHHMMSS.
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");
Converts this DateTime to a string with the format YYYY-MM-DDTHH:MM:SS.
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");
Converts this DateTime to a string with the format YYYY-Mon-DD HH:MM:SS.
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(Dte(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() == "-0004-Jan-05 00:00:02");
Converts this DateTime to a string.
Creates a DateTime from a string with the format YYYYMMDDTHHMMSS. Whitespace is stripped from the given string.
S isoString | A string formatted in the ISO format for dates and times. |
assert(DateTime.fromISOString("20100704T070612") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12))); assert(DateTime.fromISOString("19981225T021500") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0))); assert(DateTime.fromISOString("00000105T230959") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59))); assert(DateTime.fromISOString("-00040105T000002") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2))); assert(DateTime.fromISOString(" 20100704T070612 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
Creates a DateTime from a string with the format YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.
isoString | A string formatted in the ISO Extended format for dates and times. |
assert(DateTime.fromISOExtString("2010-07-04T07:06:12") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12))); assert(DateTime.fromISOExtString("1998-12-25T02:15:00") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0))); assert(DateTime.fromISOExtString("0000-01-05T23:09:59") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59))); assert(DateTime.fromISOExtString("-0004-01-05T00:00:02") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2))); assert(DateTime.fromISOExtString(" 2010-07-04T07:06:12 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
Creates a DateTime from a string with the format YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.
S simpleString | A string formatted in the way that toSimpleString formats dates and times. |
assert(DateTime.fromSimpleString("2010-Jul-04 07:06:12") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12))); assert(DateTime.fromSimpleString("1998-Dec-25 02:15:00") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0))); assert(DateTime.fromSimpleString("0000-Jan-05 23:09:59") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59))); assert(DateTime.fromSimpleString("-0004-Jan-05 00:00:02") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2))); assert(DateTime.fromSimpleString(" 2010-Jul-04 07:06:12 ") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)));
Returns the DateTime farthest in the past which is representable by DateTime.
Returns the DateTime farthest in the future which is representable by DateTime.
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.
[January 5th, 2010 - March 10th, 2010) |
[05:00:30 - 12:00:00) |
[1982-01-04T08:59:00 - 2010-07-04T12:00:00) |
TP begin | The time point which begins the interval. |
U end | The time point which ends (but is not included in) the interval. |
Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
TP begin | The time point which begins the interval. |
D duration | The duration from the starting point to the end point. |
assert(Interval!Date(Date(1996, 1, 2), dur!"years"(3)) == Interval!Date(Date(1996, 1, 2), Date(1999, 1, 2)));
Interval rhs | The Interval to assign to this one. |
Interval rhs | The Interval to assign to this one. |
The starting point of the interval. It is included in the interval.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).begin ==
Date(1996, 1, 2));
The starting point of the interval. It is included in the interval.
TP timePoint | The time point to set begin to. |
The end point of the interval. It is excluded from the interval.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).end ==
Date(2012, 3, 1));
Returns the duration between begin and end.
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).length == dur!"days"(5903));
Whether the interval's length is 0, that is, whether begin == end.
assert(Interval!Date(Date(1996, 1, 2), Date(1996, 1, 2)).empty); assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).empty);
Whether the given time point is within this interval.
TP timePoint | The time point to check for inclusion in this interval. |
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)));
Whether the given interval is completely within this interval.
Interval interval | The interval to check for inclusion in this interval. |
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))));
Whether the given interval is completely within this interval.
Always returns false (unless this interval is empty), because an interval going to positive infinity can never be contained in a finite interval.
PosInfInterval!TP interval | The interval to check for inclusion in this interval. |
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
PosInfInterval!Date(Date(1999, 5, 4))));
Whether the given interval is completely within this interval.
Always returns false (unless this interval is empty), because an interval beginning at negative infinity can never be contained in a finite interval.
NegInfInterval!TP interval | The interval to check for inclusion in this interval. |
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).contains(
NegInfInterval!Date(Date(1996, 5, 4))));
Whether this interval is before the given time point.
TP timePoint | The time point to check whether this interval is before it. |
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)));
Whether this interval is before the given interval and does not intersect with it.
Interval interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect with it.
PosInfInterval!TP interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect with it.
Always returns false (unless this interval is empty) because a finite interval can never be before an interval beginning at negative infinity.
NegInfInterval!TP interval | The interval to check for against this interval. |
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isBefore(
NegInfInterval!Date(Date(1996, 5, 4))));
Whether this interval is after the given time point.
TP timePoint | The time point to check whether this interval is after it. |
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)));
Whether this interval is after the given interval and does not intersect it.
Interval interval | The interval to check against this interval. |
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))));
Whether this interval is after the given interval and does not intersect it.
Always returns false (unless this interval is empty) because a finite interval can never be after an interval going to positive infinity.
PosInfInterval!TP interval | The interval to check against this interval. |
assert(!Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
PosInfInterval!Date(Date(1999, 5, 4))));
Whether this interval is after the given interval and does not intersect it.
NegInfInterval!TP interval | The interval to check against this interval. |
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).isAfter(
NegInfInterval!Date(Date(1996, 1, 2))));
Whether the given interval overlaps this interval.
Interval interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
PosInfInterval!TP interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
NegInfInterval!TP interval | The interval to check for intersection with this interval. |
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))));
Returns the intersection of two intervals
Interval interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
PosInfInterval!TP interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
NegInfInterval!TP interval | The interval to intersect with this interval. |
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)));
Whether the given interval is adjacent to this interval.
Interval interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
PosInfInterval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
NegInfInterval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Returns the union of two intervals
Interval interval | The interval to merge with this interval. |
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)));
Returns the union of two intervals
PosInfInterval!TP interval | The interval to merge with this interval. |
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)));
Returns the union of two intervals
NegInfInterval!TP interval | The interval to merge with this interval. |
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)));
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.
Interval interval | The interval to create a span together with this interval. |
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)));
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.
PosInfInterval!TP interval | The interval to create a span together with this interval. |
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)));
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.
NegInfInterval!TP interval | The interval to create a span together with this interval. |
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)));
Shifts the interval forward or backwards in time by the given duration (a positive duration shifts the interval forward; a negative duration shifts it backward). Effectively, it does begin += duration and end += duration.
D duration | The duration to shift the interval by. |
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)));
Shifts the interval forward or backwards in time by the given number of years and/or months (a positive number of years and months shifts the interval forward; a negative number shifts it backward). It adds the years the given years and months to both begin and end. It effectively calls add!"years"() and then add!"months"() on begin and end with the given number of years and months.
T years | The number of years to shift the interval by. |
T months | The number of months to shift the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on begin and end, causing their month to increment. |
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)));
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 by dir.
D duration | The duration to expand the interval by. |
Direction dir | The direction in time to expand the interval. |
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)));
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 by dir.
T years | The number of years to expand the interval by. |
T months | The number of months to expand the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on begin and end, causing their month to increment. |
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)));
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. If
popFirst is PopFirst.yes, then popFront is called
before the range is returned (so that front is a time point which
func would generate).
If func 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 when
func 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 to fwdRange. Their documentation starts with
"Range-generating function," making them easily searchable.
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. |
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9)); auto func = (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 PopFirst.yes 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);
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. If
popFirst is PopFirst.yes, then popFront is called
before the range is returned (so that front is a time point which
func would generate).
If func 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 when
func 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 to bwdRange. Their documentation starts with
"Range-generating function," making them easily searchable.
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. |
auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9)); auto func = (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 PopFirst.yes 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);
Converts this interval to a string.
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 using PosInfInterval is to create an infinite range which starts at a fixed point in time and goes to positive infinity.
TP begin | The time point which begins the interval. |
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
PosInfInterval rhs | The PosInfInterval to assign to this one. |
PosInfInterval rhs | The PosInfInterval to assign to this one. |
The starting point of the interval. It is included in the interval.
assert(PosInfInterval!Date(Date(1996, 1, 2)).begin == Date(1996, 1, 2));
The starting point of the interval. It is included in the interval.
TP timePoint | The time point to set begin to. |
Whether the interval's length is 0. Always returns false.
assert(!PosInfInterval!Date(Date(1996, 1, 2)).empty);
Whether the given time point is within this interval.
TP timePoint | The time point to check for inclusion in this interval. |
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(1994, 12, 24))); assert(PosInfInterval!Date(Date(1996, 1, 2)).contains(Date(2000, 1, 5)));
Whether the given interval is completely within this interval.
Interval!TP interval | The interval to check for inclusion in this interval. |
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))));
Whether the given interval is completely within this interval.
PosInfInterval interval | The interval to check for inclusion in this interval. |
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))));
Whether the given interval is completely within this interval.
Always returns false because an interval going to positive infinity can never contain an interval beginning at negative infinity.
NegInfInterval!TP interval | The interval to check for inclusion in this interval. |
assert(!PosInfInterval!Date(Date(1996, 1, 2)).contains(
NegInfInterval!Date(Date(1996, 5, 4))));
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.
TP timePoint | The time point to check whether this interval is before it. |
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(1994, 12, 24))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(Date(2000, 1, 5)));
Whether this interval is before the given interval and does not intersect it.
Always returns false (unless the given interval is empty) because an interval going to positive infinity can never be before any other interval.
Interval!TP interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect it.
Always returns false because an interval going to positive infinity can never be before any other interval.
PosInfInterval interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect it.
Always returns false because an interval going to positive infinity can never be before any other interval.
NegInfInterval!TP interval | The interval to check for against this interval. |
assert(!PosInfInterval!Date(Date(1996, 1, 2)).isBefore(
NegInfInterval!Date(Date(1996, 5, 4))));
Whether this interval is after the given time point.
TP timePoint | The time point to check whether this interval is after it. |
assert(PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(1994, 12, 24))); assert(!PosInfInterval!Date(Date(1996, 1, 2)).isAfter(Date(2000, 1, 5)));
Whether this interval is after the given interval and does not intersect it.
Interval!TP interval | The interval to check against this interval. |
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))));
Whether this interval is after the given interval and does not intersect it.
Always returns false because an interval going to positive infinity can never be after another interval going to positive infinity.
PosInfInterval interval | The interval to check against this interval. |
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))));
Whether this interval is after the given interval and does not intersect it.
NegInfInterval!TP interval | The interval to check against this interval. |
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))));
Whether the given interval overlaps this interval.
Interval!TP interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
Always returns true because two intervals going to positive infinity always overlap.
PosInfInterval interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
NegInfInterval!TP interval | The interval to check for intersection with this interval. |
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))));
Returns the intersection of two intervals
Interval!TP interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
PosInfInterval interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
NegInfInterval!TP interval | The interval to intersect with this interval. |
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)));
Whether the given interval is adjacent to this interval.
Interval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
Always returns false because two intervals going to positive infinity can never be adjacent to one another.
PosInfInterval interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
NegInfInterval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Returns the union of two intervals
Interval!TP interval | The interval to merge with this interval. |
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)));
Returns the union of two intervals
PosInfInterval interval | The interval to merge with this interval. |
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)));
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.
Interval!TP interval | The interval to create a span together with this interval. |
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)));
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.
PosInfInterval interval | The interval to create a span together with this interval. |
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)));
Shifts the begin of this interval forward or backwards in time by the given duration (a positive duration shifts the interval forward; a negative duration shifts it backward). Effectively, it does begin += duration.
D duration | The duration to shift the interval by. |
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)));
Shifts the begin of this interval forward or backwards in time by the given number of years and/or months (a positive number of years and months shifts the interval forward; a negative number shifts it backward). It adds the years the given years and months to begin. It effectively calls add!"years"() and then add!"months"() on begin with the given number of years and months.
T years | The number of years to shift the interval by. |
T months | The number of months to shift the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on begin, causing its month to increment. |
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)));
Expands the interval backwards in time. Effectively, it does begin -= duration.
D duration | The duration to expand the interval by. |
dir | The direction in time to expand the interval. |
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)));
Expands the interval forwards and/or backwards in time. Effectively, it subtracts the given number of months/years from begin.
T years | The number of years to expand the interval by. |
T months | The number of months to expand the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on begin, causing its month to increment. |
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)));
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. If
popFirst is PopFirst.yes, then popFront is called
before the range is returned (so that front is a time point which
func would generate).
If func 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 to fwdRange. Their documentation starts with
"Range-generating function," to make them easily searchable.
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. |
auto interval = PosInfInterval!Date(Date(2010, 9, 1)); auto func = (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 PopFirst.yes 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);
Converts this interval to a string.
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 using NegInfInterval is to create an infinite range which starts at negative infinity and goes to a fixed end point. Iterate over it in reverse.
begin | The time point which begins the interval. |
auto interval = PosInfInterval!Date(Date(1996, 1, 2));
NegInfInterval rhs | The NegInfInterval to assign to this one. |
NegInfInterval rhs | The NegInfInterval to assign to this one. |
The end point of the interval. It is excluded from the interval.
assert(NegInfInterval!Date(Date(2012, 3, 1)).end == Date(2012, 3, 1));
Whether the interval's length is 0. Always returns false.
assert(!NegInfInterval!Date(Date(1996, 1, 2)).empty);
Whether the given time point is within this interval.
TP timePoint | The time point to check for inclusion in this interval. |
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)));
Whether the given interval is completely within this interval.
Interval!TP interval | The interval to check for inclusion in this interval. |
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))));
Whether the given interval is completely within this interval.
Always returns false because an interval beginning at negative infinity can never contain an interval going to positive infinity.
PosInfInterval!TP interval | The interval to check for inclusion in this interval. |
assert(!NegInfInterval!Date(Date(2012, 3, 1)).contains(
PosInfInterval!Date(Date(1999, 5, 4))));
Whether the given interval is completely within this interval.
NegInfInterval interval | The interval to check for inclusion in this interval. |
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))));
Whether this interval is before the given time point.
TP timePoint | The time point to check whether this interval is before it. |
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)));
Whether this interval is before the given interval and does not intersect it.
Interval!TP interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect it.
PosInfInterval!TP interval | The interval to check for against this interval. |
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))));
Whether this interval is before the given interval and does not intersect it.
Always returns false because an interval beginning at negative infinity can never be before another interval beginning at negative infinity.
NegInfInterval interval | The interval to check for against this interval. |
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))));
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.
TP timePoint | The time point to check whether this interval is after it. |
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)));
Whether this interval is after the given interval and does not intersect it.
Always returns false (unless the given interval is empty) because an interval beginning at negative infinity can never be after any other interval.
Interval!TP interval | The interval to check against this interval. |
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))));
Whether this interval is after the given interval and does not intersect it.
Always returns false because an interval beginning at negative infinity can never be after any other interval.
PosInfInterval!TP interval | The interval to check against this interval. |
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))));
Whether this interval is after the given interval and does not intersect it.
Always returns false because an interval beginning at negative infinity can never be after any other interval.
NegInfInterval interval | The interval to check against this interval. |
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))));
Whether the given interval overlaps this interval.
Interval!TP interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
PosInfInterval!TP interval | The interval to check for intersection with this interval. |
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))));
Whether the given interval overlaps this interval.
Always returns true because two intervals beginning at negative infinity always overlap.
NegInfInterval!TP interval | The interval to check for intersection with this interval. |
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))));
Returns the intersection of two intervals
Interval!TP interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
PosInfInterval!TP interval | The interval to intersect with this interval. |
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)));
Returns the intersection of two intervals
NegInfInterval interval | The interval to intersect with this interval. |
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)));
Whether the given interval is adjacent to this interval.
Interval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
PosInfInterval!TP interval | The interval to check whether its adjecent to this interval. |
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))));
Whether the given interval is adjacent to this interval.
Always returns false because two intervals beginning at negative infinity can never be adjacent to one another.
NegInfInterval interval | The interval to check whether its adjecent to this interval. |
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))));
Returns the union of two intervals
Interval!TP interval | The interval to merge with this interval. |
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)));
Returns the union of two intervals
NegInfInterval interval | The interval to merge with this interval. |
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)));
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.
Interval!TP interval | The interval to create a span together with this interval. |
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)));
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.
NegInfInterval interval | The interval to create a span together with this interval. |
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)));
Shifts the end of this interval forward or backwards in time by the given duration (a positive duration shifts the interval forward; a negative duration shifts it backward). Effectively, it does end += duration.
D duration | The duration to shift the interval by. |
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)));
Shifts the end of this interval forward or backwards in time by the given number of years and/or months (a positive number of years and months shifts the interval forward; a negative number shifts it backward). It adds the years the given years and months to end. It effectively calls add!"years"() and then add!"months"() on end with the given number of years and months.
T years | The number of years to shift the interval by. |
T months | The number of months to shift the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on end, causing its month to increment. |
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)));
Expands the interval forwards in time. Effectively, it does end += duration.
D duration | The duration to expand the interval by. |
dir | The direction in time to expand the interval. |
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)));
Expands the interval forwards and/or backwards in time. Effectively, it adds the given number of months/years to end.
T years | The number of years to expand the interval by. |
T months | The number of months to expand the interval by. |
AllowDayOverflow allowOverflow | Whether the days should be allowed to overflow on end, causing their month to increment. |
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)));
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. If
popFirst is PopFirst.yes, then popFront is called
before the range is returned (so that front is a time point which
func would generate).
If func 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 to bwdRange. Their documentation starts with
"Range-generating function," to make them easily searchable.
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. |
auto interval = NegInfInterval!Date(Date(2010, 9, 9)); auto func = (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 PopFirst.yes 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);
Converts this interval to a string.
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.
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. |
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27)); auto func = everyDayOfWeek!Date(DayOfWeek.mon); auto range = interval.fwdRange(func); //A Thursday. Using PopFirst.yes would have made this Date(2010, 9, 6). assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2010, 9, 6)); range.popFront(); assert(range.front == Date(2010, 9, 13)); range.popFront(); assert(range.front == Date(2010, 9, 20)); range.popFront(); assert(range.empty);
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 same month 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 to
everyMonth to create the delegate.
Since it wouldn't really make sense to be iterating over a specific month
and end up with some of the time points in the succeeding month or two years
after the previous time point, AllowDayOverflow.no is always used when
calculating the next time point.
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. |
auto interval = Interval!Date(Date(2000, 1, 30), Date(2004, 8, 5)); auto func = everyMonth!(Date)(Month.feb); auto range = interval.fwdRange(func); //Using PopFirst.yes would have made this Date(2010, 2, 29). assert(range.front == Date(2000, 1, 30)); range.popFront(); assert(range.front == Date(2000, 2, 29)); range.popFront(); assert(range.front == Date(2001, 2, 28)); range.popFront(); assert(range.front == Date(2002, 2, 28)); range.popFront(); assert(range.front == Date(2003, 2, 28)); range.popFront(); assert(range.front == Date(2004, 2, 28)); range.popFront(); assert(range.empty);
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 given duration e.g. passing dur!"days"(3) to
everyDuration would result in a delegate which could be used to iterate
over a range of days which are each 3 days apart.
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. |
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27)); auto func = everyDuration!Date(dur!"days"(8)); auto range = interval.fwdRange(func); //Using PopFirst.yes would have made this Date(2010, 9, 10). assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2010, 9, 10)); range.popFront(); assert(range.front == Date(2010, 9, 18)); range.popFront(); assert(range.front == Date(2010, 9, 26)); range.popFront(); assert(range.empty);
Range-generating function.
Returns a delegate which returns the next time point which is the given
number of years, month, and duration later.
The difference between this version of everyDuration and the version
which just takes a Duration is that this one also takes the number of
years and months (along with an AllowDayOverflow to indicate whether
adding years and months 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 the duration is added
to it. However, if iterating backwards, the duration 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 adding years and months is not entirely
reversible (due to possible day overflow, regardless of whether
AllowDayOverflow.yes or AllowDayOverflow.no 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).
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. |
auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27)); auto func = everyDuration!Date(4, 1, AllowDayOverflow.yes, dur!"days"(2)); auto range = interval.fwdRange(func); //Using PopFirst.yes would have made this Date(2014, 10, 12). assert(range.front == Date(2010, 9, 2)); range.popFront(); assert(range.front == Date(2014, 10, 4)); range.popFront(); assert(range.front == Date(2018, 11, 6)); range.popFront(); assert(range.front == Date(2022, 12, 8)); range.popFront(); assert(range.empty);
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 by IntervalRange'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 by IntervalRange. 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.
IntervalRange rhs | The IntervalRange to assign to this one. |
Whether this IntervalRange is empty.
The first time point in the range.
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.
Returns a copy of this.
The interval that this IntervalRange currently covers.
The function used to generate the next time point in the range.
The Direction that this range iterates in.
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 by PosInfIntervalRange'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.
PosInfIntervalRange rhs | The PosInfIntervalRange to assign to this one. |
This is an infinite range, so it is never empty.
The first time point in the range.
Pops front from the range, using func to generate the next time point in the range.
Returns a copy of this.
The interval that this range currently covers.
The function used to generate the next time point in the range.
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 by NegInfIntervalRange'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 by
NegInfIntervalRange. 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.
NegInfIntervalRange rhs | The NegInfIntervalRange to assign to this one. |
This is an infinite range, so it is never empty.
The first time point in the range.
Pops front from the range, using func to generate the next time point in the range.
Returns a copy of this.
The interval that this range currently covers.
The function used to generate the next time point in the range.
Represents a time zone. It is used with SysTime to indicate the time zone of a SysTime.
The name of the time zone per the TZ Database. This is the name used to get a TimeZone by name with TimeZone.getTimeZone.
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.
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.
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 for hasDST because the time zone did at some point have DST.
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.
long stdTime | The UTC time that needs to be checked for DST in this time zone. |
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.
long stdTime | The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime | The time in this time zone that needs to be adjusted to UTC time. |
Returns what the offset from UTC is at the given std time. It includes the DST offset in effect at that time (if any).
long stdTime | The UTC time for which to get the offset from UTC for this time zone. |
Returns a TimeZone with the give name 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 Database name is converted to the corresponding
time zone name on Windows prior to calling
WindowsTimeZone. getTimeZone. This function allows for
the same time zone names on both Windows and Posix systems.
string name | The TZ Database name of the desired time zone |
auto tz = TimeZone.getTimeZone("America/Los_Angeles");
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.
string subName | The first part of the time zones desired. |
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.
LocalTime is a singleton class. LocalTime returns its only instance.
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.
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.
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 for hasDST because the time zone did at some point have DST.
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.
long stdTime | The UTC time that needs to be checked for DST in this time zone. |
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.
long stdTime | The UTC time that needs to be adjusted to this time zone's time. |
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.
long adjTime | The time in this time zone that needs to be adjusted to UTC time. |
A TimeZone which represents UTC.
UTC is a singleton class. UTC returns its only instance.
Always returns false.
Always returns false.
Returns the given hnsecs without changing them at all.
long stdTime | The UTC time that needs to be adjusted to this time zone's time. |
Returns the given hnsecs without changing them at all.
long adjTime | The time in this time zone that needs to be adjusted to UTC time. |
Returns a core.time.Duration of 0.
long stdTime | The UTC time for which to get the offset from UTC for this time zone. |
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.
Always returns false.
Always returns false.
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.
long stdTime | The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime | The time in this time zone that needs to be adjusted to UTC time. |
Returns utcOffset as a core.time.Duration.
long stdTime | The UTC time for which to get the offset from UTC for this time zone. |
Duration utcOffset | This time zone's offset from UTC in minutes with west of UTC being negative (it is added to UTC to get the adjusted time). |
string stdName | The stdName for this time zone. |
The number of minutes the offset from UTC is (negative is west of UTC, positive is east).
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"> 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.
To get a PosixTimeZone, either call PosixTimeZone.getTimeZone (which allows specifying the location the time zone files) or call TimeZone.getTimeZone (which will give a PosixTimeZone on Posix systems and a WindowsTimeZone on Windows systems).
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 for hasDST because the time zone did at some point have DST.
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.
long stdTime | The UTC time that needs to be checked for DST in this time zone. |
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.
long stdTime | The UTC time that needs to be adjusted to this time zone's time. |
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).
long adjTime | The time in this time zone that needs to be adjusted to UTC time. |
The default directory where the TZ Database files are. It's empty for Windows, since Windows doesn't have them.
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.
string name | The TZ Database name of the desired time zone |
string 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. |
auto tz = PosixTimeZone.getTimeZone("America/Los_Angeles"); assert(tz.name == "America/Los_Angeles"); assert(tz.stdName == "PST"); assert(tz.dstName == "PDT");
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".
string subName | The first part of the desired time zones. |
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.
string tzName | The TZ Database name to convert. |
Converts the given Windows time zone name to a corresponding TZ Database name.
string tzName | The TZ Database name to convert. |
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 of StopWatch 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 affect StopWatch's accuracy.
void foo() { 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 know the number of seconds, // use properties of TickDuration. // (seconds, msecs, usecs, hnsecs) foreach(t; times) sum += t.hnsecs; writeln("Average time: ", sum/n, " hnsecs"); }
Auto start with constructor.
Resets the stop watch.
Starts the stop watch.
Stops the stop watch.
Peek at the amount of time which has passed since the stop watch was started.
Set the amount of time which has been measured since the stop watch was started.
Confirm whether this stopwatch is measuring time.
Benchmarks code for speed assessment and comparison.
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. |
int a; void f0() {} void f1() {auto b = a;} void f2() {auto b = to!(string)(a);} auto r = benchmark!(f0, f1, f2)(10_000); writefln("Milliseconds to call fun[0] n times: %s", r[0].msecs);
Return value of benchmark with two functions comparing.
Evaluation value
This 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.
The time required of the base function
The time required of the target function
Benchmark with two functions comparing.
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. |
void f1() { // ... } void f2() { // ... } void main() { auto b = comparingBenchmark!(f1, f2, 0x80); writeln(b.point); }
Whether the given type defines all of the necessary functions for it to function as a time point.
Whether the given Gregorian Year is a leap year.
int year | The year to to be tested. |
Converts a time_t (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).
time_t unixTime | The time_t to convert. |
Converts std time (which uses midnight, January 1st, 1 A.D. UTC as its epoch and hnsecs as its units) to time_t (which uses midnight, January 1st, 1970 UTC as its epoch and seconds as its units). If time_t is 32 bits, rather than 64, and the result can't fit in a 32-bit value, then the closest value that can be held in 32 bits will be used (so time_t.max if it goes over and time_t.min if it goes under).
long stdTime | The std time to convert. |
Type representing the DOS file date/time format.
Converts from DOS file date/time to SysTime.
DosFileTime dft | The DOS file time to convert. |
TimeZone tz | The time zone which the DOS file time is assumed to be in. |
Converts from SysTime to DOS file date/time.
SysTime sysTime | The SysTime to convert. |
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.
Compares two time unit strings. "years" are the largest units and "hnsecs" are the smallest.
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
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.
this < rhs | < 0 |
this == rhs | 0 |
this > rhs | > 0 |
Returns whether the given value is valid 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).
units | The units of time to validate. |
int value | The number to validate. |
assert(valid!"hours"(12)); assert(!valid!"hours"(32)); assert(valid!"months"(12)); assert(!valid!"months"(13));
Returns whether the given day is valid for the given year and month.
units | The units of time to validate. |
int year | The year of the day to validate. |
int month | The month of the day to validate. |
int day | The day to validate. |
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. |
units | The units of time to validate. |
int year | The year of the day to validate. |
Month month | The month of the day 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. |
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.
int currMonth | The current month of the year. |
int month | The month of the year to get the number of months to. |
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.
DayOfWeek currDoW | The current day of the week. |
DayOfWeek dow | The day of the week to get the number of days to. |