Refactor regex to locale_helper to be used in other parts of the code.

This commit is contained in:
objecttothis
2019-02-21 15:04:48 +04:00
parent fd99df8c2e
commit 3b3b58bda4
2 changed files with 6 additions and 2 deletions

View File

@@ -497,4 +497,8 @@ function dateformat_bootstrap($php_format)
return strtr($php_format, $SYMBOLS_MATCHING);
}
?>
function valid_datetime($datetime)
{
return preg_match('/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])(?:( [0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/', $datetime);
}
?>

View File

@@ -258,7 +258,7 @@ class Attribute extends CI_Model
foreach($this->db->get()->result_array() as $row)
{
if(!preg_match('/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])(?:( [0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/', $row['attribute_value']))
if(valid_datetime($row['attribute_value']) === FALSE)
{
log_message('ERROR', 'item_id: ' . $row['item_id'] . ' with attribute_value: ' . $row['attribute_value'] . ' cannot be converted to datetime');
$success = FALSE;