I have a class that extends MongoDate
with just a constructor and an overloaded __toString()
.
class MyClass extends MongoDate
{
public function __construct( $param )
{
if( is_a( $param, 'MongoDate' ) )
{
parent::__construct( $param->sec, $param->usec );
}
else if ( is_a( $param, 'DateTime' ))
{
parent::__construct( $param->getTimestamp() );
}
else if( is_string( $param ) )
{
$datetime = new DateTime( $param );
parent::__construct( $datetime->getTimestamp() );
}
else
{
parent::__construct();
}
}
public function __toString()
{
return date( 'D, d M Y H:i', $this->sec );
}
}
The instances of this class are well constructed and before storage have right values.
This class has this form when is stored in MongoDB:
{ "sec" : 1387576800, "usec" : 0 }
Instead of this one that I have when the value is stored with MongoDate:
ISODate("2013-12-30T22:00:00Z")
The code the value is stored with, used in both cases, where $date
is a MyClass
or a MongoDate
:
$query = array( '_id' => $item_id );
$update = array( '$set' => array( $date_field => $date ) );
$collection->update( $query, $update );
Why the class that inherits from MongoDate is not strored as MongoDate is (as ISODate object) and how can I solve it?