Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.datetime.date

CategoryFunctions
Main date typesDateDateTime
Other date typesMonthDayOfWeekTimeOfDay
Date checkingvalidvalidTimeUnitsyearIsLeapYearisTimePointenforceValid
Date conversiondaysToDayOfWeekmonthsToMonth
Time unitscmpTimeUnitstimeStrings
OtherAllowDayOverflowDateTimeException
License:
Boost License 1.0.
Authors:
Jonathan M Davis

Sourcestd/datetime/date.d

aliasDateTimeException = core.time.TimeException;
Exception type used by std.datetime. It's an alias tocore.time.TimeException. Either can be caught without concern about which module it came from.
enumMonth: ubyte;
Represents the 12 months of the Gregorian year (January is 1).
Examples:
writeln(Date(2018, 10, 1).month);// Month.octwriteln(DateTime(1, 1, 1).month);// Month.jan
jan
feb
mar
apr
may
jun
jul
aug
sep
oct
nov
dec
enumDayOfWeek: ubyte;
Represents the 7 days of the Gregorian week (Sunday is 0).
Examples:
writeln(Date(2018, 10, 1).dayOfWeek);// DayOfWeek.monwriteln(DateTime(5, 5, 5).dayOfWeek);// DayOfWeek.thu
sun
mon
tue
wed
thu
fri
sat
aliasAllowDayOverflow = std.typecons.Flag!"allowDayOverflow".Flag;
In some date calculations, adding months or years can cause the date to fall on a day of the month which is not valid (e.g. February 29th 2001 or June 31st 2000). If overflow is allowed (as is the default), then the month will be incremented accordingly (so, February 29th 2001 would become March 1st 2001, and June 31st 2000 would become July 1st 2000). If overflow is not allowed, then the day will be adjusted to the last valid day in that month (so, February 29th 2001 would become February 28th 2001 and June 31st 2000 would become June 30th 2000).
AllowDayOverflow only applies to calculations involving months or years.
If set toAllowDayOverflow.no, then day overflow is not allowed.
Otherwise, if set toAllowDayOverflow.yes, then day overflow is allowed.
immutable string[]timeStrings;
Array of the strings representing time units, starting with the smallest unit and going to the largest. It does not include"nsecs".
Includes"hnsecs" (hecto-nanoseconds (100 ns)),"usecs" (microseconds),"msecs" (milliseconds),"seconds","minutes","hours","days","weeks","months", and"years"
structDateTime;
Combines thestd.datetime.date.Date andstd.datetime.date.TimeOfDay structs to give an object which holds both the date and the time. It is optimized for calendar-based operations and has no concept of time zone. For an object which is optimized for time operations based on the system time, usestd.datetime.systime.SysTime.std.datetime.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.
Examples:
import core.time : days, seconds;auto dt =DateTime(2000, 6, 1, 10, 30, 0);writeln(dt.date);// Date(2000, 6, 1)writeln(dt.timeOfDay);// TimeOfDay(10, 30, 0)writeln(dt.dayOfYear);// 153writeln(dt.dayOfWeek);// DayOfWeek.thudt += 10.days + 100.seconds;writeln(dt);// DateTime(2000, 6, 11, 10, 31, 40)writeln(dt.toISOExtString());// "2000-06-11T10:31:40"writeln(dt.toISOString());// "20000611T103140"writeln(dt.toSimpleString());// "2000-Jun-11 10:31:40"writeln(DateTime.fromISOExtString("2018-01-01T12:00:00"));// DateTime(2018, 1, 1, 12, 0, 0)writeln(DateTime.fromISOString("20180101T120000"));// DateTime(2018, 1, 1, 12, 0, 0)writeln(DateTime.fromSimpleString("2018-Jan-01 12:00:00"));// DateTime(2018, 1, 1, 12, 0, 0)
pure nothrow @nogc @safe this(Datedate, TimeOfDaytod = TimeOfDay.init);
Parameters:
DatedateThe date portion ofDateTime.
TimeOfDaytodThe time portion ofDateTime.
pure @safe this(intyear, intmonth, intday, inthour = 0, intminute = 0, intsecond = 0);
Parameters:
intyearThe year portion of the date.
intmonthThe month portion of the date (January is 1).
intdayThe day portion of the date.
inthourThe hour portion of the time;
intminuteThe minute portion of the time;
intsecondThe second portion of the time;
pure nothrow @nogc @safe intopCmp(DateTimerhs) const;
Compares thisDateTime with the givenDateTime..
Returns:
this < rhs< 0
this == rhs0
this > rhs> 0
pure nothrow @nogc @property @safe Datedate() const;
The date portion ofDateTime.
pure nothrow @nogc @property @safe voiddate(Datedate);
The date portion ofDateTime.
Parameters:
DatedateThe Date to set thisDateTime's date portion to.
pure nothrow @nogc @property @safe TimeOfDaytimeOfDay() const;
The time portion ofDateTime.
pure nothrow @nogc @property @safe voidtimeOfDay(TimeOfDaytod);
The time portion ofDateTime.
Parameters:
TimeOfDaytodThestd.datetime.date.TimeOfDay to set thisDateTime's time portion to.
pure nothrow @nogc @property @safe shortyear() const;
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
pure @property @safe voidyear(intyear);
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Parameters:
intyearThe year to set thisDateTime's year to.
Throws:
std.datetime.date.DateTimeException if the new year is not a leap year and if the resulting date would be on February 29th.
Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).year);// 1999writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).year);// 2010writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).year);// -7
pure @property @safe shortyearBC() const;
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Examples:
writeln(DateTime(Date(0, 1, 1), TimeOfDay(12, 30, 33)).yearBC);// 1writeln(DateTime(Date(-1, 1, 1), TimeOfDay(10, 7, 2)).yearBC);// 2writeln(DateTime(Date(-100, 1, 1), TimeOfDay(4, 59, 0)).yearBC);// 101
pure @property @safe voidyearBC(intyear);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Parameters:
intyearThe year B.C. to set thisDateTime's year to.
Throws:
std.datetime.date.DateTimeException if a non-positive value is given.
Examples:
auto dt = DateTime(Date(2010, 1, 1), TimeOfDay(7, 30, 0));dt.yearBC = 1;writeln(dt);// DateTime(Date(0, 1, 1), TimeOfDay(7, 30, 0))dt.yearBC = 10;writeln(dt);// DateTime(Date(-9, 1, 1), TimeOfDay(7, 30, 0))
pure nothrow @nogc @property @safe Monthmonth() const;
Month of a Gregorian Year.
Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).month);// 7writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).month);// 10writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).month);// 4
pure @property @safe voidmonth(Monthmonth);
Month of a Gregorian Year.
Parameters:
MonthmonthThe month to set thisDateTime's month to.
Throws:
std.datetime.date.DateTimeException if the given month is not a valid month.
pure nothrow @nogc @property @safe ubyteday() const;
Day of a Gregorian Month.
Examples:
writeln(DateTime(Date(1999, 7, 6), TimeOfDay(9, 7, 5)).day);// 6writeln(DateTime(Date(2010, 10, 4), TimeOfDay(0, 0, 30)).day);// 4writeln(DateTime(Date(-7, 4, 5), TimeOfDay(7, 45, 2)).day);// 5
pure @property @safe voidday(intday);
Day of a Gregorian Month.
Parameters:
intdayThe day of the month to set thisDateTime's day to.
Throws:
std.datetime.date.DateTimeException if the given day is not a valid day of the current month.
pure nothrow @nogc @property @safe ubytehour() const;
Hours past midnight.
pure @property @safe voidhour(inthour);
Hours past midnight.
Parameters:
inthourThe hour of the day to set thisDateTime's hour to.
Throws:
std.datetime.date.DateTimeException if the given hour would result in an invalidDateTime.
pure nothrow @nogc @property @safe ubyteminute() const;
Minutes past the hour.
pure @property @safe voidminute(intminute);
Minutes past the hour.
Parameters:
intminuteThe minute to set thisDateTime's minute to.
Throws:
std.datetime.date.DateTimeException if the given minute would result in an invalidDateTime.
pure nothrow @nogc @property @safe ubytesecond() const;
Seconds past the minute.
pure @property @safe voidsecond(intsecond);
Seconds past the minute.
Parameters:
intsecondThe second to set thisDateTime's second to.
Throws:
std.datetime.date.DateTimeException if the given seconds would result in an invalidDateTime.
pure nothrow @nogc ref @safe DateTimeadd(string units)(longvalue, AllowDayOverflowallowOverflow = AllowDayOverflow.yes)
if (units == "years" || units == "months");
Adds the given number of years or months to thisDateTime, mutating it. 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:
unitsThe type of units to add ("years" or "months").
longvalueThe number of months or years to add to thisDateTime.
AllowDayOverflowallowOverflowWhether the days should be allowed to overflow, causing the month to increment.
Returns:
A reference to theDateTime (this).
Examples:
auto dt1 = DateTime(2010, 1, 1, 12, 30, 33);dt1.add!"months"(11);writeln(dt1);// DateTime(2010, 12, 1, 12, 30, 33)auto dt2 = DateTime(2010, 1, 1, 12, 30, 33);dt2.add!"months"(-11);writeln(dt2);// DateTime(2009, 2, 1, 12, 30, 33)auto dt3 = DateTime(2000, 2, 29, 12, 30, 33);dt3.add!"years"(1);writeln(dt3);// DateTime(2001, 3, 1, 12, 30, 33)auto dt4 = DateTime(2000, 2, 29, 12, 30, 33);dt4.add!"years"(1, AllowDayOverflow.no);writeln(dt4);// DateTime(2001, 2, 28, 12, 30, 33)
pure nothrow @nogc ref @safe DateTimeroll(string units)(longvalue, AllowDayOverflowallowOverflow = AllowDayOverflow.yes)
if (units == "years" || units == "months");
Adds the given number of years or months to thisDateTime, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. Rolling aDateTime 12 months gets the exact sameDateTime. 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:
unitsThe type of units to add ("years" or "months").
longvalueThe number of months or years to add to thisDateTime.
AllowDayOverflowallowOverflowWhether the days should be allowed to overflow, causing the month to increment.
Returns:
A reference to theDateTime (this).
Examples:
auto dt1 = DateTime(2010, 1, 1, 12, 33, 33);dt1.roll!"months"(1);writeln(dt1);// DateTime(2010, 2, 1, 12, 33, 33)auto dt2 = DateTime(2010, 1, 1, 12, 33, 33);dt2.roll!"months"(-1);writeln(dt2);// DateTime(2010, 12, 1, 12, 33, 33)auto dt3 = DateTime(1999, 1, 29, 12, 33, 33);dt3.roll!"months"(1);writeln(dt3);// DateTime(1999, 3, 1, 12, 33, 33)auto dt4 = DateTime(1999, 1, 29, 12, 33, 33);dt4.roll!"months"(1, AllowDayOverflow.no);writeln(dt4);// DateTime(1999, 2, 28, 12, 33, 33)auto dt5 = DateTime(2000, 2, 29, 12, 30, 33);dt5.roll!"years"(1);writeln(dt5);// DateTime(2001, 3, 1, 12, 30, 33)auto dt6 = DateTime(2000, 2, 29, 12, 30, 33);dt6.roll!"years"(1, AllowDayOverflow.no);writeln(dt6);// DateTime(2001, 2, 28, 12, 30, 33)
pure nothrow @nogc ref @safe DateTimeroll(string units)(longvalue)
if (units == "days");

