The Date class represents a date or a day. Date instances are immutable. @class Date() @desc Construct a Date object representing the current date (today) in local time. @end @class Date(year as Int, month as Int, day as Int) @desc 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. @example Date(2010, 3, 8) -- 8th of March, 2010 @end @end @class Date(string as Str[, format as Str]) @desc 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. @end
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. @end