Mongolid\Serializer\Type\UTCDateTime::init PHP Method

init() protected method

Initializes timestamp and mongoDate variables.
protected init ( integer | MongoDB\BSON\UTCDateTime | null $datetime ) : boolean
$datetime integer | MongoDB\BSON\UTCDateTime | null MongoUTCDateTime or Timestamp to wrap. If it was null, uses current timestamp.
return boolean
    protected function init($datetime)
    {
        if (is_null($datetime)) {
            $datetime = time();
        }
        if (is_int($datetime)) {
            $this->timestamp = $datetime * 1000;
            $this->mongoDate = new MongoUTCDateTime($this->timestamp);
            return true;
        }
        if ($datetime instanceof MongoUTCDateTime) {
            $this->mongoDate = $datetime;
            $this->timestamp = $datetime->toDateTime()->getTimestamp() * 1000;
            return true;
        }
        return false;
    }