pure nothrow @nogc ref @safe DateTimeroll(string units)(longvalue)
if (units == "hours" || units == "minutes" || units == "seconds");
Adds the given number of units to thisDateTime, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling aDateTime one year's worth of days gets the exact sameDateTime.
Accepted units are"days","minutes","hours","minutes", and"seconds".
Parameters:
unitsThe units to add.
longvalueThe number ofunits to add to thisDateTime.
Returns:
A reference to theDateTime (this).
Examples:
auto dt1 = DateTime(2010, 1, 1, 11, 23, 12);dt1.roll!"days"(1);writeln(dt1);// DateTime(2010, 1, 2, 11, 23, 12)dt1.roll!"days"(365);writeln(dt1);// DateTime(2010, 1, 26, 11, 23, 12)dt1.roll!"days"(-32);writeln(dt1);// DateTime(2010, 1, 25, 11, 23, 12)auto dt2 = DateTime(2010, 7, 4, 12, 0, 0);dt2.roll!"hours"(1);writeln(dt2);// DateTime(2010, 7, 4, 13, 0, 0)auto dt3 = DateTime(2010, 1, 1, 0, 0, 0);dt3.roll!"seconds"(-1);writeln(dt3);// DateTime(2010, 1, 1, 0, 0, 59)
pure nothrow @nogc @safe DateTimeopBinary(string op)(Durationduration) const
if (op == "+" || op == "-");

