std.datetime
Module containing Date/Time functionality. This module provides:- Types to represent points in time: SysTime, Date, TimeOfDay, and DateTime.
- Types to represent durations of time.
- Types to represent intervals of time.
- Types to represent ranges over intervals of time.
- Types to represent time zones (used by SysTime).
- A platform-independent, high precision stopwatch type: StopWatch
- Benchmarking functions.
- Various helper functions.
auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtendedString(); auto restoredTime = SysTime.fromISOExtendedString(timeString);Various functions take a string (or strings) to represent a unit of time (e.g. convert!("days", "hours")(numDays)). The valid strings to use with such functions are "years", "months", "weeks", "days", "hours", "minutes", "seconds", "msecs" (milliseconds), "usecs" (microseconds), "hnsecs" (hecto-nanoseconds - i.e. 100 ns) or some subset thereof. There are a few functions in core.time which take "nsecs", but because nothing in std.datetime has precision greater than hnsecs, and very little in core.time does, no functions in std.datetime accept "nsecs". Note:
core.time is publicly imported by std.datetime, so if you're using std.datetime, you don't need to import core.time. Also, DateTimeException is an alias for core.time's TimeException, so you don't need to worry about core.time functions and std.datetime functions throwing different exception types (except in the rare case that they throw something other than TimeException or DateTimeException). See Also:
ISO 8601 Wikipedia entry on TZ Database List of Time Zones License:
Boost License 1.0. Authors:
Jonathan M Davis and Kato Shoichi Source:
std/datetime.d
- Represents the 12 months of the Gregorian year (January is 1).
- Represents the 7 days of the Gregorian week (Sunday is 0).
- 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.
- No, don't allow day overflow.
- Yes, allow day overflow.
- 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.
- Backward.
- Forward.
- Both backward and forward.
- 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, and if you want the first time point
in the range to match what the function generates, then you 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. By using
PopFirst.yes, you would be telling the function which returned the
range that you wanted popFront to be called so that front would then be
an Easter - the next one generated by the function (which if you were
iterating forward, would be the Easter following the original front,
while if you were 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 you
want - e.g. if you were iterating over every day starting at the beginning
of the interval).
- No, don't call popFront() before returning the range.
- Yes, call popFront() before returning the range.
- Used by StopWatch to indicate whether it should start immediately upon
construction.
- No, don't start the StopWatch when it is constructed.
- Yes, do start the StopWatch when it is constructed.
- 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. So, you can catch either and not worry 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.
Throws:
ErrnoException (on Posix) or Exception (on Windows) if it fails to get the time of day. - Returns the number of hnsecs since midnight, January 1st, 1 A.D. for the
current time.
Throws:
DateTimeException if it fails to get the 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.
Warning:
On some systems, the monotonic clock may stop counting when the computer goes to sleep or hibernates. So, the monotonic clock could be off if that occurs. This is known to happen on Mac OS X. It has not been tested whether it occurs on either Windows or Linux. Throws:
DateTimeException if it fails to get the 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.
Warning:
On some systems, the monotonic clock may stop counting when the computer goes to sleep or hibernates. So, the monotonic clock could be off if that occurs. This is known to happen on Mac OS X. It has not been tested whether it occurs on either Windows or on Linux. Throws:
DateTimeException if it fails to get the time.
- SysTime is the type used when you want to get the current time from the
system or if you're doing anything that involves time zones. Unlike
DateTime, the time zone is an integral part of SysTime (though if
all you care about is local time, you can pretty much ignore time zones, 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.
Basically, if you care about calendar-based operations and don't
necessarily care about time zones, then DateTime would be the type to
use. However, if what you care about is the system time, then SysTime
would be the type to use.
Clock.currTime will return the current time as a SysTime. If you
want to convert a SysTime to a Date or DateTime, simply cast
it. And if you ever want to convert a Date or DateTime to a
SysTime, use SysTime's constructor, and you can 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). So, if
you don't want to risk any conversion errors, keep your times as
SysTimes. Aside from DST though, there shouldn't be any conversion
problems.
If you care about using time zones other than local time or UTC, you can use
PosixTimeZone on Posix systems (or on Windows, if you provide the TZ
Database files), and you can use WindowsTimeZone on Windows systems.
The time in SysTime is kept internally in hnsecs from midnight,
January 1st, 1 A.D. UTC. So, you never get conversion errors 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, look at the documentation for
TimeZone, PosixTimeZone, and WindowsTimeZone.
SysTime's range is from approximately 29,000 B.C. to approximately
29,000 A.D.
- nothrow this(in DateTime dateTime, immutable TimeZone tz = null);
- Parameters:
DateTime dateTime The DateTime to use to set this SysTime's internal std time. As DateTime has no concept of time zone, tz is used as its time zone. 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. - nothrow this(in DateTime dateTime, in FracSec fsec, immutable TimeZone tz = null);
- Parameters:
DateTime dateTime The DateTime to use to set this SysTime's internal std time. As DateTime has no concept of time zone, tz is used as its time zone. FracSec fsec 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. - nothrow this(in Date date, immutable TimeZone tz = null);
- Parameters:
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. - pure nothrow this(long stdTime, immutable TimeZone tz = null);
- Note:
Whereas the other constructors take in the given date/time, assume that it's in the given time zone, and convert it to hnsecs in UTC since midnight, January 1st, 1 A.D. UTC - i.e. std time - this constructor takes a std time, which is specifically already in UTC, so no conversion takes place. Of course, the various getter properties and functions will use the given time zone's conversion function to convert the results to that time zone, but no conversion of the arguments to this constructor takes place. Parameters: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. - Parameters:
SysTime rhs The SysTime to assign to this one. - Parameters:
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.
Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 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.
Parameters:
Throws:int year The year to set this SysTime's year to.
DateTimeException if the new year is not a leap year and the resulting date would be on February 29th. Examples: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.
Throws:
DateTimeException if isAD is true. Examples: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.
Parameters:
Throws:int year The year B.C. to set this SysTime's year to.
DateTimeException if a non-positive value is given. Examples: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.
Examples:
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);
- Month of a Gregorian Year.
Parameters:
Throws:Month month The month to set this SysTime's month to.
DateTimeException if the given month is not a valid month. - Day of a Gregorian Month.
Examples:
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);
- Day of a Gregorian Month.
Parameters:
Throws:int day The day of the month to set this SysTime's day to.
DateTimeException if the given day is not a valid day of the current month. - Hours past midnight.
- Hours past midnight.
Parameters:
Throws:int hour The hours to set this SysTime's hour to.
DateTimeException if the given hour are not a valid hour of the day. - Minutes past the current hour.
- Minutes past the current hour.
Parameters:
Throws:minutes The minute to set this SysTime's minute to.
DateTimeException if the given minute are not a valid minute of an hour. - Seconds past the current minute.
- Seconds past the current minute.
Parameters:
Throws:int second The second to set this SysTime's second to.
DateTimeException if the given second are not a valid second of a minute. - Fractional seconds passed the second.
- Fractional seconds passed the second.
Parameters:
FracSec fracSec The fractional seconds to set this SysTimes's fractional seconds to. - 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.
Parameters:
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.
Parameters:
tz The TimeZone to set this SysTime's time zone to. - Returns whether DST is in effect for this SysTime.
- 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).
Parameters:
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. So, if you roll a SysTime 12 months, you
get the exact same SysTime. However, the days can still be affected
due to the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Parameters:
Examples:units The type of units to add ("years" or "months"). value The number of months or years to add to this SysTime. 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. So, for instance, if you roll a SysTime one
year's worth of days, then you get the exact same SysTime.
Accepted units are "days", "minutes", "hours",
"minutes", "seconds", "msecs", "usecs", and
"hnsecs".
Note that when rolling msecs, usecs or hnsecs, they all add up to a
second. So, for example, rolling 1000 msecs is exactly the same as
rolling 100,000 usecs.
Parameters:
Examples:units The units to add. 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
Parameters:SysTime + duration --> SysTime SysTime - duration --> SysTime SysTime + duration --> SysTime SysTime - duration --> SysTime 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
Parameters:SysTime + duration --> SysTime SysTime - duration --> SysTime SysTime + duration --> SysTime SysTime - duration --> SysTime 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 SysTime - SysTime --> duration - Returns the difference between the two SysTimes in months.
You can get the difference in years by subtracting the year property
of two SysTimes, and you can get the difference in days or weeks by
subtracting the SysTimes themselves and using the Duration
that results, but because you cannot convert between months and smaller
units without a specific date (which Durations don't have), you
cannot get the difference in months without doing some math using both
the year and month properties, so this is a convenience function for
getting the difference in months.
Note that the number of days in the months or how far into the month
either date is is irrelevant. It is the difference in the month property
combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Parameters:
Examples: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.
Examples:
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.
Parameters:
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.
Examples:
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.
Parameters:
Examples: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.
See Also:
ISO Week Date. - SysTime for the last day in the month that this Date is in.
The time portion of endOfMonth is always 23:59:59.9999999.
Examples:
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonth == SysTime(DateTime(1999, 1, 31, 23, 59, 59), 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.
Examples:
assert(SysTime(DateTime(1999, 1, 6, 0, 0, 0)).endOfMonthDay == 31); assert(SysTime(DateTime(1999, 2, 7, 19, 30, 0)).endOfMonthDay == 28); assert(SysTime(DateTime(2000, 2, 7, 5, 12, 27)).endOfMonthDay == 29); assert(SysTime(DateTime(2000, 6, 4, 12, 22, 9)).endOfMonthDay == 30);
- Whether the current year is a date in A.D.
Examples:
assert(SysTime(DateTime(1, 1, 1, 12, 7, 0)).isAD); assert(SysTime(DateTime(2010, 12, 31, 0, 0, 0)).isAD); assert(!SysTime(DateTime(0, 12, 31, 23, 59, 59)).isAD); assert(!SysTime(DateTime(-2010, 1, 1, 2, 2, 2)).isAD);
- 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.
Examples:
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.
Examples:
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toISOExtendedString() == "2010-07-04T07:06:12"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(24)).toISOExtendedString() == "1998-12-25T02:15:00.024"); assert(SysTime(DateTime(0, 1, 5, 23, 9, 59)).toISOExtendedString() == "0000-01-05T23:09:59"); assert(SysTime(DateTime(-4, 1, 5, 0, 0, 2), FracSec.from!"hnsecs"(520_920)).toISOExtendedString() == "-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.
Examples:
assert(SysTime(DateTime(2010, 7, 4, 7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12"); assert(SysTime(DateTime(1998, 12, 25, 2, 15, 0), 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. If you wish the returned SysTime to be a particular time
zone, then 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.
Parameters:
Throws:isoString A string formatted in the ISO format for dates and times. tz The time zone to convert the given time to (no conversion occurs if null).
DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. Examples: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(-480))); assert(SysTime.fromISOString("20100704T070612+8:00") == SysTime(DateTime(2010, 7, 3, 7, 6, 12), new SimpleTimeZone(480)));
- 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 toISOExtendedString
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. If you wish the returned SysTime to be a particular time
zone, then 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.
Parameters:
Throws:isoString A string formatted in the ISO Extended format for dates and times. tz The time zone to convert the given time to (no conversion occurs if null).
DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. Examples:assert(SysTime.fromISOExtendedString("2010-07-04T07:06:12") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOExtendedString("1998-12-25T02:15:00.007") == SysTime(DateTime(1998, 12, 25, 2, 15, 0), FracSec.from!"msecs"(7))); assert(SysTime.fromISOExtendedString("0000-01-05T23:09:59.00002") == SysTime(DateTime(0, 1, 5, 23, 9, 59), FracSec.from!"usecs"(20))); assert(SysTime.fromISOExtendedString("-0004-01-05T00:00:02") == SysTime(DateTime(-4, 1, 5, 0, 0, 2))); assert(SysTime.fromISOExtendedString(" 2010-07-04T07:06:12 ") == SysTime(DateTime(2010, 7, 4, 7, 6, 12))); assert(SysTime.fromISOExtendedString("2010-07-04T07:06:12Z") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), UTC())); assert(SysTime.fromISOExtendedString("2010-07-04T07:06:12-8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(-480))); assert(SysTime.fromISOExtendedString("2010-07-04T07:06:12+8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(480)));
- 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. If you wish the returned SysTime to be a particular time
zone, then 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.
Parameters:
Throws:simpleString A string formatted in the way that toSimpleString formats dates and times. tz The time zone to convert the given time to (no conversion occurs if null).
DateTimeException if the given string is not in the ISO format or if the resulting SysTime would not be valid. Examples: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(-480))); assert(SysTime.fromSimpleString("2010-Jul-04 07:06:12+8:00") == SysTime(DateTime(2010, 7, 4, 7, 6, 12), new SimpleTimeZone(480)));
- 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.
- pure this(int year, int month, int day);
- Throws:
DateTimeException if the resulting Date would not be valid. Parameters:int year Year of the Gregorian Calendar. Positive values are A.D. Non-positive values are B.C. with year 0 being the year prior to 1 A.D. int month Month of the year. int day Day of the month. - pure nothrow this(int day);
- Parameters:
int day The Xth day of the Gregorian Calendar that the constructed Date will be for. - Compares this Date with the given Date.
Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 this < rhs < 0 this == rhs 0 this > rhs > 0 - Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Examples:
assert(Date(1999, 7, 6).year == 1999); assert(Date(2010, 10, 4).year == 2010); assert(Date(-7, 4, 5).year == -7);
- Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive
are B.C.
Parameters:
Throws:int year The year to set this Date's year to.
DateTimeException if the new year is not a leap year and the resulting date would be on February 29th. - Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Throws:
DateTimeException if isAD is true. Examples: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.
Parameters:
Throws:int year The year B.C. to set this Date's year to.
DateTimeException if a non-positive value is given. Examples: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.
Examples:
assert(Date(1999, 7, 6).month == 7); assert(Date(2010, 10, 4).month == 10); assert(Date(-7, 4, 5).month == 4);
- Month of a Gregorian Year.
Parameters:
Throws:Month month The month to set this Date's month to.
DateTimeException if the given month is not a valid month or if the current day would not be valid in the given month. - Day of a Gregorian Month.
Examples:
assert(Date(1999, 7, 6).day == 6); assert(Date(2010, 10, 4).day == 4); assert(Date(-7, 4, 5).day == 5);
- Day of a Gregorian Month.
Parameters:
Throws:int day The day of the month to set this Date's day to.
DateTimeException if the given day is not a valid day of the current month. - Adds the given number of years or months to this Date. A negative
number will subtract.
Note that if day overflow is allowed, and the date with the adjusted
year/month overflows the number of days in the new month, then the month
will be incremented by one, and the day set to the number of days
overflowed. (e.g. if the day were 31 and the new month were June, then
the month would be incremented to July, and the new day would be 1). If
day overflow is not allowed, then the day will be set to the last valid
day in the month (e.g. June 31st would become June 30th).
Parameters:
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. So, if you roll a Date 12 months, you get
the exact same Date. However, the days can still be affected due to
the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Parameters:
Examples:units The type of units to add ("years" or "months"). 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. So, for instance, if you roll a Date one
year's worth of days, then you get the exact same Date.
The only accepted units are "days".
Parameters:
Examples: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
Parameters:Date + duration --> Date Date - duration --> Date Date + duration --> Date Date - duration --> Date 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
Parameters:Date + duration --> Date Date - duration --> Date Date + duration --> Date Date - duration --> Date 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 Date - Date --> duration - Returns the difference between the two Dates in months.
You can get the difference in years by subtracting the year property
of two Dates, and you can get the difference in days or weeks by
subtracting the Dates themselves and using the Duration that
results, but because you cannot convert between months and smaller units
without a specific date (which Durations don't have), you cannot
get the difference in months without doing some math using both the year
and month properties, so this is a convenience function for getting the
difference in months.
Note that the number of days in the months or how far into the month
either Date is is irrelevant. It is the difference in the month
property combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Parameters:
Examples: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.
Examples:
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.
Parameters:
Throws:int day The day of the year to set which day of the year this Date is on.
DateTimeException if the given day is an invalid day of the year. - The Xth day of the Gregorian Calendar that this Date is on.
Examples:
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.
Parameters:
Examples: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.
See Also:
ISO Week Date - Date for the last day in the month that this Date is in.
Examples:
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.
Examples:
assert(Date(1999, 1, 6).endOfMonthDay == 31); assert(Date(1999, 2, 7).endOfMonthDay == 28); assert(Date(2000, 2, 7).endOfMonthDay == 29); assert(Date(2000, 6, 4).endOfMonthDay == 30);
- Whether the current year is a date in A.D.
Examples:
assert(Date(1, 1, 1).isAD); assert(Date(2010, 12, 31).isAD); assert(!Date(0, 12, 31).isAD); assert(!Date(-2010, 1, 1).isAD);
- 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.
Examples:
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.
Examples:
assert(Date(2010, 7, 4).toISOExtendedString() == "2010-07-04"); assert(Date(1998, 12, 25).toISOExtendedString() == "1998-12-25"); assert(Date(0, 1, 5).toISOExtendedString() == "0000-01-05"); assert(Date(-4, 1, 5).toISOExtendedString() == "-0004-01-05");
- Converts this Date to a string with the format YYYY-Mon-DD.
Examples:
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.
Parameters:
Throws:isoString A string formatted in the ISO format for dates.
DateTimeException if the given string is not in the ISO format or if the resulting Date would not be valid. Examples: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.
Parameters:
Throws:isoExtString A string formatted in the ISO Extended format for dates.
DateTimeException if the given string is not in the ISO Extended format or if the resulting Date would not be valid. Examples:assert(Date.fromISOExtendedString("2010-07-04") == Date(2010, 7, 4)); assert(Date.fromISOExtendedString("1998-12-25") == Date(1998, 12, 25)); assert(Date.fromISOExtendedString("0000-01-05") == Date(0, 1, 5)); assert(Date.fromISOExtendedString("-0004-01-05") == Date(-4, 1, 5)); assert(Date.fromISOExtendedString(" 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.
Parameters:
Throws:simpleString A string formatted in the way that toSimpleString formats dates.
DateTimeException if the given string is not in the correct format or if the resulting Date would not be valid. Examples: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.
- pure this(int hour, int minute, int second = 0);
- Parameters:
Throws:int hour Hour of the day [0 - 24). int minute Minute of the hour [0 - 60). int second Second of the minute [0 - 60).
DateTimeException if the resulting TimeOfDay would be not be valid. - Compares this TimeOfDay with the given TimeOfDay.
Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 this < rhs < 0 this == rhs 0 this > rhs > 0 - Hours passed midnight.
- Hours passed midnight.
Parameters:
Throws:int hour The hour of the day to set this TimeOfDay's hour to.
DateTimeException if the given hour would result in an invalid TimeOfDay. - Minutes passed the hour.
- Minutes passed the hour.
Parameters:
Throws:int minute The minute to set this TimeOfDay's minute to.
DateTimeException if the given minute would result in an invalid TimeOfDay. - Seconds passed the minute.
- Seconds passed the minute.
Parameters:
Throws:int second The second to set this TimeOfDay's second to.
DateTimeException if the given second would result in an invalid TimeOfDay. - 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. So, for instance, if you roll a TimeOfDay
one hours's worth of minutes, then you get the exact same
TimeOfDay.
Accepted units are "hours", "minutes", and "seconds".
Parameters:
Examples:units The units to add. 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
Parameters:TimeOfDay + duration --> TimeOfDay TimeOfDay - duration --> TimeOfDay TimeOfDay + duration --> TimeOfDay TimeOfDay - duration --> TimeOfDay 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
Parameters:TimeOfDay + duration --> TimeOfDay TimeOfDay - duration --> TimeOfDay TimeOfDay + duration --> TimeOfDay TimeOfDay - duration --> TimeOfDay 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
Parameters:TimeOfDay - TimeOfDay --> duration TimeOfDay - TimeOfDay --> duration rhs The TimeOfDay to subtract from this one. - Converts this TimeOfDay to a string with the format HHMMSS.
Examples:
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.
Examples:
assert(TimeOfDay(0, 0, 0).toISOExtendedString() == "000000"); assert(TimeOfDay(12, 30, 33).toISOExtendedString() == "123033");
- Converts this TimeOfDay to a string.
- Creates a TimeOfDay from a string with the format HHMMSS.
Whitespace is stripped from the given string.
Parameters:
Throws:isoString A string formatted in the ISO format for times.
DateTimeException if the given string is not in the ISO format or if the resulting TimeOfDay would not be valid. Examples: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.
Parameters:
Throws:isoString A string formatted in the ISO Extended format for times.
DateTimeException if the given string is not in the ISO Extended format or if the resulting TimeOfDay would not be valid. Examples:assert(TimeOfDay.fromISOExtendedString("00:00:00") == TimeOfDay(0, 0, 0)); assert(TimeOfDay.fromISOExtendedString("12:30:33") == TimeOfDay(12, 30, 33)); assert(TimeOfDay.fromISOExtendedString(" 12:30:33 ") == TimeOfDay(12, 30, 33));
- Returns midnight.
- Returns one second short of midnight.
- Combines the Date and TimeOfDay structs to give you an object
which holds both the date and the time. It is optimized for calendar-based
operations and has no concept of time zone. If you want an object which is
optimized for time operations based on the system time, then use
SysTime. SysTime has a concept of time zone and has much higher
precision (hnsecs). DateTime is intended primarily for calendar-based
uses rather than precise time operations.
- pure nothrow this(in Date date, in TimeOfDay tod = (TimeOfDay).init);
- Parameters:
Date date The date portion of DateTime. TimeOfDay tod The time portion of DateTime. - pure this(int year, int month, int day, int hour = 0, int minute = 0, int second = 0);
- Parameters:
int year The year portion of the date. int month The month portion of the date. int day The day portion of the date. int hour The hour portion of the time; int minute The minute portion of the time; int second The second portion of the time; - Compares this DateTime with the given DateTime..
Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 this < rhs < 0 this == rhs 0 this > rhs > 0 - The date portion of DateTime.
- The date portion of DateTime.
Parameters:
Date date The Date to set this DateTime's date portion to. - The time portion of DateTime.
- The time portion of DateTime.
Parameters:
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.
Parameters:
Throws:int year The year to set this DateTime's year to.
DateTimeException if the new year is not a leap year and if the resulting date would be on February 29th. Examples: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.
Throws:
DateTimeException if isAD is true. Examples: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.
Parameters:
Throws:int year The year B.C. to set this DateTime's year to.
DateTimeException if a non-positive value is given. Examples: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.
Examples:
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);
- Month of a Gregorian Year.
Parameters:
Throws:Month month The month to set this DateTime's month to.
DateTimeException if the given month is not a valid month. - Day of a Gregorian Month.
Examples:
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);
- Day of a Gregorian Month.
Parameters:
Throws:int day The day of the month to set this DateTime's day to.
DateTimeException if the given day is not a valid day of the current month. - Hours passed midnight.
- Hours passed midnight.
Parameters:
Throws:int hour The hour of the day to set this DateTime's hour to.
DateTimeException if the given hour would result in an invalid DateTime. - Minutes passed the hour.
- Minutes passed the hour.
Parameters:
Throws:int minute The minute to set this DateTime's minute to.
DateTimeException if the given minute would result in an invalid DateTime. - Seconds passed the minute.
- Seconds passed the minute.
Parameters:
Throws:int second The second to set this DateTime's second to.
DateTimeException if the given seconds would result in an invalid DateTime. - Adds the given number of years or months to this DateTime. A
negative number will subtract.
Note that if day overflow is allowed, and the date with the adjusted
year/month overflows the number of days in the new month, then the month
will be incremented by one, and the day set to the number of days
overflowed. (e.g. if the day were 31 and the new month were June, then
the month would be incremented to July, and the new day would be 1). If
day overflow is not allowed, then the day will be set to the last valid
day in the month (e.g. June 31st would become June 30th).
Parameters:
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. So, if you roll a DateTime 12 months, you
get the exact same DateTime. However, the days can still be
affected due to the differing number of days in each month.
Because there are no units larger than years, there is no difference
between adding and rolling years.
Parameters:
Examples:units The type of units to add ("years" or "months"). value The number of months or years to add to this DateTime. 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. So, for instance, if you roll a DateTime one
year's worth of days, then you get the exact same DateTime.
Accepted units are "days", "minutes", "hours",
"minutes", and "seconds".
Parameters:
Examples: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
Parameters:DateTime + duration --> DateTime DateTime - duration --> DateTime DateTime + duration --> DateTime DateTime - duration --> DateTime 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
Parameters:DateTime + duration --> DateTime DateTime - duration --> DateTime DateTime + duration --> DateTime DateTime - duration --> DateTime 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 DateTime - DateTime --> duration - Returns the difference between the two DateTimes in months.
You can get the difference in years by subtracting the year property
of two DateTimes, and you can get the difference in days or weeks
by subtracting the DateTimes themselves and using the Duration that
results, but because you cannot convert between months and smaller units
without a specific date (which Durations don't have), you cannot
get the difference in months without doing some math using both the year
and month properties, so this is a convenience function for getting the
difference in months.
Note that the number of days in the months or how far into the month
either date is is irrelevant. It is the difference in the month property
combined with the difference in years * 12. So, for instance,
December 31st and January 1st are one month apart just as December 1st
and January 31st are one month apart.
Parameters:
Examples: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.
Examples:
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.
Parameters:
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.
Examples:
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.
Parameters:
Examples: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.
See Also:
ISO Week Date - DateTime for the last day in the month that this DateTime is
in. The time portion of endOfMonth is always 23:59:59.
Examples:
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonth == DateTime(Date(1999, 1, 31), TimeOfDay(23, 59, 59))); assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonth == DateTime(Date(1999, 2, 28), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonth == DateTime(Date(2000, 2, 29), TimeOfDay(23, 59, 59))); assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonth == DateTime(Date(2000, 6, 30), TimeOfDay(23, 59, 59)));
- The last day in the month that this DateTime is in.
Examples:
assert(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).endOfMonthDay == 31); assert(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).endOfMonthDay == 28); assert(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).endOfMonthDay == 29); assert(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).endOfMonthDay == 30);
- Whether the current year is a date in A.D.
Examples:
assert(DateTime(Date(1, 1, 1), TimeOfDay(12, 7, 0)).isAD); assert(DateTime(Date(2010, 12, 31), TimeOfDay(0, 0, 0)).isAD); assert(!DateTime(Date(0, 12, 31), TimeOfDay(23, 59, 59)).isAD); assert(!DateTime(Date(-2010, 1, 1), TimeOfDay(2, 2, 2)).isAD);
- 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.
Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOString() == "20100704T070612"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOString() == "19981225T021500"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOString() == "00000105T230959"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOString() == "-00040105T000002");
- Converts this DateTime to a string with the format
YYYY-MM-DDTHH:MM:SS.
Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtendedString() == "2010-07-04T07:06:12"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtendedString() == "1998-12-25T02:15:00"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtendedString() == "0000-01-05T23:09:59"); assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtendedString() == "-0004-01-05T00:00:02");
- Converts this DateTime to a string with the format
YYYY-Mon-DD HH:MM:SS.
Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() == "2010-Jul-04 07:06:12"); assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() == "1998-Dec-25 02:15:00"); assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() == "0000-Jan-05 23:09:59"); assert(DateTime(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.
Parameters:
Throws:isoString A string formatted in the ISO format for dates and times.
DateTimeException if the given string is not in the ISO format or if the resulting DateTime would not be valid. Examples: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.
Parameters:
Throws:isoString A string formatted in the ISO Extended format for dates and times.
DateTimeException if the given string is not in the ISO Extended format or if the resulting DateTime would not be valid. Examples:assert(DateTime.fromISOExtendedString("2010-07-04T07:06:12") == DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12))); assert(DateTime.fromISOExtendedString("1998-12-25T02:15:00") == DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0))); assert(DateTime.fromISOExtendedString("0000-01-05T23:09:59") == DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59))); assert(DateTime.fromISOExtendedString("-0004-01-05T00:00:02") == DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2))); assert(DateTime.fromISOExtendedString(" 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.
Parameters:
Throws:simpleString A string formatted in the way that toSimpleString formats dates and times.
DateTimeException if the given string is not in the correct format or if the resulting DateTime would not be valid. Examples: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.
A range can be obtained from an Interval, allowing you to iterate over that interval, with the exact time points which are iterated over depending on the function which generates the range.[January 5th, 2010 - March 10th, 2010) [05:00:30 - 12:00:00) [1982-01-04T08:59:00 - 2010-07-04T12:00:00) [January 5th, 2010 - March 10th, 2010) [05:00:30 - 12:00:00) [1982-01-04T08:59:00 - 2010-07-04T12:00:00) - Parameters:
Throws:begin The time point which begins the interval. end The time point which ends (but is not included in) the interval.
DateTimeException if end is before begin. Examples:Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1));
- Parameters:
Throws:begin The time point which begins the interval. duration The duration from the starting point to the end point.
DateTimeException if the resulting end is before begin. Examples:assert(Interval!Date(Date(1996, 1, 2), Dur.years(3)) == Interval!Date(Date(1996, 1, 2), Date(1999, 1, 2)));
- Parameters:
Interval rhs The Interval to assign to this one. - Parameters:
Interval rhs The Interval to assign to this one. - The starting point of the interval. It is included in the interval.
Examples:
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.
Parameters:
Throws:TP timePoint The time point to set begin to.
DateTimeException if the resulting interval would be invalid. - The end point of the interval. It is excluded from the interval.
Examples:
assert(Interval!Date(Date(1996, 1, 2), Date(2012, 3, 1)).end == Date(2012, 3, 1));
- The end point of the interval. It is excluded from the interval.
Parameters:
Throws:TP timePoint The time point to set end to.
DateTimeException if the resulting interval would be invalid. - Returns the duration between begin and end.
Examples:
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.
Examples:
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.
Parameters:
Throws:TP timePoint The time point to check for inclusion in this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to check for inclusion in this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to check for inclusion in this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to check for inclusion in this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:TP timePoint The time point to check whether this interval is before it.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to check for against this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to check for against this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to check for against this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:TP timePoint The time point to check whether this interval is after it.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to check against this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to check against this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to check against this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to check for intersection with this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to check for intersection with this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to check for intersection with this interval.
DateTimeException if this interval is empty. Examples: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
Parameters:
Throws:Interval interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect or if either interval is empty. Examples: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
Parameters:
Throws:PosInfInterval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect or if this interval is empty. Examples: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
Parameters:
Throws:NegInfInterval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect or if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to check whether its adjecent to this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to check whether its adjecent to this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to check whether its adjecent to this interval.
DateTimeException if this interval is empty. Examples: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
Parameters:
Throws:Interval interval The interval to merge with this interval.
DateTimeException if the two intervals do not intersect and are not adjacent or if either interval is empty. Examples: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
Parameters:
Throws:PosInfInterval!(TP) interval The interval to merge with this interval.
DateTimeException if the two intervals do not intersect and are not adjacent or if this interval is empty. Examples: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
Parameters:
Throws:NegInfInterval!(TP) interval The interval to merge with this interval.
DateTimeException if the two intervals do not intersect and are not adjacent or if this interval is empty. Examples: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.
Parameters:
Throws:Interval interval The interval to create a span together with this interval.
DateTimeException if either interval is empty. Examples: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.
Parameters:
Throws:PosInfInterval!(TP) interval The interval to create a span together with this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:NegInfInterval!(TP) interval The interval to create a span together with this interval.
DateTimeException if this interval is empty. Examples: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.
Parameters:
Throws:duration The duration to shift the interval by.
DateTimeException this interval is empty or if the resulting interval would be invalid. Examples: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 duration
(a positive duration shifts the interval forward; a negative duration
shifts it backward). Effectively, it does begin += duration and
end += duration.
Parameters:
Throws:D duration The duration to shift the interval by.
DateTimeException this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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)));
- 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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
Throws:duration The duration to expand the interval by. dir The direction in time to expand the interval.
DateTimeException this interval is empty or if the resulting interval would be invalid. Examples: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 does begin -= duration and/or end += duration. Whether
it expands forwards and/or backwards in time is determined by
dir.
Parameters:
Throws:D duration The duration to expand the interval by. Direction dir The direction in time to expand the interval.
DateTimeException this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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," so you can easily search for them.
Parameters:
Throws: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.
DateTimeException if this interval is empty. Warning:
func must be logically pure. Ideally, func would be a function pointer to a pure function, but forcing func to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange, func must be a delegate. If func retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. So, if you want to avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. If func is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant if you're creating your own delegate. Examples: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," so you can easily search for them.
Parameters:
Throws: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.
DateTimeException if this interval is empty. Warning:
func must be logically pure. Ideally, func would be a function pointer to a pure function, but forcing func to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange, func must be a delegate. If func retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. So, if you want to avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. If func is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant if you're creating your own delegate. Examples: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.
- Parameters:
Examples:begin The time point which begins the interval. auto interval = PosInfInterval!Date(Date(1996, 1, 2));
- Parameters:
PosInfInterval rhs The PosInfInterval to assign to this one. - Parameters:
PosInfInterval rhs The PosInfInterval to assign to this one. - The starting point of the interval. It is included in the interval.
Examples:
assert(PosInfInterval!Date(Date(1996, 1, 2)).begin == Date(1996, 1, 2));
- The starting point of the interval. It is included in the interval.
Parameters:
TP timePoint The time point to set begin to. - Whether the interval's length is 0. Always returns false.
Examples:
assert(!PosInfInterval!Date(Date(1996, 1, 2)).empty);
- Whether the given time point is within this interval.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for inclusion in this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for against this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check against this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for intersection with this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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
Parameters:
Throws:Interval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect or if the given interval is empty. Examples: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
Parameters:
Examples: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
Parameters:
Throws:NegInfInterval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect. Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check whether its adjecent to this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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
Parameters:
Throws:Interval!(TP) interval The interval to merge with this interval.
DateTimeException if the two intervals do not intersect and are not adjacent or if the given interval is empty. Note:
There is no overload for merge which takes a NegInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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
Parameters:
Note:PosInfInterval interval The interval to merge with this interval.
There is no overload for merge which takes a NegInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to create a span together with this interval.
DateTimeException if the given interval is empty. Note:
There is no overload for span which takes a NegInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Note:PosInfInterval interval The interval to create a span together with this interval.
There is no overload for span which takes a NegInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Examples: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 duration (a positive duration shifts the interval forward; a
negative duration shifts it backward). Effectively, it does
begin += duration.
Parameters:
Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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.
Parameters:
Examples: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 backwards in time. Effectively, it does
begin -= duration.
Parameters:
Examples: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.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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)));
- Expands the interval forwards and/or backwards in time. Effectively,
it subtracts the given number of months/years from begin.
Parameters:
DateTimeException if this interval is empty or if the resulting interval would be invalid. Examples: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," so you can easily search for them.
Parameters:
Throws: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.
DateTimeException if this interval is empty. Warning:
func must be logically pure. Ideally, func would be a function pointer to a pure function, but forcing func to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange, func must be a delegate. If func retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. So, if you want to avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. If func is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant if you're creating your own delegate. Examples: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. You would
then iterate over it in reverse.
- Parameters:
Examples:begin The time point which begins the interval. auto interval = PosInfInterval!Date(Date(1996, 1, 2));
- Parameters:
NegInfInterval rhs The NegInfInterval to assign to this one. - Parameters:
NegInfInterval rhs The NegInfInterval to assign to this one. - The end point of the interval. It is excluded from the interval.
Examples:
assert(NegInfInterval!Date(Date(2012, 3, 1)).end == Date(2012, 3, 1));
- The end point of the interval. It is excluded from the interval.
Parameters:
TP timePoint The time point to set end to. - Whether the interval's length is 0. Always returns false.
Examples:
assert(!NegInfInterval!Date(Date(1996, 1, 2)).empty);
- Whether the given time point is within this interval.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for inclusion in this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for against this interval.
DateTimeException if the given interval is empty Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check against this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check for intersection with this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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
Parameters:
Throws:Interval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect or if the given interval is empty. Examples: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
Parameters:
Throws:PosInfInterval!(TP) interval The interval to intersect with this interval.
DateTimeException if the two intervals do not intersect. Examples: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
Parameters:
Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to check whether its adjecent to this interval.
DateTimeException if the given interval is empty. Examples: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.
Parameters:
Examples: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.
Parameters:
Examples: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
Parameters:
Throws:Interval!(TP) interval The interval to merge with this interval.
DateTimeException if the two intervals do not intersect and are not adjacent or if the given interval is empty. Note:
There is no overload for merge which takes a PosInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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
Parameters:
Note:NegInfInterval interval The interval to merge with this interval.
There is no overload for merge which takes a PosInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Throws:Interval!(TP) interval The interval to create a span together with this interval.
DateTimeException if the given interval is empty. Note:
There is no overload for span which takes a PosInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Note:NegInfInterval interval The interval to create a span together with this interval.
There is no overload for span which takes a PosInfInterval. This is because you can't have an interval which goes from negative infinity to positive infinity. Examples: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.
Parameters:
Examples: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 duration (a positive duration shifts the interval forward; a
negative duration shifts it backward). Effectively, it does
end += duration.
Parameters:
Examples: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.
Parameters:
DateTimeException if empty is true or if the resulting interval would be invalid. Examples: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)));
- 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.
Parameters:
DateTimeException if empty is true or if the resulting interval would be invalid. Examples: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.
Parameters:
Examples: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 in time. Effectively, it does
end += duration.
Parameters:
Examples: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.
Parameters:
DateTimeException if empty is true or if the resulting interval would be invalid. Examples: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)));
- Expands the interval forwards and/or backwards in time. Effectively,
it adds the given number of months/years to end.
Parameters:
DateTimeException if empty is true or if the resulting interval would be invalid. Examples: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," so you can easily search for them.
Parameters:
Throws: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.
DateTimeException if this interval is empty. Warning:
func must be logically pure. Ideally, func would be a function pointer to a pure function, but forcing func to be pure is far too restrictive to be useful, and in order to have the ease of use of having functions which generate functions to pass to fwdRange, func must be a delegate. If func retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. So, if you want to avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. If func is given the same time point with two different calls, it must return the same result both times. Of course, none of the functions in this module have this problem, so it's only relevant if you're creating your own delegate. Examples: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 you to iterate over successive time points which
are all the same day of the week. e.g. passing DayOfWeek.mon to
everyDayOfWeek would result in a delegate which could be used to
iterate over all of the Mondays in a range.
Parameters:
Examples: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 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 you to iterate over successive time points
which are in the same month but different years. For example, you could
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.
Parameters:
Examples:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. 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 you to iterate 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.
Parameters:
Examples:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. 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 you the same time points as
iterating forward would have (even assuming that the end of the range is a
time point which would be returned by the delegate when iterating forward
from begin).
Parameters:
Examples:dir The direction to iterate in. If passing the return value to fwdRange, use Direction.fwd. If passing it to bwdRange, use Direction.bwd. years The number of years to add to the time point passed to the delegate. months The number of months to add to the time point passed to the delegate. allowOverflow Whether the days should be allowed to overflow on begin and end, causing their month to increment. 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. So, for instance, if you
had an Interval!Date, and you wanted to iterate over all of the days in
that interval, you would 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, if you're iterating 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. If you're iterating 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.
- Parameters:
IntervalRange rhs The IntervalRange to assign to this one. - Whether this IntervalRange is empty.
- The first time point in the range.
Throws:
DateTimeException if the range is empty. - Pops front from the range, using func to generate the next
time point in the range. If the generated time point is beyond the edge
of the range, then front is set to that edge, and the range is then
empty. So, if iterating forwards, and the generated time point is
greater than the interval's end, then front is set to
end. If iterating backwards, and the generated time point is less
than the interval's begin, then front is set to begin.
Throws:
DateTimeException if the range is empty or if the generated time point is in the wrong direction (i.e. if you're iterating forward and the generated time point is before front, or if you're iterating backwards, and the generated time point is after front). - 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. So, for
instance, if you had a PosInfInterval!Date, and you wanted to iterate
over all of the days in that interval, you would 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,
you would 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.
- Parameters:
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.
Throws:
DateTimeException if the generated time point is less than front. - 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. So, for
instance, if you had a NegInfInterval!Date, and you wanted to iterate
over all of the days in that interval, you would 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,
you would 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 you get 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.
- Parameters:
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.
Throws:
DateTimeException if the generated time point is greater than front. - 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.
See Also:
Wikipedia entry on TZ Database List of Time Zones - 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.
Parameters:
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.
Parameters:
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).
Parameters:
long adjTime The time in this time zone that needs to be adjusted to UTC time. - Returns a TimeZone with the give name per the TZ Database.
This returns a PosixTimeZone on Posix systems and a
WindowsTimeZone on Windows systems. If you want a
PosixTimeZone on Windows, then 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. So, this function allows you to use
the same time zone names on both Windows and Posix systems.
See Also:
Wikipedia entry on TZ Database List of Time Zones Windows <-> TZ Database Name Conversion Table Parameters:
Throws:string name The TZ Database name of the time zone that you're looking for.
DateTimeException if the given time zone could not be found. Examples:auto tz = TimeZone.getTimeZone("America/Los_Angeles");
- Returns a list of the names of the time zones installed on the system.
You can provide a sub-name to narrow down the list of time zones (which
will likely be in the thousands if you get them all). For example,
if you pass in "America" as the sub-name, then only the time zones which
begin with "America" will be returned.
On Windows, this function will convert the Windows time zone names to
the corresponding TZ Database names with
windowsTZNameToTZDatabaseName. If you want the actual Windows time
zone names, use WindowsTimeZone.getInstalledTZNames directly.
Parameters:
Throws:string subName The first part of the time zones that you want.
FileException on Posix systems if it fails to read from disk. DateTimeException on Windows systems if it fails to read the registry.
- 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.
- The name of the time zone per the TZ Database. This is the name used to
get a TimeZone by name with TimeZone.getTimeZone.
Note that this always returns the empty string. This is because time
zones cannot be uniquely identified by the attributes given by the
OS (such as the stdName and dstName), and neither Posix
systems nor Windows systems provide an easy way to get the TZ
Database name of the local time zone.
See Also:
Wikipedia entry on TZ Database List of Time Zones - 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.
Parameters:
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.
Parameters:
See Also:long stdTime The UTC time that needs to be adjusted to this time zone's time.
TimeZone.utcToTZ - Returns std time using the standard C function calls on Posix systems
and the standard Windows system calls on Windows systems to adjust the
time to UTC from the appropriate time zone.
See Also:
TimeZone.tzToUTC Parameters:long adjTime The time in this time zone that needs to be adjusted to UTC time.
- 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.
Parameters:
See Also:long stdTime The UTC time that needs to be adjusted to this time zone's time.
TimeZone.utcToTZ - Returns the given hnsecs without changing them at all.
See Also:
TimeZone.tzToUTC Parameters:long adjTime The time in this time zone that needs to be adjusted to UTC time.
- 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, fromISOExtendedString, 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.
Parameters:
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).
Parameters:
long adjTime The time in this time zone that needs to be adjusted to UTC time. - immutable this(int utcOffset, string stdName = "");
- Parameters:
int 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. You can, however, use
PosixTimeZone (which reads its information from the TZ Database files
on disk) on Windows if you provide the TZ Database files
( Repository with the TZ Database files (tzdata) )
yourself and tell PosixTimeZone.getTimeZone where the directory holding
them is.
TZ Database files hold DST transitions for a large interval of the time
covered by time_t. So, barring errors in the information in the TZ
Database files, it will use the correct DST rules for any date. Windows, on
the other hand, maintains only the current DST rules, so historical dates
will use the current DST rules (and therefore potentially be incorrect). So,
if you want the DST rules that you use to be more accurate, or if you're
looking for your program to act consistently on both Posix and Windows
systems, then, as mentioned above, you'll need to include the TZ Database
files with your program and give PosixTimeZone.getTimeZone the
directory on disk where they are located.
To get a PosixTimeZone, either call PosixTimeZone.getTimeZone
(which will allow you to specify the location the time zone files) or call
TimeZone.getTimeZone (which will give you a PosixTimeZone on Posix
systems and a WindowsTimeZone on Windows systems).
Note:
Unless your system's local time zone deals with leap seconds (which is highly unlikely), then only way that you will get a time zone which takes leap seconds into account is if you use PosixTimeZone with a time zone whose name starts with "right/". Those time zone files do include leap seconds, and PosixTimeZone will take them into account (though posix systems which use a "right/" time zone as their local time zone will not take leap seconds into account even though they're in the file). See Also:
Wikipedia entry on TZ Database List of 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.
Parameters:
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.
Parameters:
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).
Parameters:
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.
See Also:
Wikipedia entry on TZ Database List of Time Zones Parameters:
Throws:string name The TZ Database name of the time zone that you're looking for. string tzDatabaseDir The directory where the TZ Database files are located. Because these files are not located on Windows systems, you will need to provide them yourself and give their location here if you wish to use PosixTimeZones.
DateTimeException if the given time zone could not be found or FileException if the TZ Database file could not be opened. Examples: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.
You can provide a sub-name to narrow down the list of time zones (which
will likely be in the thousands if you get them all). For example,
if you pass in "America" as the sub-name, then only the time zones which
begin with "America" will be returned.
Parameters:
Throws:string subName The first part of the time zones that you want.
FileException if it fails to read from disk.
- This class is Windows-Only.
Represents a time zone from the Windows registry. Unfortunately, Windows
does not use the TZ Database. You can, however, use PosixTimeZone
(which reads its information from the TZ Database files on disk) on
Windows if you provide the TZ Database files
( Repository with the TZ Database files (tzdata) )
yourself and tell PosixTimeZone.getTimeZone where the directory
holding them is.
TZ Database files hold DST transitions for a large interval of the time
covered by time_t. So, barring errors in the information in the TZ
Database files, it will use the correct DST rules for any date. Windows,
on the other hand, maintains only the current DST rules, so historical
dates will use the current DST rules (and therefore potentially be
incorrect). So, if you want the DST rules that you use to be more
accurate, or if you're looking for your program to act consistently on
both Posix and Windows systems, then, as mentioned above, you'll need to
include the TZ Database files with your program and give
PosixTimeZone.getTimeZone the directory on disk where they are
located.
However, if all you care about is whether current times use the correct
DST rules, or if you don't care whether the DST rules are historically
accurate, then you can just use WindowsTimeZone on Windows.
WindowsTimeZone does not exist on Posix systems.
To get a WindowsTimeZone, either call
WindowsTimeZone.getTimeZone or call TimeZone.getTimeZone
(which will give you 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.
Parameters:
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.
Parameters:
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).
Parameters:
long adjTime The time in this time zone that needs to be adjusted to UTC time. - Returns a TimeZone with the given name per the Windows time
zone names. The time zone information is fetched from the Windows
registry.
See Also:
Wikipedia entry on TZ Database List of Time Zones Parameters:
Throws:string name The TZ Database name of the time zone that you're looking for.
DateTimeException if the given time zone could not be found. Examples:auto tz = TimeZone.getTimeZone("America/Los_Angeles");
- Returns a list of the names of the time zones installed on the system.
- This function is Posix-Only. Allows you to set the local time zone on Posix systems with the TZ database name by setting the TZ environment variable. Unfortunately, there is no way to do it on Windows using the TZ database name, so this function only exists on Posix systems.
- This function is Posix-Only. Clears the TZ environment variable.
- 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 that you started
with, in a few cases, you will 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.
See Also:
Windows <-> TZ Database Name Conversion Table Parameters:
Throws:string tzName The TZ Database name to convert.
DateTimeException if the given tzName cannot be converted. - Converts the given Windows time zone name to a corresponding TZ Database
name.
See Also:
Windows <-> TZ Database Name Conversion Table Parameters:
Throws:string tzName The TZ Database name to convert.
DateTimeException if the given tzName cannot be converted. - StopWatch's AutoStart flag
- 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 switching
between threads) can also affect StopWatch's accuracy.
Examples:
void foo() { StopWatch sw; static immutable N = 100; TickDuration[N] times; TickDuration last = TickDuration.from!"seconds"(0); foreach (i; 0..N) { sw.start(); // start/resume mesuring. foreach (Unused; 0..1000000) bar(); sw.stop(); // stop/pause mesuring. // Return value of peek() after having stopped are the always same. writeln((i+1)*1000000, " times done, lap time: ", sw.peek().msec, "[ms]"); times[i] = sw.peek() - last; last = sw.peek(); } real sum = 0; // When you want to know the number of seconds of the fact, // you can use properties of TickDuration. // (seconds, mseconds, useconds, hnsecs) foreach (e; times) sum += e.hnsecs; writeln("Average time: ", sum/N, " hnsecs"); }
- Benchmarks code for speed assessment and comparison.
Parameters:
Returns:fun aliases of callable objects (e.g. function names). Each should take no arguments. times The number of times each function is to be executed.
An array of n uints. Element at slot i contains the number of msecs spent in calling the ith function times times. Examples:int a; void f0() { } void f1() { auto b = a; } void f2() { auto b = to!(string)(a); } auto r = benchmark!(f0, f1, f2)(10_000_000);
- Return value of benchmark with two functions comparing.
- Evaluation value This returns the evaluation value of performance as the ratio that is compared between BaseFunc's time and TargetFunc's time. If performance is high, this returns a high value.
- The time required of the target function
- The time required of the base function
- Benchmark with two functions comparing.
Parameters:
Examples: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); }
- Scheduled for deprecation. This is only here to help transition code which uses std.date to using std.datetime. Returns a d_time for the given SysTime.
- Scheduled for deprecation. This is only here to help transition code which uses std.date to using std.datetime. Returns a SysTime for the given d_time.
- Returns the absolute value of a duration.
- 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.
Parameters:
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).
Parameters:
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).
Note:
While Windows systems require that time_t be non-negative (in spite of time_t being signed), this function still returns negative numbers on Windows, since it's more flexible to allow negative time_t for those who need it. So, if you're on Windows and are using the standard C functions or Win32 API functions which take a time_t, you may want to check whether the return value of stdTimeToUnixTime is non-negative. Parameters:long stdTime The std time to convert. - This function is Windows-Only.
Converts a SYSTEMTIME struct to a SysTime.
Parameters:
Throws:SYSTEMTIME* st The SYSTEMTIME struct to convert. TimeZone tz The time zone that the time in the SYSTEMTIME struct is assumed to be (if the SYSTEMTIME was supplied by a Windows system call, the SYSTEMTIME will either be in local time or UTC, depending on the call).
DateTimeException if the given SYSTEMTIME will not fit in a SysTime, which is highly unlikely to happen given that SysTime.max is in 29,228 A.D. and the maximum SYSTEMTIME is in 30,827 A.D. - This function is Windows-Only.
Converts a SysTime to a SYSTEMTIME struct.
The SYSTEMTIME which is returned will be set using the given
SysTime's time zone, so if you want the SYSTEMTIME to be in
UTC, set the SysTime's time zone to UTC.
Parameters:
Throws:SysTime sysTime The SysTime to convert.
DateTimeException if the given SysTime will not fit in a SYSTEMTIME. This will only happen if the SysTime's date is prior to 1601 A.D. - This function is Windows-Only.
Converts a FILETIME struct to a SysTime.
Parameters:
Throws:FILETIME* ft The FILETIME struct to convert. TimeZone tz The time zone that the SysTime will be in (FILETIMEs are in UTC).
DateTimeException if the given FILETIME will not fit in a SysTime or if the FILETIME cannot be converted to a SYSTEMTIME. - This function is Windows-Only.
Converts a SysTime to a FILETIME struct.
FILETIMEs are always in UTC.
Parameters:
Throws:SysTime sysTime The SysTime to convert.
DateTimeException if the given SysTime will not fit in a FILETIME. - Type representing the DOS file date/time format.
- Converts from DOS file date/time to SysTime.
Parameters:
Throws:DosFileTime dft The DOS file time to convert. TimeZone tz The time zone which the DOS file time is assumed to be in.
DateTimeException if the DosFileTime is invalid. - Converts from SysTime to DOS file date/time.
Parameters:
Throws:SysTime sysTime The SysTime to convert.
DateTimeException if the given SysTime cannot be converted to a DosFileTime. - 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.
Returns:
Throws:this < rhs < 0 this == rhs 0 this > rhs > 0 this < rhs < 0 this == rhs 0 this > rhs > 0
DateTimeException if either of the given strings is not a valid time unit string. - Compares two time unit strings at compile time. "years" are the largest
units and "hnsecs" are the smallest.
This template is used instead of cmpTimeUnits because exceptions
can't be thrown at compile time and cmpTimeUnits must enforce that
the strings it's given are valid time unit strings. This template uses a
template constraint instead.
Returns:
this < rhs < 0 this == rhs 0 this > rhs > 0 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).
Parameters:
Examples:units The units of time to validate. 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.
Parameters:
units The units of time to validate. year The year of the day to validate. month The month of the day to validate. day The day to validate. - Parameters:
Throws:units The units of time to validate. value The number to validate. file The file that the DateTimeException will list if thrown. line The line number that the DateTimeException will list if thrown.
DateTimeException if valid!units(value) is false. - Parameters:
Throws:units The units of time to validate. year The year of the day to validate. month The month of the day to validate. day The day to validate. file The file that the DateTimeException will list if thrown. line The line number that the DateTimeException will list if thrown.
DateTimeException if valid!"days"(year, month, day) is false. - Returns the number of months from the current months of the year to the
given month of the year. If they are the same, then the result is 0.
Parameters:
int currMonth The current month of the year. int month The month of the year to get the number of months to. - Returns the number of days from the current day of the week to the given
day of the week. If they are the same, then the result is 0.
Parameters:
DayOfWeek currDoW The current day of the week. DayOfWeek dow The day of the week to get the number of days to. - Function for starting to a stop watch time when the function is called
and stopping it when its return value goes out of scope and is destroyed.
When the value that is returned by this function is destroyed,
func will run. func is a unary function that takes a
TickDuration.
Examples:
writeln("benchmark start!"); { auto mt = measureTime!((a){assert(a.seconds);}); doSomething(); } writeln("benchmark end!");