Hi,
If you create a database table with a 4 digit DATE field, the CMS will not accept any entry other than '0000'. The problem seems to be in the line 'if (strncmp($value, '0000', 4) !== 0)' in the 'auto_validate_field' function in MY_Model.php. I have replaced it with 'if (strlen($value) !== 4' but perhaps a 'preg_match' call would be a better solution.
Regards,
Chris.
Comments
Chris.
case 'date':
$valid_date = TRUE;
if ($field_data['type'] == 'year')
{
$reg_exp = $field_data['max_length'] == 4 ? '/(19|20)\d\d$/' : '/\d\d$/';
$valid_date = preg_match($reg_exp, $value);
}
else
{
$valid_date = (strncmp($value, '0000', 4) === 0);
}
if ($valid_date == FALSE)
{
$this->validator->add_rule($field, 'valid_date', "Invalid date for ".$field_name, $value);
if ($field_data['type'] == 'datetime') $this->validator->add_rule($field, 'valid_time', "Invalid time for ".$field_name, $value);
}
break;
Chris.
http://dev.mysql.com/doc/refman/5.1/en/year.html
Chris.
Given that it was "semi" I tried to update using the GitHUB code. Now if one updates the time field, the date field gets zero'd out. I assume that this is the bug described above. You don't have to change it to get it zero'd -- it always happens
It looks as though the time field now works.
I've added a datetime field since I need a fix. It appears to work --I did at least basic testing.
So three observations that might help:
1. June date code worked, June time code had issues
2. 7 months ago update works for time but not date
3. Datetime seems to be OK
4. June version of date and time is in general less fatal than the 7 months ago version
I'm recoding to datetime field ... but I know not everyone has that option...
I've gone back to the older code -- it appears to have been cleaner -- just needed the time field fixed.