Bug Report #3088
Validate::date() doesn't handle dates correctly
| Status: | Closed | Start date: | 07/16/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 100% |
||
| Category: | Core | |||
| Target version: | v3.0.12 | |||
| Resolution: | wontfix | Points: |
Description
Hello !
Validate::date() uses strtotime which doesn't treat correctly dates from other format than US.
Like, in France, the common date format is d/m/Y instead of Y-m-d in USA.
Should it be possible to change this behavior ?
Thanks,
Have a good day ;)
History
Updated by Sam de Freyssinet almost 3 years ago
This is a PHP function and should be treated as such. As with all other uses of strtotime(), the onus is on the developer to ensure that supply dates in a comprehensible format. I recommend using 'd M Y' format, with strtotime() will also be able to parse correctly regardless of the locale.
Updated by Woody Gilk almost 3 years ago
- Status changed from New to Feedback
What would you recommend instead of strtotime? I don't know of a similar function that provides the same flexibility.
Updated by Jeremy Bush almost 3 years ago
The common format in the USA is actually m-d-Y.
Updated by Thomas Lété almost 3 years ago
One possible solution would be providing a second argument which could be used in addition of strptime ([[http://be2.php.net/manual/en/function.strptime.php]])
Updated by Human Internals almost 3 years ago
Do notice that strtotime returns valid dates to other strings such as 'Next Sunday' , '+30 days' etc.
You wouldn't necessarily want to accept these as valid dates.
Updated by Woody Gilk almost 3 years ago
We cannot use strptime because it isn't available on Windows.
Updated by Woody Gilk over 2 years ago
- Status changed from Feedback to Closed
- Resolution set to wontfix
Human Internals wrote:
Do notice that strtotime returns valid dates to other strings such as 'Next Sunday' , '+30 days' etc.
You wouldn't necessarily want to accept these as valid dates.
Those are valid dates though.
I'm closing this as wontfix because there is no better solution presented. Patches welcome.
Updated by Thomas Lété almost 2 years ago
- Status changed from Closed to Feedback
- Target version changed from v3.0.8 to v3.2.0
Hi !
I reopen this bug because I recently used the php DateTime class which could fit the needs of the validation class.
http://be2.php.net/manual/fr/datetime.construct.php
A quick fix could be :
public static function date($str)
{
try
{
$date = new DateTime($str);
}
catch (Exception $e)
{
return false;
}
return true;
}
Please give me your opinion :)
Updated by Isaiah DeRose-Wilson almost 2 years ago
- Status changed from Feedback to Closed
- Target version changed from v3.2.0 to v3.0.12
- % Done changed from 0 to 100