2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Represents a column in the database with the type 'Time'
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Time extends DBField {
|
|
|
|
|
2008-10-16 10:44:32 +02:00
|
|
|
function setValue($value) {
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
if($value) {
|
|
|
|
if(preg_match( '/(\d{1,2})[:.](\d{2})([ap]m)/', $value, $match )) $this->_12Hour( $match );
|
|
|
|
else $this->value = date('H:i:s', strtotime($value));
|
|
|
|
} else $value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setValue($value) {
|
2008-10-16 10:44:32 +02:00
|
|
|
return $this->setValue( $value );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Nice() {
|
|
|
|
return date('g:ia', strtotime($this->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
function Nice24() {
|
|
|
|
return date('H:i', strtotime($this->value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-17 03:07:26 +02:00
|
|
|
function TwelveHour( $parts ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$hour = $parts[1];
|
|
|
|
$min = $parts[2];
|
|
|
|
$half = $parts[3];
|
|
|
|
|
|
|
|
$this->value = (( $half == 'pm' ) ? $hour + 12 : $hour ) .":$min:00";
|
|
|
|
}
|
|
|
|
|
|
|
|
function requireField() {
|
|
|
|
DB::requireField($this->tableName, $this->name, "time");
|
|
|
|
}
|
2008-08-06 04:43:46 +02:00
|
|
|
|
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 TimeField($this->name, $title);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
?>
|