pure nothrow @nogc @safe DateTimeopBinaryRight(string op)(Durationduration) const
if (op == "+");
Gives the result of adding or subtracting acore.time.Duration from thisDateTime.
The legal types of arithmetic forDateTime using this operator are
DateTime+Duration-->DateTime
DateTime-Duration-->DateTime
Duration+DateTime-->DateTime
Parameters:
DurationdurationThecore.time.Duration to add to or subtract from thisDateTime.
Examples:
import core.time : hours, seconds;assert(DateTime(2015, 12, 31, 23, 59, 59) + seconds(1) ==       DateTime(2016, 1, 1, 0, 0, 0));assert(DateTime(2015, 12, 31, 23, 59, 59) + hours(1) ==       DateTime(2016, 1, 1, 0, 59, 59));assert(DateTime(2016, 1, 1, 0, 0, 0) - seconds(1) ==       DateTime(2015, 12, 31, 23, 59, 59));assert(DateTime(2016, 1, 1, 0, 59, 59) - hours(1) ==       DateTime(2015, 12, 31, 23, 59, 59));assert(DateTime(2015, 12, 31, 23, 59, 59) + hours(1) ==       hours(1) + DateTime(2015, 12, 31, 23, 59, 59));
pure nothrow @nogc ref @safe DateTimeopOpAssign(string op)(Durationduration)
if (op == "+" || op == "-");
Gives the result of adding or subtracting a duration from thisDateTime, as well as assigning the result to thisDateTime.
The legal types of arithmetic forDateTime using this operator are
DateTime+duration-->DateTime
DateTime-duration-->DateTime
Parameters:
DurationdurationThe duration to add to or subtract from thisDateTime.
pure nothrow @nogc @safe DurationopBinary(string op)(DateTimerhs) const
if (op == "-");
Gives the difference between twoDateTimes.
The legal types of arithmetic forDateTime using this operator are
DateTime-DateTime-->duration
pure nothrow @nogc @safe intdiffMonths(DateTimerhs) const;
Returns the difference between the twoDateTimes in months.
To get the difference in years, subtract the year property of twoDateTimes. To get the difference in days or weeks, subtract theDateTimes themselves and use thecore.time.Duration that results. Because converting between months and smaller units requires a specific date (whichcore.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months.
Note that the number of days in the months or how far into the month either date is is irrelevant. It is the difference in the month property combined with the difference in years * 12. So, for instance, December 31st and January 1st are one month apart just as December 1st and January 31st are one month apart.
Parameters:
DateTimerhsTheDateTime to subtract from this one.
Examples:
assert(DateTime(1999, 2, 1, 12, 2, 3).diffMonths(           DateTime(1999, 1, 31, 23, 59, 59)) == 1);assert(DateTime(1999, 1, 31, 0, 0, 0).diffMonths(           DateTime(1999, 2, 1, 12, 3, 42)) == -1);assert(DateTime(1999, 3, 1, 5, 30, 0).diffMonths(           DateTime(1999, 1, 1, 2, 4, 7)) == 2);assert(DateTime(1999, 1, 1, 7, 2, 4).diffMonths(           DateTime(1999, 3, 31, 0, 30, 58)) == -2);
pure nothrow @nogc @property @safe boolisLeapYear() const;
Whether thisDateTime is in a leap year.
pure nothrow @nogc @property @safe DayOfWeekdayOfWeek() const;
Day of the week thisDateTime is on.
pure nothrow @nogc @property @safe ushortdayOfYear() const;
Day of the year thisDateTime is on.
Examples:
writeln(DateTime(Date(1999, 1, 1), TimeOfDay(12, 22, 7)).dayOfYear);// 1writeln(DateTime(Date(1999, 12, 31), TimeOfDay(7, 2, 59)).dayOfYear);// 365writeln(DateTime(Date(2000, 12, 31), TimeOfDay(21, 20, 0)).dayOfYear);// 366
pure @property @safe voiddayOfYear(intday);
Day of the year.
Parameters:
intdayThe day of the year to set which day of the year thisDateTime is on.
pure nothrow @nogc @property @safe intdayOfGregorianCal() const;
The Xth day of the Gregorian Calendar that thisDateTime is on.
Examples:
writeln(DateTime(Date(1, 1, 1), TimeOfDay(0, 0, 0)).dayOfGregorianCal);// 1writeln(DateTime(Date(1, 12, 31), TimeOfDay(23, 59, 59)).dayOfGregorianCal);// 365writeln(DateTime(Date(2, 1, 1), TimeOfDay(2, 2, 2)).dayOfGregorianCal);// 366writeln(DateTime(Date(0, 12, 31), TimeOfDay(7, 7, 7)).dayOfGregorianCal);// 0writeln(DateTime(Date(0, 1, 1), TimeOfDay(19, 30, 0)).dayOfGregorianCal);// -365writeln(DateTime(Date(-1, 12, 31), TimeOfDay(4, 7, 0)).dayOfGregorianCal);// -366writeln(DateTime(Date(2000, 1, 1), TimeOfDay(9, 30, 20)).dayOfGregorianCal);// 730_120writeln(DateTime(Date(2010, 12, 31), TimeOfDay(15, 45, 50)).dayOfGregorianCal);// 734_137
pure nothrow @nogc @property @safe voiddayOfGregorianCal(intdays);
The Xth day of the Gregorian Calendar that thisDateTime is on. Setting this property does not affect the time portion ofDateTime.
Parameters:
intdaysThe day of the Gregorian Calendar to set thisDateTime to.
Examples:
auto dt = DateTime(Date.init, TimeOfDay(12, 0, 0));dt.dayOfGregorianCal = 1;writeln(dt);// DateTime(Date(1, 1, 1), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = 365;writeln(dt);// DateTime(Date(1, 12, 31), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = 366;writeln(dt);// DateTime(Date(2, 1, 1), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = 0;writeln(dt);// DateTime(Date(0, 12, 31), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = -365;writeln(dt);// DateTime(Date(-0, 1, 1), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = -366;writeln(dt);// DateTime(Date(-1, 12, 31), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = 730_120;writeln(dt);// DateTime(Date(2000, 1, 1), TimeOfDay(12, 0, 0))dt.dayOfGregorianCal = 734_137;writeln(dt);// DateTime(Date(2010, 12, 31), TimeOfDay(12, 0, 0))
pure nothrow @property @safe ubyteisoWeek() const;
The ISO 8601 week of the year that thisDateTime is in.
See Also:
pure nothrow @property @safe shortisoWeekYear() const;
The year of the ISO 8601 week calendar that thisDateTime is in.
See Also:
pure nothrow @property @safe DateTimeendOfMonth() const;
DateTime for the last day in the month that thisDateTime 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)));
pure nothrow @nogc @property @safe ubytedaysInMonth() const;
The last day in the month that thisDateTime is in.
Examples:
writeln(DateTime(Date(1999, 1, 6), TimeOfDay(0, 0, 0)).daysInMonth);// 31writeln(DateTime(Date(1999, 2, 7), TimeOfDay(19, 30, 0)).daysInMonth);// 28writeln(DateTime(Date(2000, 2, 7), TimeOfDay(5, 12, 27)).daysInMonth);// 29writeln(DateTime(Date(2000, 6, 4), TimeOfDay(12, 22, 9)).daysInMonth);// 30
pure nothrow @nogc @property @safe boolisAD() const;
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);
pure nothrow @nogc @property @safe longjulianDay() const;
TheJulian day for thisDateTime at the given time. For example, prior to noon, 1996-03-31 would be the Julian day number 2_450_173, so this function returns 2_450_173, while from noon onward, the julian day number would be 2_450_174, so this function returns 2_450_174.
pure nothrow @nogc @property @safe longmodJulianDay() const;
The modifiedJulian day for any time on this date (since, the modified Julian day changes at midnight).
pure nothrow @safe stringtoISOString() const;

voidtoISOString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDateTime to a string with the formatYYYYMMDDTHHMMSS. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
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");
pure nothrow @safe stringtoISOExtString() const;

voidtoISOExtString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDateTime to a string with the formatYYYY-MM-DDTHH:MM:SS. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toISOExtString() =="2010-07-04T07:06:12");assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toISOExtString() =="1998-12-25T02:15:00");assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toISOExtString() =="0000-01-05T23:09:59");assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toISOExtString() =="-0004-01-05T00:00:02");
pure nothrow @safe stringtoSimpleString() const;

