Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throwing AmbiguousDateException in Carbon::parse()? #425

Closed
pocketarc opened this issue Aug 20, 2015 · 1 comment
Closed

Throwing AmbiguousDateException in Carbon::parse()? #425

pocketarc opened this issue Aug 20, 2015 · 1 comment

Comments

@pocketarc
Copy link

I'm considering making a fork of Carbon to add support for Carbon::parse() to throw an AmbiguousDateException (or something similarly-named) so that it could always be used without fear of misinterpreting dates.

For example, "20-02-2015" is not ambiguous and would be accepted, whereas "10-02-2015" is and would throw an exception, which could then be caught by the application to let the user know that their inputted date could mean multiple dates, and that they should enter it in a different format. Of course, enforcing a specific date format is best (and is what I currently do), but there are situations where it places an unnecessary burden on the user (e.g. importing data where you don't know the date format). In that situation, if most of the dates could be figured out automatically and you only had to ask the user to check a couple of them because they're ambiguous, that would beat forcing users to use a specific format, in my opinion.

I don't know if anyone would find this useful, but I know I would. If I built it and created a thorough suite of unit tests for it, would it be something you think is worth adding to Carbon?

@briannesbitt
Copy link
Owner

Not sure the real use for this. Seems you can almost always enforce a format as you suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants