The OpenD Programming Language

Date

Represents a date in the Proleptic Gregorian Calendar ranging from 32,768 B.C. to 32,767 A.D. Positive years are A.D. Non-positive years are B.C.

Year, month, and day are kept separately internally so that Date is optimized for calendar-based operations.

Date uses the Proleptic Gregorian Calendar, so it assumes the Gregorian leap year calculations for its entire length. As per ISO 8601, it treats 1 B.C. as year 0, i.e. 1 B.C. is 0, 2 B.C. is -1, etc. Use yearBC to use B.C. as a positive integer with 1 B.C. being the year prior to 1 A.D.

Year 0 is a leap year.

struct Date {}

Constructors

this
this(int year, int month, int day)
this
this(int day)

Members

Functions

add
Date add(long value, AllowDayOverflow allowOverflow)

Adds the given number of years or months to this Date, mutating it. A negative number will subtract.

diffMonths
int diffMonths(Date rhs)

Returns the difference between the two Dates in months.

opBinary
Date opBinary(Duration duration)

Gives the result of adding or subtracting a core.time.Duration from

opBinary
Duration opBinary(Date rhs)

Gives the difference between two Dates.

opCmp
int opCmp(Date rhs)

Compares this Date with the given Date.

opOpAssign
Date opOpAssign(Duration duration)

Gives the result of adding or subtracting a core.time.Duration from this Date, as well as assigning the result to this Date.

roll
Date roll(long value, AllowDayOverflow allowOverflow)

Adds the given number of years or months to this Date, mutating it. A negative number will subtract.

roll
Date roll(long days)

Adds the given number of units to this Date, mutating it. A negative number will subtract.

toISOExtString
string toISOExtString()
void toISOExtString(W writer)

Converts this Date to a string with the format YYYY-MM-DD. If writer is set, the resulting string will be written directly to it.

toISOString
string toISOString()
void toISOString(W writer)

Converts this Date to a string with the format YYYYMMDD. If writer is set, the resulting string will be written directly to it.

toSimpleString
string toSimpleString()
void toSimpleString(W writer)

Converts this Date to a string with the format YYYY-Mon-DD. If writer is set, the resulting string will be written directly to it.

toString
string toString()
void toString(W writer)

Converts this Date to a string.

Properties

day
ubyte day [@property getter]

Day of a Gregorian Month.

day
int day [@property setter]

Day of a Gregorian Month.

dayOfGregorianCal
int dayOfGregorianCal [@property getter]

The Xth day of the Gregorian Calendar that this Date is on.

dayOfGregorianCal
int dayOfGregorianCal [@property setter]

The Xth day of the Gregorian Calendar that this Date is on.

dayOfWeek
DayOfWeek dayOfWeek [@property getter]

Day of the week this Date is on.

dayOfYear
ushort dayOfYear [@property getter]

Day of the year this Date is on.

dayOfYear
int dayOfYear [@property setter]

Day of the year.

daysInMonth
ubyte daysInMonth [@property getter]

The last day in the month that this Date is in.

endOfMonth
Date endOfMonth [@property getter]

Date for the last day in the month that this Date is in.

isAD
bool isAD [@property getter]

Whether the current year is a date in A.D.

isLeapYear
bool isLeapYear [@property getter]

Whether this Date is in a leap year.

isoWeek
ubyte isoWeek [@property getter]

The ISO 8601 week of the year that this Date is in.

isoWeekAndYear
auto isoWeekAndYear [@property getter]

The ISO 8601 week and year of the year that this Date is in.

isoWeekYear
short isoWeekYear [@property getter]

The year inside the ISO 8601 week calendar that this Date is in.

julianDay
long julianDay [@property getter]

The Julian day for this Date at noon (since the Julian day changes at noon).

max
Date max [@property getter]

Returns the Date farthest in the future which is representable by Date.

min
Date min [@property getter]

Returns the Date farthest in the past which is representable by Date.

modJulianDay
long modJulianDay [@property getter]

The modified Julian day for any time on this date (since, the modified Julian day changes at midnight).

month
Month month [@property getter]

Month of a Gregorian Year.

month
Month month [@property setter]

Month of a Gregorian Year.

year
short year [@property getter]

Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.

year
int year [@property setter]

Year of the Gregorian Calendar. Positive numbers are A.D. Non-positive are B.C.

yearBC
ushort yearBC [@property getter]

Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.

yearBC
int yearBC [@property setter]

Year B.C. of the Gregorian Calendar counting year 0 as 1 B.C.

Static functions

fromISOExtString
Date fromISOExtString(S isoExtString)

Creates a Date from a string with the format YYYY-MM-DD. Whitespace is stripped from the given string.

fromISOString
Date fromISOString(S isoString)

Creates a Date from a string with the format YYYYMMDD. Whitespace is stripped from the given string.

fromSimpleString
Date fromSimpleString(S simpleString)

Creates a Date from a string with the format YYYY-Mon-DD. Whitespace is stripped from the given string.

Structs

Duration (from core.time)
struct Duration via public import core.time : Duration;

Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).

Examples

import core.time : days;

auto d = Date(2000, 6, 1);

assert(d.dayOfYear == 153);
assert(d.dayOfWeek == DayOfWeek.thu);

d += 10.days;
assert(d == Date(2000, 6, 11));

assert(d.toISOExtString() == "2000-06-11");
assert(d.toISOString() == "20000611");
assert(d.toSimpleString() == "2000-Jun-11");

assert(Date.fromISOExtString("2018-01-01") == Date(2018, 1, 1));
assert(Date.fromISOString("20180101") == Date(2018, 1, 1));
assert(Date.fromSimpleString("2018-Jan-01") == Date(2018, 1, 1));

Meta