voidtoSimpleString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDateTime to a string with the formatYYYY-Mon-DD HH:MM:SS. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
assert(DateTime(Date(2010, 7, 4), TimeOfDay(7, 6, 12)).toSimpleString() =="2010-Jul-04 07:06:12");assert(DateTime(Date(1998, 12, 25), TimeOfDay(2, 15, 0)).toSimpleString() =="1998-Dec-25 02:15:00");assert(DateTime(Date(0, 1, 5), TimeOfDay(23, 9, 59)).toSimpleString() =="0000-Jan-05 23:09:59");assert(DateTime(Date(-4, 1, 5), TimeOfDay(0, 0, 2)).toSimpleString() =="-0004-Jan-05 00:00:02");
pure nothrow @safe stringtoString() const;

voidtoString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDateTime to a string.
This function exists to make it easy to convert aDateTime to a string for code that does not care what the exact format is - just that it presents the information in a clear manner. It also makes it easy to simply convert aDateTime to a string when using functions such asto!string,format, orwriteln which use toString to convert user-defined types. So, it is unlikely that much code will call toString directly.
The format of the string is purposefully unspecified, and code that cares about the format of the string should usetoISOString,toISOExtString,toSimpleString, or some other custom formatting function that explicitly generates the format that the code needs. The reason is that the code is then clear about what format it's using, making it less error-prone to maintain the code and interact with other software that consumes the generated strings. It's for this same reason thatDateTime has nofromString function, whereas it does havefromISOString,fromISOExtString, andfromSimpleString.
The format returned by toString may or may not change in the future.
pure @safe DateTimefromISOString(S)(scope const SisoString)
if (isSomeString!S);
Creates aDateTime from a string with the format YYYYMMDDTHHMMSS. Whitespace is stripped from the given string.
Parameters:
SisoStringA string formatted in the ISO format for dates and times.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO format or if the resultingDateTime would not be valid.
pure @safe DateTimefromISOExtString(S)(scope const SisoExtString)
if (isSomeString!S);
Creates aDateTime from a string with the format YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.
Parameters:
SisoExtStringA string formatted in the ISO Extended format for dates and times.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO Extended format or if the resultingDateTime would not be valid.
pure @safe DateTimefromSimpleString(S)(scope const SsimpleString)
if (isSomeString!S);
Creates aDateTime from a string with the format YYYY-Mon-DD HH:MM:SS. Whitespace is stripped from the given string.
Parameters:
SsimpleStringA string formatted in the way that toSimpleString formats dates and times.
Throws:
std.datetime.date.DateTimeException if the given string is not in the correct format or if the resultingDateTime would not be valid.
static pure nothrow @nogc @property @safe DateTimemin();
Returns theDateTime farthest in the past which is representable byDateTime.
static pure nothrow @nogc @property @safe DateTimemax();
Returns theDateTime farthest in the future which is representable byDateTime.
structDate;
Represents a date in theProleptic 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 thatDate is optimized for calendar-based operations.
Date uses the Proleptic Gregorian Calendar, so it assumes the Gregorian leap year calculations for its entire length. As perISO 8601, it treats 1 B.C. as year 0, i.e. 1 B.C. is 0, 2 B.C. is -1, etc. UseyearBC to use B.C. as a positive integer with 1 B.C. being the year prior to 1 A.D.
Year 0 is a leap year.
Examples:
import core.time : days;auto d =Date(2000, 6, 1);writeln(d.dayOfYear);// 153writeln(d.dayOfWeek);// DayOfWeek.thud += 10.days;writeln(d);// Date(2000, 6, 11)writeln(d.toISOExtString());// "2000-06-11"writeln(d.toISOString());// "20000611"writeln(d.toSimpleString());// "2000-Jun-11"writeln(Date.fromISOExtString("2018-01-01"));// Date(2018, 1, 1)writeln(Date.fromISOString("20180101"));// Date(2018, 1, 1)writeln(Date.fromSimpleString("2018-Jan-01"));// Date(2018, 1, 1)
pure @safe this(intyear, intmonth, intday);
Throws:
std.datetime.date.DateTimeException if the resultingDate would not be valid.
Parameters:
intyearYear 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.
intmonthMonth of the year (January is 1).
intdayDay of the month.
pure nothrow @nogc @safe this(intday);
Parameters:
intdayThe Xth day of the Gregorian Calendar that the constructedDate will be for.
pure nothrow @nogc @safe intopCmp(Daterhs) const;
Compares thisDate with the givenDate.
Returns:
this < rhs< 0
this == rhs0
this > rhs> 0
pure nothrow @nogc @property @safe shortyear() const;
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Examples:
writeln(Date(1999, 7, 6).year);// 1999writeln(Date(2010, 10, 4).year);// 2010writeln(Date(-7, 4, 5).year);// -7
pure @property @safe voidyear(intyear);
Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Parameters:
intyearThe year to set this Date's year to.
Throws:
std.datetime.date.DateTimeException if the new year is not a leap year and the resulting date would be on February 29th.
Examples:
writeln(Date(1999, 7, 6).year);// 1999writeln(Date(2010, 10, 4).year);// 2010writeln(Date(-7, 4, 5).year);// -7
pure @property @safe ushortyearBC() const;
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Examples:
writeln(Date(0, 1, 1).yearBC);// 1writeln(Date(-1, 1, 1).yearBC);// 2writeln(Date(-100, 1, 1).yearBC);// 101
pure @property @safe voidyearBC(intyear);
Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.
Parameters:
intyearThe year B.C. to set thisDate's year to.
Throws:
std.datetime.date.DateTimeException if a non-positive value is given.
Examples:
auto date = Date(2010, 1, 1);date.yearBC = 1;writeln(date);// Date(0, 1, 1)date.yearBC = 10;writeln(date);// Date(-9, 1, 1)
pure nothrow @nogc @property @safe Monthmonth() const;
Month of a Gregorian Year.
Examples:
writeln(Date(1999, 7, 6).month);// 7writeln(Date(2010, 10, 4).month);// 10writeln(Date(-7, 4, 5).month);// 4
pure @property @safe voidmonth(Monthmonth);
Month of a Gregorian Year.
Parameters:
MonthmonthThe month to set thisDate's month to.
Throws:
std.datetime.date.DateTimeException if the given month is not a valid month or if the current day would not be valid in the given month.
pure nothrow @nogc @property @safe ubyteday() const;
Day of a Gregorian Month.
Examples:
writeln(Date(1999, 7, 6).day);// 6writeln(Date(2010, 10, 4).day);// 4writeln(Date(-7, 4, 5).day);// 5
pure @property @safe voidday(intday);
Day of a Gregorian Month.
Parameters:
intdayThe day of the month to set thisDate's day to.
Throws:
std.datetime.date.DateTimeException if the given day is not a valid day of the current month.
pure nothrow @nogc ref @safe Dateadd(string units)(longvalue, AllowDayOverflowallowOverflow = AllowDayOverflow.yes)
if (units == "years");
Adds the given number of years or months to thisDate, mutating it. 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:
unitsThe type of units to add ("years" or "months").
longvalueThe number of months or years to add to thisDate.
AllowDayOverflowallowOverflowWhether the day should be allowed to overflow, causing the month to increment.
Returns:
A reference to theDate (this).
Examples:
auto d1 = Date(2010, 1, 1);d1.add!"months"(11);writeln(d1);// Date(2010, 12, 1)auto d2 = Date(2010, 1, 1);d2.add!"months"(-11);writeln(d2);// Date(2009, 2, 1)auto d3 = Date(2000, 2, 29);d3.add!"years"(1);writeln(d3);// Date(2001, 3, 1)auto d4 = Date(2000, 2, 29);d4.add!"years"(1, AllowDayOverflow.no);writeln(d4);// Date(2001, 2, 28)
pure nothrow @nogc ref @safe Dateroll(string units)(longvalue, AllowDayOverflowallowOverflow = AllowDayOverflow.yes)
if (units == "years");
Adds the given number of years or months to thisDate, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. Rolling aDate 12 months gets the exact sameDate. 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:
unitsThe type of units to add ("years" or "months").
longvalueThe number of months or years to add to thisDate.
AllowDayOverflowallowOverflowWhether the day should be allowed to overflow, causing the month to increment.
Returns:
A reference to theDate (this).
Examples:
auto d1 = Date(2010, 1, 1);d1.roll!"months"(1);writeln(d1);// Date(2010, 2, 1)auto d2 = Date(2010, 1, 1);d2.roll!"months"(-1);writeln(d2);// Date(2010, 12, 1)auto d3 = Date(1999, 1, 29);d3.roll!"months"(1);writeln(d3);// Date(1999, 3, 1)auto d4 = Date(1999, 1, 29);d4.roll!"months"(1, AllowDayOverflow.no);writeln(d4);// Date(1999, 2, 28)auto d5 = Date(2000, 2, 29);d5.roll!"years"(1);writeln(d5);// Date(2001, 3, 1)auto d6 = Date(2000, 2, 29);d6.roll!"years"(1, AllowDayOverflow.no);writeln(d6);// Date(2001, 2, 28)
pure nothrow @nogc ref @safe Dateroll(string units)(longdays)
if (units == "days");
Adds the given number of units to thisDate, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling aDate one year's worth of days gets the exact sameDate.
The only accepted units are"days".
Parameters:
unitsThe units to add. Must be"days".
longdaysThe number of days to add to thisDate.
Returns:
A reference to theDate (this).
Examples:
auto d = Date(2010, 1, 1);d.roll!"days"(1);writeln(d);// Date(2010, 1, 2)d.roll!"days"(365);writeln(d);// Date(2010, 1, 26)d.roll!"days"(-32);writeln(d);// Date(2010, 1, 25)
pure nothrow @nogc @safe DateopBinary(string op)(Durationduration) const
if (op == "+" || op == "-");

