views:

144

answers:

2

Is there an easy way to determine if a year is a leap year?

+13  A: 

Try:

now = DateTime.now 
flag = Date.leap?( now.year )

From: http://www.ruby-doc.org/stdlib/

Mitch Wheat
Thought this might be in the library, but was not sure.
MikeJ
A: 
is_leap_year = year % 4 == 0 && year % 100 != 0 || year % 400 == 0
Pesto