mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: an time field input between 12:00pm to 12:59pm can't save back to database or always save as 00:00:00.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84086 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
fbbffb5f90
commit
5c68bb3bde
@ -11,7 +11,7 @@ class Time extends DBField {
|
|||||||
|
|
||||||
function setValue($value) {
|
function setValue($value) {
|
||||||
if($value) {
|
if($value) {
|
||||||
if(preg_match( '/(\d{1,2})[:.](\d{2})([ap]m)/', $value, $match )) $this->TwelveHour( $match );
|
if(preg_match( '/(\d{1,2})[:.](\d{2})([a|A|p|P|][m|M])/', $value, $match )) $this->TwelveHour( $match );
|
||||||
else $this->value = date('H:i:s', strtotime($value));
|
else $this->value = date('H:i:s', strtotime($value));
|
||||||
} else {
|
} else {
|
||||||
$value = null;
|
$value = null;
|
||||||
@ -53,7 +53,8 @@ class Time extends DBField {
|
|||||||
$min = $parts[2];
|
$min = $parts[2];
|
||||||
$half = $parts[3];
|
$half = $parts[3];
|
||||||
|
|
||||||
$this->value = (( $half == 'pm' ) ? $hour + 12 : $hour ) .":$min:00";
|
// the transmation should exclude 12:00pm ~ 12:59pm
|
||||||
|
$this->value = (( (strtolower($half) == 'pm') && $hour != '12') ? $hour + 12 : $hour ) .":$min:00";
|
||||||
}
|
}
|
||||||
|
|
||||||
function requireField() {
|
function requireField() {
|
||||||
|
@ -70,6 +70,28 @@ class DBFieldTest extends SapphireTest {
|
|||||||
$this->assertEquals("'0'", singleton('Text')->prepValueForDB(0000));
|
$this->assertEquals("'0'", singleton('Text')->prepValueForDB(0000));
|
||||||
$this->assertEquals("'test'", singleton('Text')->prepValueForDB('test'));
|
$this->assertEquals("'test'", singleton('Text')->prepValueForDB('test'));
|
||||||
$this->assertEquals("'123'", singleton('Text')->prepValueForDB(123));
|
$this->assertEquals("'123'", singleton('Text')->prepValueForDB(123));
|
||||||
|
|
||||||
|
/* Time behaviour */
|
||||||
|
$time = singleton('Time');
|
||||||
|
$time->setValue('00:01am');
|
||||||
|
$this->assertEquals("00:01:00", $time->getValue());
|
||||||
|
$time->setValue('00:59am');
|
||||||
|
$this->assertEquals("00:59:00", $time->getValue());
|
||||||
|
$time->setValue('11:59am');
|
||||||
|
$this->assertEquals("11:59:00", $time->getValue());
|
||||||
|
$time->setValue('12:00pm');
|
||||||
|
$this->assertEquals("12:00:00", $time->getValue());
|
||||||
|
$time->setValue('12:59am');
|
||||||
|
$this->assertEquals("12:59:00", $time->getValue());
|
||||||
|
$time->setValue('1:00pm');
|
||||||
|
$this->assertEquals("13:00:00", $time->getValue());
|
||||||
|
$time->setValue('11:59pm');
|
||||||
|
$this->assertEquals("23:59:00", $time->getValue());
|
||||||
|
$time->setValue('00:00am');
|
||||||
|
$this->assertEquals("00:00:00", $time->getValue());
|
||||||
|
$time->setValue('00:00:00');
|
||||||
|
$this->assertEquals("00:00:00", $time->getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user