Updating all setter methods on DBDate to return an instance of themselves

This commit is contained in:
Joe Harvey 2017-01-24 15:55:35 +00:00
parent 60c8996309
commit 3633d6e27f

View File

@ -33,6 +33,7 @@ class DBDate extends DBField
* @config
* @see DBDateTime::nice_format
* @see DBTime::nice_format
* @return $this
*/
private static $nice_format = 'd/m/Y';
@ -42,18 +43,19 @@ class DBDate extends DBField
// don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be
// saved as NULL in database
$this->value = null;
return;
return $this;
}
// @todo This needs tidy up (what if you only specify a month and a year, for example?)
if (is_array($value)) {
if (!empty($value['Day']) && !empty($value['Month']) && !empty($value['Year'])) {
$this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day'];
return;
} else {
// return nothing (so checks below don't fail on an empty array)
return null;
}
/*
* return $this whether successfully set values from array based
* input or not (so checks below don't fail on an empty array)
*/
return $this;
}
// Default to NZ date format - strtotime expects a US date
@ -67,12 +69,11 @@ class DBDate extends DBField
try {
$date = new DateTime($value);
$this->value = $date->format('Y-m-d');
return;
} catch (Exception $e) {
$this->value = null;
return;
}
}
return $this;
}
/**