pure nothrow @nogc @safe DateopBinaryRight(string op)(Durationduration) const
if (op == "+");
Gives the result of adding or subtracting acore.time.Duration from thisDate.
The legal types of arithmetic forDate using this operator are
Date+Duration-->Date
Date-Duration-->Date
Duration+Date-->Date
Parameters:
DurationdurationThecore.time.Duration to add to or subtract from thisDate.
Examples:
import core.time : days;writeln(Date(2015, 12, 31) + days(1));// Date(2016, 1, 1)writeln(Date(2004, 2, 26) + days(4));// Date(2004, 3, 1)writeln(Date(2016, 1, 1) - days(1));// Date(2015, 12, 31)writeln(Date(2004, 3, 1) - days(4));// Date(2004, 2, 26)writeln(Date(2004, 2, 26) + days(4));// days(4) + Date(2004, 2, 26)
pure nothrow @nogc ref @safe DateopOpAssign(string op)(Durationduration)
if (op == "+" || op == "-");
Gives the result of adding or subtracting acore.time.Duration from thisDate, as well as assigning the result to thisDate.
The legal types of arithmetic forDate using this operator are
Date+Duration-->Date
Date-Duration-->Date
Parameters:
DurationdurationThecore.time.Duration to add to or subtract from thisDate.
pure nothrow @nogc @safe DurationopBinary(string op)(Daterhs) const
if (op == "-");
Gives the difference between twoDates.
The legal types of arithmetic forDate using this operator are
Date-Date-->duration
pure nothrow @nogc @safe intdiffMonths(Daterhs) const;
Returns the difference between the twoDates in months.
To get the difference in years, subtract the year property of twoDates. To get the difference in days or weeks, subtract theDates themselves and use thecore.time.Duration that results. Because converting between months and smaller units requires a specific date (whichcore.time.Durations don't have), getting the difference in months requires some math using both the year and month properties, so this is a convenience function for getting the difference in months.
Note that the number of days in the months or how far into the month eitherDate 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:
DaterhsTheDate to subtract from this one.
Examples:
writeln(Date(1999, 2, 1).diffMonths(Date(1999, 1, 31)));// 1writeln(Date(1999, 1, 31).diffMonths(Date(1999, 2, 1)));// -1writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1)));// 2writeln(Date(1999, 1, 1).diffMonths(Date(1999, 3, 31)));// -2
pure nothrow @nogc @property @safe boolisLeapYear() const;
Whether thisDate is in a leap year.
pure nothrow @nogc @property @safe DayOfWeekdayOfWeek() const;
Day of the week thisDate is on.
pure nothrow @nogc @property @safe ushortdayOfYear() const;
Day of the year thisDate is on.
Examples:
writeln(Date(1999, 1, 1).dayOfYear);// 1writeln(Date(1999, 12, 31).dayOfYear);// 365writeln(Date(2000, 12, 31).dayOfYear);// 366
pure @property @safe voiddayOfYear(intday);
Day of the year.
Parameters:
intdayThe day of the year to set which day of the year thisDate is on.
Throws:
std.datetime.date.DateTimeException if the given day is an invalid day of the year.
pure nothrow @nogc @property @safe intdayOfGregorianCal() const;
The Xth day of the Gregorian Calendar that thisDate is on.
Examples:
writeln(Date(1, 1, 1).dayOfGregorianCal);// 1writeln(Date(1, 12, 31).dayOfGregorianCal);// 365writeln(Date(2, 1, 1).dayOfGregorianCal);// 366writeln(Date(0, 12, 31).dayOfGregorianCal);// 0writeln(Date(0, 1, 1).dayOfGregorianCal);// -365writeln(Date(-1, 12, 31).dayOfGregorianCal);// -366writeln(Date(2000, 1, 1).dayOfGregorianCal);// 730_120writeln(Date(2010, 12, 31).dayOfGregorianCal);// 734_137
pure nothrow @nogc @property @safe voiddayOfGregorianCal(intday);
The Xth day of the Gregorian Calendar that thisDate is on.
Parameters:
intdayThe day of the Gregorian Calendar to set thisDate to.
Examples:
auto date = Date.init;date.dayOfGregorianCal = 1;writeln(date);// Date(1, 1, 1)date.dayOfGregorianCal = 365;writeln(date);// Date(1, 12, 31)date.dayOfGregorianCal = 366;writeln(date);// Date(2, 1, 1)date.dayOfGregorianCal = 0;writeln(date);// Date(0, 12, 31)date.dayOfGregorianCal = -365;writeln(date);// Date(-0, 1, 1)date.dayOfGregorianCal = -366;writeln(date);// Date(-1, 12, 31)date.dayOfGregorianCal = 730_120;writeln(date);// Date(2000, 1, 1)date.dayOfGregorianCal = 734_137;writeln(date);// Date(2010, 12, 31)
pure nothrow @property @safe autoisoWeekAndYear() const;
The ISO 8601 week and year of the year that thisDate is in.
Returns:
An anonymous struct with the membersisoWeekYear for the resulting year andisoWeek for the resulting ISO week.
See Also:
pure nothrow @property @safe ubyteisoWeek() const;
The ISO 8601 week of the year that thisDate is in.
See Also:
pure nothrow @property @safe shortisoWeekYear() const;
The year inside the ISO 8601 week calendar that thisDate is in.
May differ fromyear between 28 December and 4 January.
See Also:
pure nothrow @property @safe DateendOfMonth() const;
Date for the last day in the month that thisDate is in.
Examples:
writeln(Date(1999, 1, 6).endOfMonth);// Date(1999, 1, 31)writeln(Date(1999, 2, 7).endOfMonth);// Date(1999, 2, 28)writeln(Date(2000, 2, 7).endOfMonth);// Date(2000, 2, 29)writeln(Date(2000, 6, 4).endOfMonth);// Date(2000, 6, 30)
pure nothrow @nogc @property @safe ubytedaysInMonth() const;
The last day in the month that thisDate is in.
Examples:
writeln(Date(1999, 1, 6).daysInMonth);// 31writeln(Date(1999, 2, 7).daysInMonth);// 28writeln(Date(2000, 2, 7).daysInMonth);// 29writeln(Date(2000, 6, 4).daysInMonth);// 30
pure nothrow @nogc @property @safe boolisAD() const;
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);
pure nothrow @nogc @property @safe longjulianDay() const;
TheJulian day for thisDate at noon (since the Julian day changes at noon).
pure nothrow @nogc @property @safe longmodJulianDay() const;
The modifiedJulian day for any time on this date (since, the modified Julian day changes at midnight).
pure nothrow @safe stringtoISOString() const;

