Caio Felipe
Caio Felipe

Reputation: 81

Date invalid Rails leap year

A person was born in 1988 Feb 29 a leap year. How to define this date - 1 day(Feb 28) when the year is not leap?

def valid_date
d = DateTime.parse("Feb. 29")
rescue ArgumentError  
d = "Invalid Date"
end

Upvotes: 2

Views: 492

Answers (1)

Matt Ray
Matt Ray

Reputation: 71

date = 'Feb. 29'
begin
  DateTime.parse(date)
rescue ArgumentError
  DateTime.parse('Feb. 28') if date == 'Feb. 29'
end

Upvotes: 2

Related Questions