From 3b3b58bda419f54a8236112c835e07fcdb8815c3 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Thu, 21 Feb 2019 15:04:48 +0400 Subject: [PATCH] Refactor regex to locale_helper to be used in other parts of the code. --- application/helpers/locale_helper.php | 6 +++++- application/models/Attribute.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index 51b893848..5a8426f87 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -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); +} +?> \ No newline at end of file diff --git a/application/models/Attribute.php b/application/models/Attribute.php index abbe95292..7b4b329bd 100644 --- a/application/models/Attribute.php +++ b/application/models/Attribute.php @@ -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;