mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allow calling Format() on a Time DB field type to specify the formatting type
MINOR Code formatting fixes for Date and Time classes MINOR Added phpDoc comments to methods git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@74786 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
9a5928438a
commit
515f7b1587
@ -79,10 +79,13 @@ class Date extends DBField {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the date formatted using the given PHP formatting string
|
||||
* Return the date using a particular formatting string.
|
||||
*
|
||||
* @param string $format Format code string. e.g. "d M Y"
|
||||
* @return string The date in the requested format
|
||||
*/
|
||||
function Format($formattingString) {
|
||||
if($this->value) return date($formattingString, strtotime($this->value));
|
||||
function Format($format) {
|
||||
if($this->value) return date($format, strtotime($this->value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,6 +307,6 @@ class Date extends DBField {
|
||||
public function scaffoldFormField($title = null, $params = null) {
|
||||
return new DateField($this->name, $title);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -13,17 +13,40 @@ class Time extends DBField {
|
||||
if($value) {
|
||||
if(preg_match( '/(\d{1,2})[:.](\d{2})([ap]m)/', $value, $match )) $this->TwelveHour( $match );
|
||||
else $this->value = date('H:i:s', strtotime($value));
|
||||
} else $value = null;
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a user friendly format for time
|
||||
* in a 12 hour format.
|
||||
*
|
||||
* @return string Time in 12 hour format
|
||||
*/
|
||||
function Nice() {
|
||||
return date('g:ia', strtotime($this->value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a user friendly format for time
|
||||
* in a 24 hour format.
|
||||
*
|
||||
* @return string Time in 24 hour format
|
||||
*/
|
||||
function Nice24() {
|
||||
return date('H:i', strtotime($this->value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the time using a particular formatting string.
|
||||
*
|
||||
* @param string $format Format code string. e.g. "g:ia"
|
||||
* @return string The date in the requested format
|
||||
*/
|
||||
function Format($format) {
|
||||
if($this->value) return date($format, strtotime($this->value));
|
||||
}
|
||||
|
||||
function TwelveHour( $parts ) {
|
||||
$hour = $parts[1];
|
||||
@ -42,5 +65,6 @@ class Time extends DBField {
|
||||
public function scaffoldFormField($title = null, $params = null) {
|
||||
return new TimeField($this->name, $title);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user