View source code
Display the source code in std/datetime/date.d from which this page was generated on github.
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 using local clone.

Module std.datetime.date

Category Functions
Main date types Date DateTime
Other date types Month DayOfWeek TimeOfDay
Date checking valid validTimeUnits yearIsLeapYear isTimePoint enforceValid
Date conversion daysToDayOfWeek monthsToMonth
Time units cmpTimeUnits timeStrings
Other AllowDayOverflow DateTimeException

Functions

NameDescription
cmpTimeUnits(lhs, rhs) Compares two time unit strings. "years" are the largest units and "hnsecs" are the smallest.
daysToDayOfWeek(currDoW, dow) 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.
enforceValid(value, file, line)
enforceValid(year, month, day, file, line) 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.
monthsToMonth(currMonth, month) 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.
valid(value) 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).
valid(year, month, day) Returns whether the given day is valid for the given year and month.
validTimeUnits(units) Whether all of the given strings are valid units of time.
yearIsLeapYear(year) Whether the given Gregorian Year is a leap year.

Structs

NameDescription
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.
DateTime Combines the Date and 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 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.
TimeOfDay Represents a time of day with hours, minutes, and seconds. It uses 24 hour time.

Enums

NameDescription
DayOfWeek Represents the 7 days of the Gregorian week (Sunday is 0).
Month Represents the 12 months of the Gregorian year (January is 1).

Manifest constants

NameTypeDescription
CmpTimeUnits Compares two time unit strings at compile time. "years" are the largest units and "hnsecs" are the smallest.
isTimePoint Whether the given type defines all of the necessary functions for it to function as a time point.

Global variables

NameTypeDescription
timeStrings immutable(char[][]) Array of the strings representing time units, starting with the smallest unit and going to the largest. It does not include "nsecs".

Aliases

NameTypeDescription
AllowDayOverflow Flag!("allowDayOverflow") 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).
DateTimeException TimeException Exception type used by std.datetime. It's an alias to TimeException. Either can be caught without concern about which module it came from.

Authors

Jonathan M Davis

License

Boost License 1.0.