voidtoISOString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDate to a string with the formatYYYYMMDD. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
writeln(Date(2010, 7, 4).toISOString());// "20100704"writeln(Date(1998, 12, 25).toISOString());// "19981225"writeln(Date(0, 1, 5).toISOString());// "00000105"writeln(Date(-4, 1, 5).toISOString());// "-00040105"
pure nothrow @safe stringtoISOExtString() const;

voidtoISOExtString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDate to a string with the formatYYYY-MM-DD. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
writeln(Date(2010, 7, 4).toISOExtString());// "2010-07-04"writeln(Date(1998, 12, 25).toISOExtString());// "1998-12-25"writeln(Date(0, 1, 5).toISOExtString());// "0000-01-05"writeln(Date(-4, 1, 5).toISOExtString());// "-0004-01-05"
pure nothrow @safe stringtoSimpleString() const;

voidtoSimpleString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDate to a string with the formatYYYY-Mon-DD. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
writeln(Date(2010, 7, 4).toSimpleString());// "2010-Jul-04"writeln(Date(1998, 12, 25).toSimpleString());// "1998-Dec-25"writeln(Date(0, 1, 5).toSimpleString());// "0000-Jan-05"writeln(Date(-4, 1, 5).toSimpleString());// "-0004-Jan-05"
pure nothrow @safe stringtoString() const;

voidtoString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisDate to a string.
This function exists to make it easy to convert aDate to a string for code that does not care what the exact format is - just that it presents the information in a clear manner. It also makes it easy to simply convert aDate to a string when using functions such asto!string,format, orwriteln which use toString to convert user-defined types. So, it is unlikely that much code will call toString directly.
The format of the string is purposefully unspecified, and code that cares about the format of the string should usetoISOString,toISOExtString,toSimpleString, or some other custom formatting function that explicitly generates the format that the code needs. The reason is that the code is then clear about what format it's using, making it less error-prone to maintain the code and interact with other software that consumes the generated strings. It's for this same reasonDate has nofromString function, whereas it does havefromISOString,fromISOExtString, andfromSimpleString.
The format returned by toString may or may not change in the future.
pure @safe DatefromISOString(S)(scope const SisoString)
if (isSomeString!S);
Creates aDate from a string with the format YYYYMMDD. Whitespace is stripped from the given string.
Parameters:
SisoStringA string formatted in the ISO format for dates.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO format or if the resultingDate would not be valid.
pure @safe DatefromISOExtString(S)(scope const SisoExtString)
if (isSomeString!S);
Creates aDate from a string with the format YYYY-MM-DD. Whitespace is stripped from the given string.
Parameters:
SisoExtStringA string formatted in the ISO Extended format for dates.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO Extended format or if the resultingDate would not be valid.
pure @safe DatefromSimpleString(S)(scope const SsimpleString)
if (isSomeString!S);
Creates aDate from a string with the format YYYY-Mon-DD. Whitespace is stripped from the given string.
Parameters:
SsimpleStringA string formatted in the way that toSimpleString formats dates.
Throws:
std.datetime.date.DateTimeException if the given string is not in the correct format or if the resultingDate would not be valid.
static pure nothrow @nogc @property @safe Datemin();
Returns theDate farthest in the past which is representable byDate.
static pure nothrow @nogc @property @safe Datemax();
Returns theDate farthest in the future which is representable byDate.
structTimeOfDay;
Represents a time of day with hours, minutes, and seconds. It uses 24 hour time.
Examples:
import core.time : minutes, seconds;auto t =TimeOfDay(12, 30, 0);t += 10.minutes + 100.seconds;writeln(t);// TimeOfDay(12, 41, 40)writeln(t.toISOExtString());// "12:41:40"writeln(t.toISOString());// "124140"writeln(TimeOfDay.fromISOExtString("15:00:00"));// TimeOfDay(15, 0, 0)writeln(TimeOfDay.fromISOString("015000"));// TimeOfDay(1, 50, 0)
pure @safe this(inthour, intminute, intsecond = 0);
Parameters:
inthourHour of the day [0 - 24).
intminuteMinute of the hour [0 - 60).
intsecondSecond of the minute [0 - 60).
Throws:
std.datetime.date.DateTimeException if the resultingTimeOfDay would be not be valid.
pure nothrow @nogc @safe intopCmp(TimeOfDayrhs) const;
Compares thisTimeOfDay with the givenTimeOfDay.
Returns:
this < rhs< 0
this == rhs0
this > rhs> 0
pure nothrow @nogc @property @safe ubytehour() const;
Hours past midnight.
pure @property @safe voidhour(inthour);
Hours past midnight.
Parameters:
inthourThe hour of the day to set thisTimeOfDay's hour to.
Throws:
std.datetime.date.DateTimeException if the given hour would result in an invalidTimeOfDay.
pure nothrow @nogc @property @safe ubyteminute() const;
Minutes past the hour.
pure @property @safe voidminute(intminute);
Minutes past the hour.
Parameters:
intminuteThe minute to set thisTimeOfDay's minute to.
Throws:
std.datetime.date.DateTimeException if the given minute would result in an invalidTimeOfDay.
pure nothrow @nogc @property @safe ubytesecond() const;
Seconds past the minute.
pure @property @safe voidsecond(intsecond);
Seconds past the minute.
Parameters:
intsecondThe second to set thisTimeOfDay's second to.
Throws:
std.datetime.date.DateTimeException if the given second would result in an invalidTimeOfDay.
pure nothrow @nogc ref @safe TimeOfDayroll(string units)(longvalue)
if (units == "hours");

