Skip to content

Commit

Permalink
Allow usage of milliseconds/microseconds in TIMESTAMP and TIME column…
Browse files Browse the repository at this point in the history
…s using sqlType="DATETIME(6)"

Example:

  $dateTime = \DateTime::createFromFormat('U.u', microtime(true));
  $status->setCreatedAt($dateTime);
  • Loading branch information
marcj committed Apr 20, 2016
1 parent c0a0d21 commit 4911238
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1722,10 +1722,10 @@ protected function addTemporalMutator(&$script, Column $col)
$format = 'Y-m-d';
break;
case 'TIME':
$format = 'H:i:s';
$format = 'H:i:s.u';
break;
default:
$format = 'Y-m-d H:i:s';
$format = 'Y-m-d H:i:s.u';
}
$script .= "
if (\$this->{$clo} === null || \$dt === null || \$dt->format(\"$format\") !== \$this->{$clo}->format(\"$format\")) {";
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Platform/DefaultPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ public function getPhpArrayString($stringValue)
*/
public function getTimestampFormatter()
{
return 'Y-m-d H:i:s';
return 'Y-m-d H:i:s.u';
}

/**
Expand All @@ -1292,7 +1292,7 @@ public function getTimestampFormatter()
*/
public function getTimeFormatter()
{
return 'H:i:s';
return 'H:i:s.u';
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/Propel/Generator/Platform/MysqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,6 @@ public function doQuoting($text)
return '`' . strtr($text, ['.' => '`.`']) . '`';
}

public function getTimestampFormatter()
{
return 'Y-m-d H:i:s';
}

public function getColumnBindingPHP(Column $column, $identifier, $columnValueAccessor, $tab = " ")
{
// FIXME - This is a temporary hack to get around apparent bugs w/ PDO+MYSQL
Expand Down

0 comments on commit 4911238

Please sign in to comment.