Open kirc0de opened 3 years ago
The same problem with -
instead of /
.
So I tried to change test case:
public function it_checks_expiration_date()
{
// ...
$this->assertTrue($this->dateValidator('02-18', 'MM-YY')->passes());
// ...
}
And it fails :–(.
This 02-18
value and MM-YY
format are from examples in README.md, but this do not work.
I found the source of my problems: there is incorrect format. The right one is Carbon::createFromFormat('m/y', '06/23')
. Need to fix it in README.md
and change MM-YY
format there.
I can fix readme. But what to do with Carbon::parse()
and its exception? What do you think?
I just ran into this issue because I wanted to use the 'm/Y' format. The Carbon::parse() doesn't do anything helpful. I ended up having to abandon this validation for regex/date_format/after validations.
I think that line was added because it blocks a string like '3/22' without a leading zero because there is no way to enforce checking for the leading 0 with the date parsing in PHP. The only way I can thing to fix that is by doing a string comparison of the string to be parsed to the result formatted back. Unfortunately, then formats that you want to have match leading 0 not required but allowed wouldn't be reliable.
I'm trying to do like this:
When the lib tun
passes()
method it runs inside and throw an Exception:There are no ways to disable this parsing or etc.
What do you think about this bug/feature? :–)