End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Date#leap?
d.leap? → bool
ext/date/date_core.c
View on GitHub ↗
static VALUE
d_lite_leap_p(VALUE self)
{
int rjd, ns, ry, rm, rd;
get_d1(self);
if (m_gregorian_p(dat))
return f_boolcast(c_gregorian_leap_p(m_year(dat)));
c_civil_to_jd(m_year(dat), 3, 1, m_virtual_sg(dat),
&rjd, &ns);
c_jd_to_civil(rjd - 1, m_virtual_sg(dat), &ry, &rm, &rd);
return f_boolcast(rd == 29);
}
Returns true if the year is a leap year.
Example
Date.new(2000).leap? #=> true Date.new(2001).leap? #=> false