ENHANCEMENT SSDatetime->setValue() can now set a timestamp, consistently working the same as Date does

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@77120 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-05-19 00:35:15 +00:00
parent a4cf64f105
commit 5322ecc692

View File

@ -12,13 +12,18 @@
* @subpackage model
*/
class SSDatetime extends Date {
function setValue($value) {
// Default to NZ date format - strtotime expects a US date
if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts))
if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) {
$value = "$parts[2]/$parts[1]/$parts[3]";
if($value) $this->value = date('Y-m-d H:i:s', strtotime($value));
else $value = null;
}
if(is_numeric($value)) {
$this->value = date('Y-m-d H:i:s', $value);
} elseif(is_string($value)) {
$this->value = date('Y-m-d H:i:s', strtotime($value));
}
}
function Nice() {