2007-08-18 04:33:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Represents a date-time field.
|
2009-04-02 19:17:04 +02:00
|
|
|
* The field currently supports New Zealand date format (DD/MM/YYYY),
|
|
|
|
* or an ISO 8601 formatted date and time (Y-m-d H:i:s).
|
|
|
|
* Alternatively you can set a timestamp that is evaluated through
|
|
|
|
* PHP's built-in date() and strtotime() function according to your system locale.
|
|
|
|
*
|
|
|
|
* @todo Add localization support, see http://open.silverstripe.com/ticket/2931
|
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
2007-08-18 04:33:28 +02:00
|
|
|
class SSDatetime extends Date {
|
2009-05-19 02:35:15 +02:00
|
|
|
|
2007-08-18 04:33:28 +02:00
|
|
|
function setValue($value) {
|
2009-05-18 23:24:33 +02:00
|
|
|
// Default to NZ date format - strtotime expects a US date
|
2009-05-19 02:35:15 +02:00
|
|
|
if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) {
|
2009-05-18 23:24:33 +02:00
|
|
|
$value = "$parts[2]/$parts[1]/$parts[3]";
|
2009-05-19 02:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2007-08-18 04:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Nice() {
|
|
|
|
return date('d/m/Y g:ia', strtotime($this->value));
|
|
|
|
}
|
|
|
|
function Nice24() {
|
|
|
|
return date('d/m/Y H:i', strtotime($this->value));
|
|
|
|
}
|
|
|
|
function Date() {
|
|
|
|
return date('d/m/Y', strtotime($this->value));
|
|
|
|
}
|
|
|
|
function Time() {
|
|
|
|
return date('g:ia', strtotime($this->value));
|
|
|
|
}
|
|
|
|
function Time24() {
|
|
|
|
return date('H:i', strtotime($this->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
function requireField() {
|
2008-11-23 02:01:03 +01:00
|
|
|
$parts=Array('datatype'=>'datetime');
|
|
|
|
$values=Array('type'=>'ssdatetime', 'parts'=>$parts);
|
|
|
|
DB::requireField($this->tableName, $this->name, $values);
|
2007-08-18 04:33:28 +02:00
|
|
|
}
|
|
|
|
|
2007-10-29 01:55:52 +01:00
|
|
|
function URLDatetime() {
|
|
|
|
return date('Y-m-d%20H:i:s', strtotime($this->value));
|
|
|
|
}
|
|
|
|
|
2008-10-14 00:20:41 +02:00
|
|
|
public function scaffoldFormField($title = null, $params = null) {
|
2008-08-06 04:43:46 +02:00
|
|
|
return new PopupDateTimeField($this->name, $title);
|
2007-08-18 04:33:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|