- this(Year year, MonthOfYear month, DayOfMonth day);
- Params:
| Year 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. |
| MonthOfYear month |
Month of the year. |
| DayOfMonth day |
Day of the month. |
- const int opCmp(in Date rhs);
- Compares this Date with the given Date.
Returns:
| this < rhs | < 0 |
| this == rhs | 0 |
| this > rhs | > 0 |
- const Year year();
- Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
- void year(Year year);
- Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.
Params:
| Year year |
The year to set this Date's year to. |
Examples:
assert(Date(1999, 7, 6).year == 1999);
assert(Date(2010, 10, 4).year == 2010);
assert(Date(-7, 4, 5).year == -7);
- const Year yearBC();
- Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception
is thrown 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);
- void yearBC(Year year);
- Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C. An exception
is thrown if a non-positive value is given.
Params:
| Year year |
The year B.C. to set this Date's year to. |
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));
- const MonthOfYear month();
- 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);
- void month(MonthOfYear month);
- Month of a Gregorian Year.
Params:
| mounth |
The month to set this Date's month to. |
- const DayOfMonth day();
- 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);
- void day(DayOfMonth day);
- Day of a Gregorian Month.
Params:
| DayOfMonth day |
The day of the month to set this Date's day to. |
- void addYears(int years, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
- Adds the given number of years to this Date. A negative number will subtract.
Note that if day overflow is allowed, and the date is Febuary 29th of a leap year,
and the new year is not a leap year, then the date is shifted to March 1st. If
day overflow is not allowed, then the date is shifted to February 28th.
Params:
| int years |
The number of years to add to this Date. |
| AllowDayOverflow allowOverflow |
Whether the days should be allowed to overflow, causing the month to increment. |
Examples:
auto date1 = Date(2010, 1, 1);
date1.addYears(1);
assert(date1 == Date(2011, 1, 1));
auto date2 = Date(2010, 1, 1);
date2.addYears(-1);
assert(date2 == Date(2009, 1, 1));
auto date3 = Date(2000, 2, 29);
date3.addYears(1);
assert(date3 == Date(2001, 3, 1));
auto date4 = Date(2000, 2, 29);
date4.addYears(1, AllowDayOverflow.no);
assert(date4 == Date(2001, 2, 28));
- void addMonths(int months, AllowDayOverflow allowOverflow = (AllowDayOverflow).yes);
- Adds the given number of months to this Date. A negative number will subtract.
The year will be adjusted along with the month if the number of months added (or subtracted)
would overflow (or underflow) the current year.
Note that if day overflow is allowed, and the date with the adjusted month overflows the number
of days in the new month, then the month will be incremented by one, and the days 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).
Params:
| int months |
The number of months to add to this Date. |
| AllowDayOverflow allowOverflow |
Whether the days should be allowed to overflow, causing the month to increment. |
Examples:
auto date1 = Date(2010, 1, 1);
date1.addMonths(1);
assert(date1 == Date(2010, 2, 1));
auto date2 = Date(2010, 1, 1);
date2.addMonths(-1);
assert(date2 == Date(2009, 12, 1));
auto date3 = Date(1999, 1, 29);
date3.addMonths(1);
assert(date3 == Date(1999, 3, 1));
auto date4 = Date(1999, 1, 29);
date4.addMonths(1, AllowDayOverflow.no);
assert(date4 == Date(1999, 2, 28));
- void addWeeks(long weeks);
- Adds the given number of weeks to this Date. A negative number will subtract.
The day, month, and year will be adjusted accordingly.
addWeeks(numWeeks) is effectively equivalent to addDays(numWeeks * 7).
Note that addWeeks(52) is not equivalent to addYear(1) because a year does not have
exactly 52 weeks.
Params:
| long weeks |
The number of weeks to add to this Date. |
Examples:
auto date1 = Date(2010, 1, 1);
auto date2 = date1;
date1.addWeeks(1);
date2.addDays(7);
assert(date1 == date2);
date1.addWeeks(52);
date2.addYears(1);
assert(date1 != date2);
assert(date1 == Date(2011, 1, 7));
assert(date2 == Date(2011, 1, 8));
- void addDays(long days);
- Adds the given number of days to this Date. A negative number will subtract.
The month will be adjusted along with the day if the number of days added (or subtracted)
would overflow (or underflow) the current month. The year will be adjusted along with
the month if the increase (or decrease) to the month would cause it to overflow (or underflow)
the current year.
addDays(numDays) is effectively equivalent to date.dayOfGregorianCal = date.dayOfGregorianCal + days.
Params:
| long days |
The number of days to add to this Date. |
Examples:
auto date = Date(2010, 1, 1);
date.addDays(1);
assert(date == Date(2010, 1, 2));
date.addDays(365);
assert(date == Date(2011, 1, 2));
date.addDays(-32);
assert(date == Date(2010, 12, 1));
- void addTimeUnit(TimeUnit units)(long value, AllowDayOverflow allowOverflow = AllowDayOverflow.yes);
- Function for adding time units generically. The given TimeUnit must
be TimeUnit.year, TimeUnit.month, TimeUnit.week, or TimeUnit.day.
Params:
| units |
The type of unit to add to. |
| value |
The number of units to add to the given type of unit. |
| allowOverflow |
Whether the days should be allowed to overflow, causing
the month to increment (only really applies to TimeUnit.year
and TimeUnit.month, but addTimeUnit() is generic, so it's included;
It's ignore otherwise). |
Examples:
addTimeUnit!(TimeUnit.year)(numYears); //translates to addYears(numYears);
addTimeUnit!(TimeUnit.month)(numMonths); //translates to addMonths(numMonths);
addTimeUnit!(TimeUnit.week)(numWeeks); //translates to addMonths(numWeeks);
addTimeUnit!(TimeUnit.day)(numDays); //translates to addMonths(numDays);
- const bool isLeapYear();
- Whether this Date is in a leap year.
- const Tuple!(short,ubyte,ubyte) yearMonthDay();
- Date as a tuple of year, month, and day.
- const DayOfWeek dayOfWeek();
- Day of the week.
- const DayOfYear dayOfYear();
- 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);
- void dayOfYear(DayOfYear day);
- Day of the year.
Params:
| DayOfYear day |
The day of the year to set which day of the year this Date is on. |
- const DayOfGregorianCal dayOfGregorianCal();
- The Xth day of the Gregorian Calendar.
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);
- void dayOfGregorianCal(DayOfGregorianCal days);
- The Xth day of the Gregorian Calendar.
Examples:
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));
- const ISOWeek isoWeek();
- The ISO 8601 week of the year that this Date is.
See Also:
ISO Week Date
- const Date endOfMonth();
- 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));
- const DayOfMonth endOfMonthDay();
- 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);
- const bool isAD();
- Whether the current year is a date in A.D.
Examples:
assert(Date(1, 1, 1).isAD);
assert(Date(2010, 12, 31).isAD);
assert(!Date(0, 12, 31).isAD);
assert(!Date(-2010, 1, 1).isAD);
- const bool isSpecial();
- Returns true if isInfinity or isNAD are true.
- const bool isInfinity();
- Returns true if this date represents positive or negative infinity.
- const bool isPosInfinity();
- Returns true if this date represents positive.
- const bool isNegInfinity();
- Returns true if this date represents negative infinity.
- const bool isNAD();
- Returns true if this date is NAD (Not-a-Date), the Date equivalent of NAN.
- const long julianDay();
- The julian day for this Date at noon (since the julian day changes at noon).
- const long modJulianDay();
- The modified julian day for this Date at any time (since, the modified julian day changes at midnight).
- const string toISOString();
- 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");
- const string toISOExtendedString();
- 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");
- const string toSimpleString();
- Converts this Date to a string with the format YYYY-MonthShortName-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");
- string toString();
- Converts this Date to a string.
- const string toString();
- Converts this Date to a string.
- static bool yearIsLeapYear(Year year);
- Whether the given Year is a leap year.
- static Date posInfinity();
- Returns a Date for which isPosInfinity is true.
- static Date negInfinity();
- Returns a Date for which isNegInfinity is true.
- static Date notADate();
- Returns a Date for which isNAD is true.
- static Date min();
- Returns the Date farthest in the past which is representable by Date.
- static Date max();
- Returns the Date farthest in the future which is representable by Date.
- static TimeUnit minResolution();
- The lowest time resolution that Date has.
- static TimeUnit maxResolution();
- The highest time resolution that Date has.