I have added a cck field date type to one of my content types. While adding a content, i use the date as "03/31/2001" but I get a validation error saying "The day is invalid". Upon doing some trial and error I find that it is only for dates after 29 that it throws me the validation error. I'm assuming that the validation does not check the month before checking the date, i.e. only for february dates after 28 should be verified.

Please provide a patch or ask me for more details.

Comments

mukesh.agarwal17’s picture

Status: Active » Needs review

found the issue..

Version: 7.x-1.0-alpha2
File: date_api.module
Function: arrayErrors($arr)
Line: 588
Error: When calling the function forceValid for all parts of the date, (in my case - date, month and year), the 4th parameter of the function forceValid is "month" and it should be month of the date that one is checking and not the current month (the month extracted from "now").. same goes with year..

Code modified:

Current Code:
public function arrayErrors($arr) {
$errors = array();
$now = date_now();
foreach ($arr as $part => $value) {
// Avoid false errors when a numeric value is input as a string by forcing it numeric.
$value = intval($value);
if (!empty($value) && $this->forceValid($part, $value, 'now', $now->format('n'), $now->format('Y')) != $value) {

Modified Code:
public function arrayErrors($arr) {
$errors = array();
$now = date_now();
$month = array_key_exists('month', $arr) ? $arr['month'] : $now->format('n');
$year = array_key_exists('year', $arr) ? $arr['year'] : $now->format('Y');
foreach ($arr as $part => $value) {
// Avoid false errors when a numeric value is input as a string by forcing it numeric.
$value = intval($value);
if (!empty($value) && $this->forceValid($part, $value, 'now', $month, $year) != $value) {

and it worked for me.. TADA.. will submit the patch when I find time.. or if the maintainer of the module can make sure that it is handled in the next release, it will be wonderful..

arlinsandbulte’s picture

Status: Needs review » Closed (duplicate)

Duplicate of #1047412: Using date filter in February causes "The day is invalid" error.
There is a patch there too. Perhaps the approaches should be compared.

mukesh.agarwal17’s picture

The patch works perfectly. Thanks!