Closed
Description
The default behavior is to convert MongoDate to string after the requests.
public function setRawAttributes(array $attributes, $sync = false)
{
foreach($attributes as $key => &$value)
{
// Convert MongoId to string
if ($value instanceof MongoId)
{
$value = (string) $value;
}
// Convert MongoDate to string
else if ($value instanceof MongoDate)
{
$value = $this->asDateTime($value)->format('Y-m-d H:i:s');
}
}
parent::setRawAttributes($attributes, $sync);
}
Why ? If we save a date as a MongoDate, it is to be able to make operation on this field. For example, detect the number of days since a start date.
Today, we have very strange cases like this one :
$program = Program::create('date_start' => new MongoDate());
var_dump($program->date_start);
var_dump(Program::find($program->id)->date_start);
// Output :
class MongoDate#2497 (2) {
public $sec =>
int(1384179623)
public $usec =>
int(0)
}
string(19) "2013-11-11 14:20:23"
And a default string format is not very useful because it is different for each country (I'm french...). Something more useful could be to override the MongoDate __toString
method but I'm not sure that it is the role of this package.
Metadata
Metadata
Assignees
Labels
No labels