{"action":"closed","issue":{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/244","repository_url":"https://api.github.com/repos/mongodb/mongo-php-driver","labels_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/244/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/244/comments","events_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/244/events","html_url":"https://github.com/mongodb/mongo-php-driver/issues/244","id":137080970,"number":244,"title":"Unable to safe convert time formats from PHP to UTCDateTime","user":{"login":"jakubboucek","id":1657322,"avatar_url":"https://avatars.githubusercontent.com/u/1657322?v=3","gravatar_id":"","url":"https://api.github.com/users/jakubboucek","html_url":"https://github.com/jakubboucek","followers_url":"https://api.github.com/users/jakubboucek/followers","following_url":"https://api.github.com/users/jakubboucek/following{/other_user}","gists_url":"https://api.github.com/users/jakubboucek/gists{/gist_id}","starred_url":"https://api.github.com/users/jakubboucek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakubboucek/subscriptions","organizations_url":"https://api.github.com/users/jakubboucek/orgs","repos_url":"https://api.github.com/users/jakubboucek/repos","events_url":"https://api.github.com/users/jakubboucek/events{/privacy}","received_events_url":"https://api.github.com/users/jakubboucek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-28T18:38:02Z","updated_at":"2016-02-29T09:40:23Z","closed_at":"2016-02-29T09:40:23Z","body":"PHP native work with time like an integer timestamp, that mean **seconds** from epoch.\r\nMongo (and other Javascript based apps) use the same principle, but base unit is **milliseconds**.\r\n\r\nIn a previous version of Mongo driver [class `MongoDate` work with native PHP format](https://secure.php.net/manual/en/class.mongodate.php) and doing convert to Mongo's milliseconds safe without the user's wishes.\r\n\r\nThis driver doesn't provide safe way to convert PHP date format to Mongo format, [`UTCDateTime` is expect input as milliseconds](https://secure.php.net/manual/en/class.mongodb-bson-utcdatetime.php) and user must keep it in mind and always do this useless multiplication: http://stackoverflow.com/a/34906712/1641372\r\n\r\nAnd in addition, I can not extend `UTCDateTime` because method `__construct` is marked as `final`. Is no another way how to use clean and directly time in Mongo. \r\n\r\nExpexted way:\r\n```php\r\npublic function addItem( $title, \\DateTime $date ) {\r\n\t$data = [\r\n\t\t'title' => $title,\r\n\t\t'created_date' => new UTCDateTime( $date )\r\n\t];\r\n\t$this->anyCollection->insertOne( $data );\r\n}\r\n```\r\nBut it doesn't works. I must use this stupid way **everywhere I am work with date in Mongo**:\r\n```php\r\n...\r\n\t\t'created_date' => new UTCDateTime( $date->toTimestamp() *1000 )\r\n...\r\n```\r\n\r\nI tried to expand `UTCDateTime` and replace `__construct` by my own implementation like a:\r\n```php\r\nclass CustomUTCDateTime extends \\MongoDB\\BSON\\UTCDateTime {\r\n\tpublic __construct ( \\DateTime $date ) {\r\n\t\tparent::__construct( $date->toTimestamp() *1000 );\r\n\t}\r\n}\r\n\r\npublic function addItem( $title, \\DateTime $date ) {\r\n\t$data = [\r\n\t\t'title' => $title,\r\n\t\t'created_date' => new CustomUTCDateTime( $date )\r\n\t];\r\n\t$this->anyCollection->insertOne( $data );\r\n}\r\n``` \r\nBut I can't – `__construct` is `final` :-(\r\n\r\nI think: safe converting values between environments is one of the important jobs for drivers.\r\n\r\nCan you please to help me find safe way to using time with your driver? Or allow to overrides driver's methods."}}