Reputation: 81
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
Reputation: 71
date = 'Feb. 29'
begin
DateTime.parse(date)
rescue ArgumentError
DateTime.parse('Feb. 28') if date == 'Feb. 29'
end
Upvotes: 2