verify: add the dateSQL check

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3565 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-05-03 13:41:49 +00:00
parent 0df7e1bded
commit 4ea1128595

View File

@@ -158,7 +158,7 @@ class verify
/////////////// ///////////////
// DATES // // DATES //
/////////////// ///////////////
/** Check if $val is a valid date /** Check if $val is a valid date and time in SQL
A valid date is 2014-03-20 12:27:34 A valid date is 2014-03-20 12:27:34
Return true or false Return true or false
@param string $val The date to check */ @param string $val The date to check */
@@ -167,7 +167,7 @@ class verify
return \verify::staticIs_datetimeSQL ($val); return \verify::staticIs_datetimeSQL ($val);
} }
/** Check if $val is a valid date in static mode /** Check if $val is a valid date and time in SQL in static mode
A valid date is 2014-03-20 12:27:34 A valid date is 2014-03-20 12:27:34
Return true or false Return true or false
@param string $val The date to check */ @param string $val The date to check */
@@ -175,7 +175,7 @@ class verify
{ {
if (strlen ($val) !== 19) if (strlen ($val) !== 19)
return false; return false;
$arr = date_parse ($val); $arr = \date_parse ($val);
if ($arr["warning_count"] !==0) if ($arr["warning_count"] !==0)
return false; return false;
if ($arr["error_count"] !==0) if ($arr["error_count"] !==0)
@@ -189,6 +189,37 @@ class verify
return true; return true;
} }
/** Check if $val is a valid date in SQL
A valid date is 2014-03-20
Return true or false
@param string $val The date to check */
public function is_dateSQL ($val)
{
return \verify::staticIs_dateSQL ($val);
}
/** Check if $val is a valid date in SQL in static mode
A valid date is 2014-03-20
Return true or false
@param string $val The date to check */
public static function staticIs_dateSQL ($val)
{
if (strlen ($val) !== 10)
return false;
$arr = \date_parse ($val);
if ($arr["warning_count"] !==0)
return false;
if ($arr["error_count"] !==0)
return false;
if (isset ($arr["tz_abbr"]))
return false;
if (strspn ($val, "0123456789-") !== strlen ($val))
return false;
if (\DateTime::createFromFormat("Y-m-d", $val) === false)
return false;
return true;
}
///////////////// /////////////////
// NUMBERS // // NUMBERS //
///////////////// /////////////////