{"action":"created","issue":{"url":"https://api.github.com/repos/google/protobuf/issues/3986","repository_url":"https://api.github.com/repos/google/protobuf","labels_url":"https://api.github.com/repos/google/protobuf/issues/3986/labels{/name}","comments_url":"https://api.github.com/repos/google/protobuf/issues/3986/comments","events_url":"https://api.github.com/repos/google/protobuf/issues/3986/events","html_url":"https://github.com/google/protobuf/issues/3986","id":278495337,"number":3986,"title":"[Python] Enhancement request: Timestamp from datetime on one line","user":{"login":"arthur-tacca","id":20324099,"avatar_url":"https://avatars1.githubusercontent.com/u/20324099?v=4","gravatar_id":"","url":"https://api.github.com/users/arthur-tacca","html_url":"https://github.com/arthur-tacca","followers_url":"https://api.github.com/users/arthur-tacca/followers","following_url":"https://api.github.com/users/arthur-tacca/following{/other_user}","gists_url":"https://api.github.com/users/arthur-tacca/gists{/gist_id}","starred_url":"https://api.github.com/users/arthur-tacca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arthur-tacca/subscriptions","organizations_url":"https://api.github.com/users/arthur-tacca/orgs","repos_url":"https://api.github.com/users/arthur-tacca/repos","events_url":"https://api.github.com/users/arthur-tacca/events{/privacy}","received_events_url":"https://api.github.com/users/arthur-tacca/received_events","type":"User","site_admin":false},"labels":[{"id":124699533,"url":"https://api.github.com/repos/google/protobuf/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":250677130,"url":"https://api.github.com/repos/google/protobuf/labels/python","name":"python","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":{"login":"anandolee","id":11618033,"avatar_url":"https://avatars0.githubusercontent.com/u/11618033?v=4","gravatar_id":"","url":"https://api.github.com/users/anandolee","html_url":"https://github.com/anandolee","followers_url":"https://api.github.com/users/anandolee/followers","following_url":"https://api.github.com/users/anandolee/following{/other_user}","gists_url":"https://api.github.com/users/anandolee/gists{/gist_id}","starred_url":"https://api.github.com/users/anandolee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anandolee/subscriptions","organizations_url":"https://api.github.com/users/anandolee/orgs","repos_url":"https://api.github.com/users/anandolee/repos","events_url":"https://api.github.com/users/anandolee/events{/privacy}","received_events_url":"https://api.github.com/users/anandolee/received_events","type":"User","site_admin":false},"assignees":[{"login":"anandolee","id":11618033,"avatar_url":"https://avatars0.githubusercontent.com/u/11618033?v=4","gravatar_id":"","url":"https://api.github.com/users/anandolee","html_url":"https://github.com/anandolee","followers_url":"https://api.github.com/users/anandolee/followers","following_url":"https://api.github.com/users/anandolee/following{/other_user}","gists_url":"https://api.github.com/users/anandolee/gists{/gist_id}","starred_url":"https://api.github.com/users/anandolee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anandolee/subscriptions","organizations_url":"https://api.github.com/users/anandolee/orgs","repos_url":"https://api.github.com/users/anandolee/repos","events_url":"https://api.github.com/users/anandolee/events{/privacy}","received_events_url":"https://api.github.com/users/anandolee/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2017-12-01T15:10:33Z","updated_at":"2018-05-04T20:56:43Z","closed_at":null,"author_association":"NONE","body":"The `google.protobuf.Timestamp` well-known type is very much appreciated, but I've found myself often needing to be able to convert a Python `datetime` into a `Timestamp` within an expression (especially in list comprehensions). Of course it is easy to knock up a function to do this:\r\n\r\n    def timestamp_from_datetime(dt):\r\n        ts = Timestamp()\r\n        ts.FromDatetime(dt)\r\n        return ts\r\n\r\nBut it seems a bit annoying to have to do this. Would it be possible to add a facility to do this directly into `Timestamp`? A constructor or static method would be ideal, but even just `return self` in `FromDatetime()` would do (then we could write the above as `Timestamp().FromDatetime(dt)`). The same problem applies to `Duration` from `timedelta`, although I personally have not used that class.\r\n\r\nBy the way, I realised that the only time I come across this is as part of building a larger protobuf object. Getting `datetime` objects to work directly in their constructor would be even better, for my use case at least:\r\n\r\n    my_protobuf = MyProtobufMessage(\r\n        int_field=3,  # fine\r\n        list_of_strings=[\"foo\", \"bar\"],  # fine\r\n        timestamp=datetime.utcnow(),   # error\r\n    )"},"comment":{"url":"https://api.github.com/repos/google/protobuf/issues/comments/386732305","html_url":"https://github.com/google/protobuf/issues/3986#issuecomment-386732305","issue_url":"https://api.github.com/repos/google/protobuf/issues/3986","id":386732305,"user":{"login":"bchurchill","id":640745,"avatar_url":"https://avatars0.githubusercontent.com/u/640745?v=4","gravatar_id":"","url":"https://api.github.com/users/bchurchill","html_url":"https://github.com/bchurchill","followers_url":"https://api.github.com/users/bchurchill/followers","following_url":"https://api.github.com/users/bchurchill/following{/other_user}","gists_url":"https://api.github.com/users/bchurchill/gists{/gist_id}","starred_url":"https://api.github.com/users/bchurchill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bchurchill/subscriptions","organizations_url":"https://api.github.com/users/bchurchill/orgs","repos_url":"https://api.github.com/users/bchurchill/repos","events_url":"https://api.github.com/users/bchurchill/events{/privacy}","received_events_url":"https://api.github.com/users/bchurchill/received_events","type":"User","site_admin":false},"created_at":"2018-05-04T20:56:43Z","updated_at":"2018-05-04T20:56:43Z","author_association":"NONE","body":"Thank you @seperman.  I really wish the documentation was stronger."}}
{"actor":{"display_login":"bchurchill"}}