Created
July 29, 2010 09:57
-
-
Save moiristo/497753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gregorian_date?(date) | |
return false if date.nil? | |
(date.month == 2 and date.day == 29) ? Date.gregorian_leap?(date.year) : true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method only returns false when date is nil or when the date is a 'leap date' (so, the 29th of february), while the year is not a gregorian leap year. Imho, there is currently no easy way to do this in ruby, all validation methods in the Date class will say that for example february 29th, 1500 is a valid date, while it isn't according to the gregorian calendar. Used this to solve the PostgreSQL error 'PGError: ERROR: date/time field value out of range', which is thrown when the database server detects an invalid date is passed in a query.