pure nothrow @nogc ref @safe TimeOfDayroll(string units)(longvalue)
if (units == "minutes" || units == "seconds");
Adds the given number of units to thisTimeOfDay, mutating it. A negative number will subtract.
The difference between rolling and adding is that rolling does not affect larger units. For instance, rolling aTimeOfDay one hours's worth of minutes gets the exact sameTimeOfDay.
Accepted units are"hours","minutes", and"seconds".
Parameters:
unitsThe units to add.
longvalueThe number ofunits to add to thisTimeOfDay.
Returns:
A reference to theTimeOfDay (this).
Examples:
auto tod1 = TimeOfDay(7, 12, 0);tod1.roll!"hours"(1);writeln(tod1);// TimeOfDay(8, 12, 0)auto tod2 = TimeOfDay(7, 12, 0);tod2.roll!"hours"(-1);writeln(tod2);// TimeOfDay(6, 12, 0)auto tod3 = TimeOfDay(23, 59, 0);tod3.roll!"minutes"(1);writeln(tod3);// TimeOfDay(23, 0, 0)auto tod4 = TimeOfDay(0, 0, 0);tod4.roll!"minutes"(-1);writeln(tod4);// TimeOfDay(0, 59, 0)auto tod5 = TimeOfDay(23, 59, 59);tod5.roll!"seconds"(1);writeln(tod5);// TimeOfDay(23, 59, 0)auto tod6 = TimeOfDay(0, 0, 0);tod6.roll!"seconds"(-1);writeln(tod6);// TimeOfDay(0, 0, 59)
pure nothrow @nogc @safe TimeOfDayopBinary(string op)(Durationduration) const
if (op == "+" || op == "-");

pure nothrow @nogc @safe TimeOfDayopBinaryRight(string op)(Durationduration) const
if (op == "+");
Gives the result of adding or subtracting acore.time.Duration from thisTimeOfDay.
The legal types of arithmetic forTimeOfDay using this operator are
TimeOfDay+Duration-->TimeOfDay
TimeOfDay-Duration-->TimeOfDay
Duration+TimeOfDay-->TimeOfDay
Parameters:
DurationdurationThecore.time.Duration to add to or subtract from thisTimeOfDay.
Examples:
import core.time : hours, minutes, seconds;writeln(TimeOfDay(12, 12, 12) + seconds(1));// TimeOfDay(12, 12, 13)writeln(TimeOfDay(12, 12, 12) + minutes(1));// TimeOfDay(12, 13, 12)writeln(TimeOfDay(12, 12, 12) + hours(1));// TimeOfDay(13, 12, 12)writeln(TimeOfDay(23, 59, 59) + seconds(1));// TimeOfDay(0, 0, 0)writeln(TimeOfDay(12, 12, 12) - seconds(1));// TimeOfDay(12, 12, 11)writeln(TimeOfDay(12, 12, 12) - minutes(1));// TimeOfDay(12, 11, 12)writeln(TimeOfDay(12, 12, 12) - hours(1));// TimeOfDay(11, 12, 12)writeln(TimeOfDay(0, 0, 0) - seconds(1));// TimeOfDay(23, 59, 59)writeln(TimeOfDay(12, 12, 12) + seconds(1));// seconds(1) + TimeOfDay(12, 12, 12)
pure nothrow @nogc ref @safe TimeOfDayopOpAssign(string op)(Durationduration)
if (op == "+" || op == "-");
Gives the result of adding or subtracting acore.time.Duration from thisTimeOfDay, as well as assigning the result to thisTimeOfDay.
The legal types of arithmetic forTimeOfDay using this operator are
TimeOfDay+Duration-->TimeOfDay
TimeOfDay-Duration-->TimeOfDay
Parameters:
DurationdurationThecore.time.Duration to add to or subtract from thisTimeOfDay.
pure nothrow @nogc @safe DurationopBinary(string op)(TimeOfDayrhs) const
if (op == "-");
Gives the difference between twoTimeOfDays.
The legal types of arithmetic forTimeOfDay using this operator are
TimeOfDay-TimeOfDay-->duration
Parameters:
TimeOfDayrhsTheTimeOfDay to subtract from this one.
pure nothrow @safe stringtoISOString() const;

voidtoISOString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisTimeOfDay to a string with the formatHHMMSS. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
writeln(TimeOfDay(0, 0, 0).toISOString());// "000000"writeln(TimeOfDay(12, 30, 33).toISOString());// "123033"
pure nothrow @safe stringtoISOExtString() const;

voidtoISOExtString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts thisTimeOfDay to a string with the formatHH:MM:SS. Ifwriter is set, the resulting string will be written directly to it.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
Examples:
writeln(TimeOfDay(0, 0, 0).toISOExtString());// "00:00:00"writeln(TimeOfDay(12, 30, 33).toISOExtString());// "12:30:33"
pure nothrow @safe stringtoString() const;

