1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 10:15:28 +02:00

Add a new $database->columnExists() method, plus a couple other unrelated minor adjustments

This commit is contained in:
Ryan Cramer
2020-04-10 12:40:15 -04:00
parent ac7c9da4d1
commit 48bb7c1734
3 changed files with 58 additions and 4 deletions

View File

@@ -2970,7 +2970,7 @@ class Sanitizer extends Wire {
*/
public function date($value, $format = null, array $options = array()) {
$defaults = array(
'returnFormat' => $format, // date format to return in, if different from $dateFormat
'returnFormat' => $format, // date format to return in, if different from $format
'min' => '', // Minimum date allowed (in $dateFormat format, or a unix timestamp)
'max' => '', // Maximum date allowed (in $dateFormat format, or a unix timestamp)
'default' => null, // Default value, if date didn't resolve
@@ -2978,13 +2978,14 @@ class Sanitizer extends Wire {
);
$options = array_merge($defaults, $options);
$datetime = $this->wire('datetime');
$iso8601 = 'Y-m-d H:i:s';
$_value = trim($value); // original value string
if(empty($value)) return $options['default'];
if(!is_string($value) && !is_int($value)) $value = $this->string($value);
if(ctype_digit("$value")) {
// value is in unix timestamp format
// make sure it resolves to a valid date
$value = strtotime(date('Y-m-d H:i:s', (int) $value));
$value = strtotime(date($iso8601, (int) $value));
} else {
/** @var WireDateTime $datetime */
$value = $datetime->stringToTimestamp($value, $format);