beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

Prevent date overflow in Assertion::date() by reset preset date value #250

Closed lefb766 closed 6 years ago

lefb766 commented 6 years ago

This PR fixes a date format assertion bug or gotcha caused by DateTime::createFromFormat().

For example, Assertion::date('2018-04', 'Y-m') would throw in May 31 2018. See https://stackoverflow.com/questions/21473817/wrong-month-february-datetimecreatefromformat#21473903.

The applied solution was prepending '!' to user specified format before passing it to createFromFormat(). Apparently, it's not a problem if we have duplicated '!' s in a format string.