Fix mysql datetime format

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-08 14:26:37 +02:00
parent 3bd32e6c0d
commit a5b566edd0
4 changed files with 32 additions and 4 deletions

View File

@@ -42,6 +42,8 @@ class Card extends RelationalEntity implements JsonSerializable {
protected $archived = false;
protected $duedate = null;
private $databaseType = 'sqlite';
const DUEDATE_FUTURE = 0;
const DUEDATE_NEXT = 1;
const DUEDATE_NOW = 2;
@@ -58,10 +60,17 @@ class Card extends RelationalEntity implements JsonSerializable {
$this->addResolvable('owner');
}
public function getDuedate() {
public function setDatabaseType($type) {
$this->databaseType = $type;
}
public function getDuedate($isoFormat = false) {
if($this->duedate === null)
return null;
$dt = new DateTime($this->duedate);
if (!$isoFormat && $this->databaseType === 'mysql') {
return $dt->format('Y-m-d H:i:s');
}
return $dt->format('c');
}
@@ -91,7 +100,7 @@ class Card extends RelationalEntity implements JsonSerializable {
$json['overdue'] = self::DUEDATE_OVERDUE;
}
}
$json['duedate'] = $this->getDuedate();
$json['duedate'] = $this->getDuedate(true);
return $json;
}