The OpenD Programming Language

DateTime

Combines the std.datetime.date.Date and std.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, use std.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.

struct DateTime {}

Constructors

this
this(Date date, TimeOfDay tod)
this
this(int year, int month, int day, int hour, int minute, int second)

Members

Functions

add
DateTime add(long value, AllowDayOverflow allowOverflow)

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

diffMonths
int diffMonths(DateTime rhs)

Returns the difference between the two DateTimes in months.

opBinary
DateTime opBinary(Duration duration)

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

opBinary
Duration opBinary(DateTime rhs)

Gives the difference between two DateTimes.

opCmp
int opCmp(DateTime rhs)

Compares this DateTime with the given DateTime..

opOpAssign
DateTime opOpAssign(Duration duration)

Gives the result of adding or subtracting a duration from this DateTime, as well as assigning the result to this DateTime.

roll
DateTime roll(long value, AllowDayOverflow allowOverflow)

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

roll
DateTime roll(long value)

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

toISOExtString
string toISOExtString()
void toISOExtString(W writer)

Converts this DateTime to a string with the format YYYY-MM-DDTHH:MM:SS. If writer is set, the resulting string will be written directly to it.

toISOString
string toISOString()
void toISOString(W writer)

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

toSimpleString
string toSimpleString()
void toSimpleString(W writer)

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

toString
string toString()
void toString(W writer)

Converts this DateTime to a string.

Properties

date
Date date [@property getter]

The date portion of DateTime.

date
Date date [@property setter]

The date portion of DateTime.

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 DateTime is on.

dayOfGregorianCal
int dayOfGregorianCal [@property setter]

The Xth day of the Gregorian Calendar that this DateTime is on. Setting this property does not affect the time portion of DateTime.

dayOfWeek
DayOfWeek dayOfWeek [@property getter]

Day of the week this DateTime is on.

dayOfYear
ushort dayOfYear [@property getter]

Day of the year this DateTime is on.

dayOfYear
int dayOfYear [@property setter]

Day of the year.

daysInMonth
ubyte daysInMonth [@property getter]

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

endOfMonth
DateTime endOfMonth [@property getter]

DateTime for the last day in the month that this DateTime is in. The time portion of endOfMonth is always 23:59:59.

hour
ubyte hour [@property getter]

Hours past midnight.

hour
int hour [@property setter]

Hours past midnight.

isAD
bool isAD [@property getter]

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

isLeapYear
bool isLeapYear [@property getter]

Whether this DateTime is in a leap year.

isoWeek
ubyte isoWeek [@property getter]

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

isoWeekYear
short isoWeekYear [@property getter]

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

julianDay
long julianDay [@property getter]

The Julian day for this DateTime 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.

max
DateTime max [@property getter]

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

min
DateTime min [@property getter]

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

minute
ubyte minute [@property getter]

Minutes past the hour.

minute
int minute [@property setter]

Minutes past the hour.

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.

second
ubyte second [@property getter]

Seconds past the minute.

second
int second [@property setter]

Seconds past the minute.

timeOfDay
TimeOfDay timeOfDay [@property getter]

The time portion of DateTime.

timeOfDay
TimeOfDay timeOfDay [@property setter]

The time portion of DateTime.

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
short 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
DateTime fromISOExtString(S isoExtString)

Creates a DateTime from a string with the format YYYY-MM-DDTHH:MM:SS. Whitespace is stripped from the given string.

fromISOString
DateTime fromISOString(S isoString)

Creates a DateTime from a string with the format YYYYMMDDTHHMMSS. Whitespace is stripped from the given string.

fromSimpleString
DateTime fromSimpleString(S simpleString)

Creates a DateTime from a string with the format YYYY-Mon-DD HH:MM:SS. 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, seconds;

auto dt = DateTime(2000, 6, 1, 10, 30, 0);

assert(dt.date == Date(2000, 6, 1));
assert(dt.timeOfDay == TimeOfDay(10, 30, 0));
assert(dt.dayOfYear == 153);
assert(dt.dayOfWeek == DayOfWeek.thu);

dt += 10.days + 100.seconds;
assert(dt == DateTime(2000, 6, 11, 10, 31, 40));

assert(dt.toISOExtString() == "2000-06-11T10:31:40");
assert(dt.toISOString() == "20000611T103140");
assert(dt.toSimpleString() == "2000-Jun-11 10:31:40");

assert(DateTime.fromISOExtString("2018-01-01T12:00:00") == DateTime(2018, 1, 1, 12, 0, 0));
assert(DateTime.fromISOString("20180101T120000") == DateTime(2018, 1, 1, 12, 0, 0));
assert(DateTime.fromSimpleString("2018-Jan-01 12:00:00") == DateTime(2018, 1, 1, 12, 0, 0));

Meta