diff --git a/forms/TimeField.php b/forms/TimeField.php index f2fea6791..22e243bee 100755 --- a/forms/TimeField.php +++ b/forms/TimeField.php @@ -1,39 +1,38 @@ timeformat = $timeformat; + + if($timeformat) $this->timeformat = $timeformat; } - /** - * Change the setValue to store the time (in a datetime field) - * we store the current date as well (although we don't use it for this field) - */ - function setValue( $val ) { - if( $val ) - $this->value = (date("Y-m-d",time()) . " " . date("H:i",strtotime($val)) ); - else - $this->value = null; + function dataValue() { + return date($this->timeformat,strtotime($this->value)); + } + + function setValue($val) { + $this->value = date($this->timeformat,strtotime($val)); } /** @@ -43,18 +42,6 @@ class TimeField extends TextField { return new TimeField_Readonly( $this->name, $this->title, $this->dataValue(),$this->timeformat); } - /** - * Added to the value of the input, put the date into the format - * specified in the constructer. - */ - function attrValue(){ - if($this->value){ - return date($this->timeformat,strtotime($this->value)); - }else{ - return ""; - } - } - } /** diff --git a/tests/forms/TimeFieldTest.php b/tests/forms/TimeFieldTest.php new file mode 100644 index 000000000..fb8e9fd98 --- /dev/null +++ b/tests/forms/TimeFieldTest.php @@ -0,0 +1,32 @@ +setValue('11pm'); + $this->assertEquals($dateField12h->dataValue(), '11:00pm'); + + $dateField12h->setValue('23:59'); + $this->assertEquals($dateField12h->dataValue(), '11:59pm'); + + $dateField12h->setValue('11:59pm'); + $this->assertEquals($dateField12h->dataValue(), '11:59pm'); + } + + function testDataValue24h() { + $dateField24h = new TimeField('Time', 'Time', null, 'H:i'); + + $dateField24h->setValue('11pm'); + $this->assertEquals($dateField24h->dataValue(), '23:00'); + + $dateField24h->setValue('23:59'); + $this->assertEquals($dateField24h->dataValue(), '23:59'); + + $dateField24h->setValue('11:59pm'); + $this->assertEquals($dateField24h->dataValue(), '23:59'); + } +} \ No newline at end of file