{"action":"closed","issue":{"url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/issues/942","repository_url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/issues/942/labels{/name}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/issues/942/comments","events_url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/issues/942/events","html_url":"https://github.com/GoogleCloudPlatform/google-cloud-php/issues/942","id":307889211,"number":942,"title":"Spanner: select Timestamp with non-UTC timezone ","user":{"login":"castaneai","id":562795,"avatar_url":"https://avatars2.githubusercontent.com/u/562795?v=4","gravatar_id":"","url":"https://api.github.com/users/castaneai","html_url":"https://github.com/castaneai","followers_url":"https://api.github.com/users/castaneai/followers","following_url":"https://api.github.com/users/castaneai/following{/other_user}","gists_url":"https://api.github.com/users/castaneai/gists{/gist_id}","starred_url":"https://api.github.com/users/castaneai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/castaneai/subscriptions","organizations_url":"https://api.github.com/users/castaneai/orgs","repos_url":"https://api.github.com/users/castaneai/repos","events_url":"https://api.github.com/users/castaneai/events{/privacy}","received_events_url":"https://api.github.com/users/castaneai/received_events","type":"User","site_admin":false},"labels":[{"id":540304835,"url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/labels/api:%20spanner","name":"api: spanner","color":"f8f8f8","default":false},{"id":268638473,"url":"https://api.github.com/repos/GoogleCloudPlatform/google-cloud-php/labels/type:%20question","name":"type: question","color":"c5def5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-23T03:22:13Z","updated_at":"2018-04-30T14:58:33Z","closed_at":"2018-04-30T14:58:33Z","author_association":"NONE","body":"[On Cloud Spanner RPC API, UTC timezone is used and represented as format ends with \"Z\"](https://cloud.google.com/spanner/docs/data-types?hl=en#canonical-format_1), But on PHP client library, `ValueMapperTrait` uses `\\DateTimeImmutable::createFromFormat` and may ignore \"Z\" in timestamp string from gRPC.\r\n\r\n## Test code\r\n\r\n```php\r\n// Asia/Tokyo GMT+09:00\r\ndate_default_timezone_set('Asia/Tokyo');\r\n\r\n/** @var Timestamp $ts */\r\n$ts = $db->execute('SELECT TIMESTAMP(\"2018-01-01T00:00:00.000000Z\")')->rows()->current()[0];\r\n\r\n// OK\r\n$this->assertEquals('Asia/Tokyo', $ts->get()->getTimezone()->getName());\r\n\r\n// NG\r\n$this->assertEquals('2018-01-01 09:00:00.000000+09:00', $ts->get()->format('Y-m-d H:i:s.uP'));\r\n```\r\n\r\n## Result\r\n\r\n```\r\nFailed asserting that two strings are equal.\r\nExpected :'2018-01-01 09:00:00.000000+09:00'\r\nActual   :'2018-01-01 00:00:00.000000+09:00'\r\n```\r\n\r\n## Proposal for fix\r\n\r\n```diff\r\nclass Timestamp\r\n{\r\n-    const FORMAT = 'Y-m-d\\TH:i:s.u\\Z';\r\n+    const FORMAT = 'Y-m-d\\TH:i:s.uP';\r\n```\r\n\r\n```diff\r\n             $dt = \\DateTimeImmutable::createFromFormat(Timestamp::FORMAT, str_replace('..', '.', $timestamp));\r\n+            $dt = $dt->setTimezone(new \\DateTimeZone(date_default_timezone_get()));\r\n\r\n```"}}
{"actor":{"display_login":"jdpedrie"}}