Class representing a date.
See the documentation to the file date.rb for an overview.
Internally, the date is represented as an Astronomical Julian Day Number, ajd. The Day of Calendar Reform, sg, is also stored, for conversions to other date formats. (There is also an of field for a time zone offset, but this is only for the use of the DateTime subclass.)
A new Date object is created using one of the object creation class methods named after the corresponding date format, and the arguments appropriate to that date format; for instance, Date::civil() (aliased to Date::new()) with year, month, and day-of-month, or Date::ordinal() with year and day-of-year. All of these object creation class methods also take the Day of Calendar Reform as an optional argument.
Date objects are immutable once created.
Once a Date has been created, date values can be retrieved for the different date formats supported using instance methods. For instance, #mon() gives the Civil month, #cwday() gives the Commercial day of the week, and #yday() gives the Ordinal day of the year. Date values can be retrieved in any format, regardless of what format was used to create the Date instance.
The Date class includes the Comparable module, allowing date objects to be compared and sorted, ranges of dates to be created, and so forth.
| Modules | |
|---|---|
| Format | |
| Classes | |
|---|---|
| Infinity | |
| Constants | |
|---|---|
| ABBR_ |
Abbreviated day names, in English. |
| ABBR_ |
Abbreviated month names, in English. |
| DAYNAMES | Full names of days of the week, in English. Days of the week count from 0 to 6 (except in the commercial week); a day’s numerical representation indexed into this array gives the name of that day. |
| ENGLAND | The Julian Day Number of the Day of Calendar Reform for England and her Colonies. |
| GREGORIAN | A constant used to indicate that a Date should always use the Gregorian calendar. |
| ITALY | The Julian Day Number of the Day of Calendar Reform for Italy and the Catholic countries. |
| JULIAN | A constant used to indicate that a Date should always use the Julian calendar. |
| MONTHNAMES | Full month names, in English. Months count from 1 to 12; a month’s numerical representation indexed into this array gives the name of that month (hence the first element is nil). |
| UNIXEPOCH | |
| Aliases | |
|---|---|
| leap? | |
| new | |
| new! | |
| valid_ |
|
| Public Methods | |
|---|---|
| + | Return a new Date object that is n days later than the current one. |
| - | If x is a Numeric value, create a new Date object that is x days earlier than the current one. |
| << | Return a new Date object that is n months earlier than the current one. |
| <=> | Compare this date with another date. |
| === | The relationship operator for Date. |
| >> | Return a new Date object that is n months later than the current one. |
| _ |
Dump to Marshal format. |
| _ |
Load from Marshall format. |
| _ |
|
| _ |
|
| ajd | Get the date as an Astronomical Julian Day Number. |
| ajd_ |
Convert an Astronomical Julian Day Number to an Astronomical Modified Julian Day Number. |
| ajd_ |
Convert an Astronomical Julian Day Number to a (civil) Julian Day Number. |
| amjd | Get the date as an Astronomical Modified Julian Day Number. |
| amjd_ |
Convert an Astronomical Modified Julian Day Number to an Astronomical Julian Day Number. |
| asctime | alias_method :format, :strftime |
| civil | Create a new Date object for the Civil Date specified by year y, month m, and day-of-month d. |
| civil_ |
Convert a Civil Date to a Julian Day Number. y, m, and d are the year, month, and day of the month. sg specifies the Day of Calendar Reform. |
| commercial | Create a new Date object for the Commercial Date specified by year y, week-of-year w, and day-of-week d. |
| commercial_ |
Convert a Commercial Date to a Julian Day Number. |
| ctime | Alias for #asctime |
| cwday | Get the commercial day of the week of this date. Monday is commercial day-of-week 1; Sunday is commercial day-of-week 7. |
| cweek | Get the commercial week of the year of this date. |
| cwyear | Get the commercial year of this date. See Commercial Date in the introduction for how this differs from the normal year. |
| day | Alias for #mday |
| day_ |
Get any fractional day part of the date. |
| day_ |
Convert a fractional day fr to [hours, minutes, seconds, fraction_of_a_second] |
| downto | Step backward one day at a time until we reach min (inclusive), yielding each date as we go. |
| england | Create a copy of this Date object that uses the English/Colonial Day of Calendar Reform. |
| eql? | Is this Date equal to other? |
| gregorian | Create a copy of this Date object that always uses the Gregorian Calendar. |
| gregorian? | Is the current date new-style (Gregorian Calendar)? |
| gregorian? | Does a given Julian Day Number fall inside the new-style (Gregorian) calendar? |
| gregorian_ |
Is a year a leap year in the Gregorian calendar? |
| hash | Calculate a hash value for this date. |
| inspect | Return internal object state as a programmer-readable string. |
| italy | Create a copy of this Date object that uses the Italian/Catholic Day of Calendar Reform. |
| jd | Get the date as a Julian Day Number. |
| jd | Create a new Date object from a Julian Day Number. |
| jd_ |
Convert a (civil) Julian Day Number to an Astronomical Julian Day Number. |
| jd_ |
Convert a Julian Day Number to a Civil Date. jd is the Julian Day Number. sg specifies the Day of Calendar Reform. |
| jd_ |
Convert a Julian Day Number to a Commercial Date |
| jd_ |
Convert a Julian Day Number to the number of days since the adoption of the Gregorian Calendar (in Italy). |
| jd_ |
Convert a Julian Day Number to a Modified Julian Day Number. |
| jd_ |
Convert a Julian Day Number to an Ordinal Date. |
| jd_ |
Convert a Julian Day Number to the day of the week. |
| julian | Create a copy of this Date object that always uses the Julian Calendar. |
| julian? | Is the current date old-style (Julian Calendar)? |
| julian? | Does a given Julian Day Number fall inside the old-style (Julian) calendar? |
| julian_ |
Is a year a leap year in the Julian calendar? |
| ld | Get the date as the number of days since the Day of Calendar Reform (in Italy and the Catholic countries). |
| ld_ |
Convert a count of the number of days since the adoption of the Gregorian Calendar (in Italy) to a Julian Day Number. |
| leap? | Is this a leap year? |
| mday | Get the day-of-the-month of this date. |
| mjd | Get the date as a Modified Julian Day Number. |
| mjd_ |
Convert a Modified Julian Day Number to a Julian Day Number. |
| mon | Get the month of this date. |
| month | Alias for #mon |
| new | NOTE this is the documentation for the method new!(). If you are reading this as the documentation for new(), that is because rdoc doesn’t fully support the aliasing of the initialize() method. new() is in fact an alias for #civil(): read the documentation for that method instead. |
| new_ |
Create a copy of this Date object using a new Day of Calendar Reform. |
| next | Return a new Date one day after this one. |
| ordinal | Create a new Date object from an Ordinal Date, specified by year y and day-of-year d. d can be negative, in which it counts backwards from the end of the year. No year wraparound is performed, however. An invalid value for d results in an ArgumentError being raised. |
| ordinal_ |
Convert an Ordinal Date to a Julian Day Number. |
| parse | Create a new Date object by parsing from a String, without specifying the format. |
| start | When is the Day of Calendar Reform for this Date object? |
| step | Step the current date forward step days at a time (or backward, if step is negative) until we reach limit (inclusive), yielding the resultant date at each step. |
| strftime | |
| strptime | Create a new Date object by parsing from a String according to a specified format. |
| succ | Alias for #next |
| time_ |
Convert an h hour, min minutes, s seconds period to a fractional day. |
| to_ |
Return the date as a human-readable string. |
| to_ |
|
| today | Create a new Date object representing today. |
| upto | Step forward one day at a time until we reach max (inclusive), yielding each date as we go. |
| valid_ |
Do year y, month m, and day-of-month d make a valid Civil Date? Returns the corresponding Julian Day Number if they do, nil if they don’t. |
| valid_ |
Do year y, week-of-year w, and day-of-week d make a valid Commercial Date? Returns the corresponding Julian Day Number if they do, nil if they don’t. |
| valid_ |
Is jd a valid Julian Day Number? |
| valid_ |
Do the year y and day-of-year d make a valid Ordinal Date? Returns the corresponding Julian Day Number if they do, or nil if they don’t. |
| valid_ |
Do hour h, minute min, and second s constitute a valid time? |
| wday | Get the week day of this date. Sunday is day-of-week 0; Saturday is day-of-week 6. |
| yday | Get the day-of-the-year of this date. |
| year | Get the year of this date. |
| zone_ |
|
| Private Methods | |
|---|---|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| _ |
|
| civil | Get the date as a Civil Date, [year, month, day_of_month] |
| commercial | Get the date as a Commercial Date, [year, week_of_year, day_of_week] |
| complete_ |
|
| emit | |
| emit_ |
|
| emit_ |
|
| emit_ |
|
| emit_ |
|
| emit_ |
|
| emit_ |
|
| emit_ |
|
| fix_ |
|
| fix_ |
|
| hour | Get the hour of this date. |
| jd_ |
|
| min | Get the minute of this date. |
| new_ |
|
| new_ |
|
| next_ |
|
| now | Create a new DateTime object representing the current time. |
| num_ |
|
| offset | |
| once | |
| ordinal | Get the date as an Ordinal Date, [year, day_of_year] |
| rewrite_ |
|
| s3e | |
| sec | Get the second of this date. |
| sec_ |
Get the fraction-of-a-second of this date. The unit is in days. I do NOT recommend you to use this method. |
| time | Get the time of this date as [hours, minutes, seconds, fraction_of_a_second] |
| valid_ |
|
| valid_ |
|
| valid_ |
|
| weeknum | |
| weeknum0 | |
| weeknum1 | |
| weeknum_ |
|
| wnum0 | |
| wnum1 | |
| zone | |
<code/>and<pre/>for code samples.