Name
Date — Date class
Synopsis
Date is a class to represent the calendar date. Date is based on the Julian day number, which is the number of days since midday, January 1st 4713 BC.
Currently we use the Gregorian calendar, but the Julian calendar was used prior to that time (before 1752 in England, for example). The calendar shift date is different in each country. Date class can handle both calendars and arbitrary shift dates.
There’s no relation between Julian day number and Julian calendar; it’s just coincidence.
Required Library
require 'date'
Example
require 'date' # 3000 days after Ruby was born puts Date::new(1993,2,24)+3000, "\n" # 2001-05-13
Included Module
Comparable
Class Methods
Date::exist?(
year, month, day
[,
start
])
Date::exist3?(
year, month, day
[,
start
])
Returns the Julian day number corresponding to the specified
year
,month
, andday
of year, if they are correct. If they aren’t correct, returnsnil
.Date::exist2?(
year, yday
[,
start
])
Returns the Julian day number corresponding to the specified
year
andday
of year, if they are correct. If they aren’t correct, returnsnil
.Date::existw?(
year, week, wday
[,
start
])
Returns the Julian day number corresponding to the specified calendar week-based
year
, calendarweek
, and calendarweekday
, if they are correct. If they aren’t correct, returnsnil
.Date::new(
year, month, day
[,
start
])
Date::new3(
year, month, day
[,
start
])
Creates a
Date
object corresponding to the specifiedyear
,month
, andday
of the month.Date::new1(
jd
[,
start
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.