Class time::Date

Implements Comparable<Date>, Addable<Int, Date>

The Date class represents a date or a day. Date instances are immutable.

class Date()
Construct a Date object representing the current date (today) in local time.
class Date(year as Int, month as Int, day as Int)
Construct a Date object representing a specific day. All arguments must be integers. Month and day values are not restricted to any specific range. If they are outside the valid range of values, they are normalized and the excess is moved to the month or year values. So if month is 14, the actual month value becomes 2 and year is incremented by one; if day is 0, the resulting day will be the last day of the previous month, etc.
Date(2010, 3, 8)           -- 8th of March, 2010
class Date(string as Str[, format as Str])
Construct a Date object from a string. The format argument specifies the format of the string. If the format is omitted, the default format is "YYYY-MM-DD".

The format must contain format sequences for all date components (day, month, year). A format sequence matches a date component in the string. The following list contains all the available format sequences and examples of valid values:

D day of month (1, 2, ..., 31)
DD day of month, at least 2 digits (01, 02, ... 31)
M month (1, 2, ..., 12)
MM month, at least 2 digits (01, 02, ... 12)
MMM abbreviated name of month (Jan, Feb, ..., Dec)
MMMM  name of month (January, February, ..., December)
YY year, 2 digits (00, 01, ... 99)
YYYY year, 4 digits (1978, 2010, ...)

Case is not significant in the month names and abbreviations. The YY values 69-99 are mapped to years 1969-1999, and 00-68 are mapped to years 2000-2068. You should generally use the YYYY format for years so that years before 1969 and after 2068 can be represented.

Any other characters in the format must be matched by the same character in the string. As an exception, a backslash \ followed by a character c must be matched by c.


day as Int
Day of month (the first day of the month is 1)
month as Int
Month number (1 = January, 2 = February, ...).
year as Int
Year number (e.g. 2010)
weekday as Int
Weekday of the date (1 = Monday, 2 = Tuesday, ..., 7 = Sunday).
week([rule as Constant]) as Int
Return the week number. The rule argument specifies how the week number is calculated. It can be one of FirstWeek, FirstFourDayWeek or FirstFullWeek. If unspecified, FirstFourDayWeek is assumed. Sunday is considered to be the last day of the week and Monday the first.
format(template as Str) as Str

Format the date as a string. The template string defines the format of the result. The following formatting sequences in the template are replaced with formatted Date components (examples within parentheses):

D day of month (5)
DD day of month, at least 2 digits (05)
M month (5)
MM month, at least 2 digits (05)
MMM abbreviated name of month (Feb)
MMMM  name of month (February)
YY year, 2 digits (09)
YYYY year, 4 digits (2009)
WWW abbreviation of weekday (Wed)
WWWW  weekday (Wednesday)

Other characters in the template are copied as such to the result. As an exception, a backslash \ followed by a character c is replaced with c.


date + n (Date + IntDate)
Integers representing a number of days can added to and subtracted from dates. Date() + 1, for example, refers to tomorrow.
Str(date) (Str(Date) ⇒ Str)
Convert a date to a string of the form "YYYY-MM-DD".
date1 == date2 (Date == DateBoolean)
date1 < date2 (Date < DateBoolean)
date1 > date2 (Date > DateBoolean)
Dates can be compared for equality and order. An earlier date is smaller than a later date.
Hash(date) (Hash(Date) ⇒ Int)
Return the hash value of a Date object.