mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Updating all setter methods on DBDate to return an instance of themselves
This commit is contained in:
parent
60c8996309
commit
3633d6e27f
@ -33,6 +33,7 @@ class DBDate extends DBField
|
|||||||
* @config
|
* @config
|
||||||
* @see DBDateTime::nice_format
|
* @see DBDateTime::nice_format
|
||||||
* @see DBTime::nice_format
|
* @see DBTime::nice_format
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
private static $nice_format = 'd/m/Y';
|
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
|
// 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
|
// saved as NULL in database
|
||||||
$this->value = null;
|
$this->value = null;
|
||||||
return;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo This needs tidy up (what if you only specify a month and a year, for example?)
|
// @todo This needs tidy up (what if you only specify a month and a year, for example?)
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
if (!empty($value['Day']) && !empty($value['Month']) && !empty($value['Year'])) {
|
if (!empty($value['Day']) && !empty($value['Month']) && !empty($value['Year'])) {
|
||||||
$this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day'];
|
$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
|
// Default to NZ date format - strtotime expects a US date
|
||||||
@ -67,12 +69,11 @@ class DBDate extends DBField
|
|||||||
try {
|
try {
|
||||||
$date = new DateTime($value);
|
$date = new DateTime($value);
|
||||||
$this->value = $date->format('Y-m-d');
|
$this->value = $date->format('Y-m-d');
|
||||||
return;
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->value = null;
|
$this->value = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user