voidtoString(W)(ref Wwriter) const
if (isOutputRange!(W, char));
Converts this TimeOfDay to a string.
This function exists to make it easy to convert aTimeOfDay to a string for code that does not care what the exact format is - just that it presents the information in a clear manner. It also makes it easy to simply convert aTimeOfDay to a string when using functions such asto!string,format, orwriteln which use toString to convert user-defined types. So, it is unlikely that much code will call toString directly.
The format of the string is purposefully unspecified, and code that cares about the format of the string should usetoISOString,toISOExtString, or some other custom formatting function that explicitly generates the format that the code needs. The reason is that the code is then clear about what format it's using, making it less error-prone to maintain the code and interact with other software that consumes the generated strings. It's for this same reason thatTimeOfDay has nofromString function, whereas it does havefromISOString andfromISOExtString.
The format returned by toString may or may not change in the future.
Parameters:
WwriterAchar acceptingoutput range
Returns:
Astring when not using an output range;void otherwise.
pure @safe TimeOfDayfromISOString(S)(scope const SisoString)
if (isSomeString!S);
Creates aTimeOfDay from a string with the format HHMMSS. Whitespace is stripped from the given string.
Parameters:
SisoStringA string formatted in the ISO format for times.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO format or if the resultingTimeOfDay would not be valid.
pure @safe TimeOfDayfromISOExtString(S)(scope const SisoExtString)
if (isSomeString!S);
Creates aTimeOfDay from a string with the format HH:MM:SS. Whitespace is stripped from the given string.
Parameters:
SisoExtStringA string formatted in the ISO Extended format for times.
Throws:
std.datetime.date.DateTimeException if the given string is not in the ISO Extended format or if the resultingTimeOfDay would not be valid.
static pure nothrow @nogc @property @safe TimeOfDaymin();
Returns midnight.
static pure nothrow @nogc @property @safe TimeOfDaymax();
Returns one second short of midnight.
pure nothrow @nogc @safe boolvalid(string units)(intvalue)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds");
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:
unitsThe units of time to validate.
intvalueThe number to validate.
Examples:
assert(valid!"hours"(12));assert(!valid!"hours"(32));assert(valid!"months"(12));assert(!valid!"months"(13));
pure nothrow @nogc @safe boolvalid(string units)(intyear, intmonth, intday)
if (units == "days");
Returns whether the given day is valid for the given year and month.
Parameters:
unitsThe units of time to validate.
intyearThe year of the day to validate.
intmonthThe month of the day to validate (January is 1).
intdayThe day to validate.
Examples:
assert(valid!"days"(2016, 2, 29));assert(!valid!"days"(2016, 2, 30));assert(valid!"days"(2017, 2, 20));assert(!valid!"days"(2017, 2, 29));
pure @safe voidenforceValid(string units)(intvalue, stringfile = __FILE__, size_tline = __LINE__)
if (units == "months" || units == "hours" || units == "minutes" || units == "seconds");
Parameters:
unitsThe units of time to validate.
intvalueThe number to validate.
stringfileThe file that theDateTimeException will list if thrown.
size_tlineThe line number that theDateTimeException will list if thrown.
Throws:
DateTimeException ifvalid!units(value) is false.
Examples:
import std.exception : assertThrown, assertNotThrown;assertNotThrown(enforceValid!"months"(10));assertNotThrown(enforceValid!"seconds"(40));assertThrown!DateTimeException(enforceValid!"months"(0));assertThrown!DateTimeException(enforceValid!"hours"(24));assertThrown!DateTimeException(enforceValid!"minutes"(60));assertThrown!DateTimeException(enforceValid!"seconds"(60));
pure @safe voidenforceValid(string units)(intyear, Monthmonth, intday, stringfile = __FILE__, size_tline = __LINE__)
if (units == "days");
Because the validity of the day number depends on both on the year and month of which the day is occurring, take all three variables to validate the day.
Parameters:
unitsThe units of time to validate.
intyearThe year of the day to validate.
MonthmonthThe month of the day to validate.
intdayThe day to validate.
stringfileThe file that theDateTimeException will list if thrown.
size_tlineThe line number that theDateTimeException will list if thrown.
Throws:
DateTimeException ifvalid!"days"(year, month, day) is false.
Examples:
import std.exception : assertThrown, assertNotThrown;assertNotThrown(enforceValid!"days"(2000, Month.jan, 1));// leap yearassertNotThrown(enforceValid!"days"(2000, Month.feb, 29));assertThrown!DateTimeException(enforceValid!"days"(2001, Month.feb, 29));assertThrown!DateTimeException(enforceValid!"days"(2000, Month.jan, 32));assertThrown!DateTimeException(enforceValid!"days"(2000, Month.apr, 31));
pure nothrow @nogc @safe intdaysToDayOfWeek(DayOfWeekcurrDoW, DayOfWeekdow);
Returns the number of days from the current day of the week to the given day of the week. If they are the same, then the result is 0.
Parameters:
DayOfWeekcurrDoWThe current day of the week.
DayOfWeekdowThe day of the week to get the number of days to.
Examples:
writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.mon));// 0writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.sun));// 6writeln(daysToDayOfWeek(DayOfWeek.mon, DayOfWeek.wed));// 2
pure @safe intmonthsToMonth(intcurrMonth, intmonth);
Returns the number of months from the current months of the year to the given month of the year. If they are the same, then the result is 0.
Parameters:
intcurrMonthThe current month of the year.
intmonthThe month of the year to get the number of months to.
Examples:
writeln(monthsToMonth(Month.jan, Month.jan));// 0writeln(monthsToMonth(Month.jan, Month.dec));// 11writeln(monthsToMonth(Month.jul, Month.oct));// 3
pure nothrow @nogc @safe boolyearIsLeapYear(intyear);
Whether the given Gregorian Year is a leap year.
Parameters:
intyearThe year to to be tested.
Examples:
foreach (year; [1, 2, 100, 2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010]){assert(!yearIsLeapYear(year));assert(!yearIsLeapYear(-year));}foreach (year; [0, 4, 8, 400, 800, 1600, 1996, 2000, 2004, 2008, 2012]){assert(yearIsLeapYear(year));assert(yearIsLeapYear(-year));}
enum autoisTimePoint(T);
Whether the given type defines all of the necessary functions for it to function as a time point.
  1. T must define a static property namedmin which is the smallest value ofT asUnqual!T.
  2. T must define a static property namedmax which is the largest value ofT asUnqual!T.
  3. T must define anopBinary for addition and subtraction that acceptscore.time.Duration and returnsUnqual!T.
  4. T must define anopOpAssign for addition and subtraction that acceptscore.time.Duration and returnsref Unqual!T.
  5. T must define aopBinary for subtraction which acceptsT and returnscore.time.Duration.
Examples:
import core.time : Duration;import std.datetime.interval : Interval;import std.datetime.systime : SysTime;staticassert(isTimePoint!Date);staticassert(isTimePoint!DateTime);staticassert(isTimePoint!SysTime);staticassert(isTimePoint!TimeOfDay);staticassert(!isTimePoint!int);staticassert(!isTimePoint!Duration);staticassert(!isTimePoint!(Interval!SysTime));
pure nothrow @nogc @safe boolvalidTimeUnits(string[]units...);
Whether all of the given strings are valid units of time.
"nsecs" is not considered a valid unit of time. Nothing in std.datetime can handle precision greater than hnsecs, and the few functions in core.time which deal with "nsecs" deal with it explicitly.
Examples:
assert(validTimeUnits("msecs","seconds","minutes"));assert(validTimeUnits("days","weeks","months"));assert(!validTimeUnits("ms","seconds","minutes"));
pure @safe intcmpTimeUnits(stringlhs, stringrhs);
Compares two time unit strings."years" are the largest units and"hnsecs" are the smallest.
Returns:
this < rhs< 0
this == rhs0
this > rhs> 0
Throws:
DateTimeException if either of the given strings is not a valid time unit string.
Examples:
import std.exception : assertThrown;writeln(cmpTimeUnits("hours","hours"));// 0assert(cmpTimeUnits("hours","weeks") < 0);assert(cmpTimeUnits("months","seconds") > 0);assertThrown!DateTimeException(cmpTimeUnits("month","second"));
templateCmpTimeUnits(string lhs, string rhs) if (validTimeUnits(lhs, rhs))
Compares two time unit strings at compile time."years" are the largest units and"hnsecs" are the smallest.
This template is used instead ofcmpTimeUnits because exceptions can't be thrown at compile time andcmpTimeUnits 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 == rhs0
this > rhs> 0
Examples:
staticassert(CmpTimeUnits!("years","weeks") > 0);staticassert(CmpTimeUnits!("days","days") == 0);staticassert(CmpTimeUnits!("seconds","hours") < 0);
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 06:43:12 2026

[8]ページ先頭

©2009-2026 Movatter.jp