{"action":"created","issue":{"url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/28","labels_url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/28/comments","events_url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/28/events","html_url":"https://github.com/nicolopignatelli/valueobjects/issues/28","id":58703853,"number":28,"title":"DateTime::fromNativeDateTime should be aware of timezone","user":{"login":"ajgarlag","id":388184,"avatar_url":"https://avatars.githubusercontent.com/u/388184?v=3","gravatar_id":"","url":"https://api.github.com/users/ajgarlag","html_url":"https://github.com/ajgarlag","followers_url":"https://api.github.com/users/ajgarlag/followers","following_url":"https://api.github.com/users/ajgarlag/following{/other_user}","gists_url":"https://api.github.com/users/ajgarlag/gists{/gist_id}","starred_url":"https://api.github.com/users/ajgarlag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajgarlag/subscriptions","organizations_url":"https://api.github.com/users/ajgarlag/orgs","repos_url":"https://api.github.com/users/ajgarlag/repos","events_url":"https://api.github.com/users/ajgarlag/events{/privacy}","received_events_url":"https://api.github.com/users/ajgarlag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-24T07:40:47Z","updated_at":"2015-03-05T07:57:47Z","closed_at":null,"body":"It is possible to build two equals `DateTime` objects from two different native `\\DateTime` objects because the `fromNativeDateTime` ignores the `\\DateTimeZone`.\r\n\r\n```php\r\n$nativeDateTime1 = new \\DateTime('2015-02-23 20:30:00', new \\DateTimeZone('Europe/Madrid'));\r\n$nativeDateTime2 = new \\DateTime('2015-02-23 20:30:00', new \\DateTimeZone('Europe/London'));\r\n\r\n$voDateTime1 = \\ValueObjects\\DateTime\\DateTime::fromNativeDateTime($nativeDateTime1);\r\n$voDateTime2 = \\ValueObjects\\DateTime\\DateTime::fromNativeDateTime($nativeDateTime2);\r\n\r\nvar_dump($voDateTime1->sameValueAs($voDateTime2)); //It should be false, but it is true\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/comments/77321570","html_url":"https://github.com/nicolopignatelli/valueobjects/issues/28#issuecomment-77321570","issue_url":"https://api.github.com/repos/nicolopignatelli/valueobjects/issues/28","id":77321570,"user":{"login":"ajgarlag","id":388184,"avatar_url":"https://avatars.githubusercontent.com/u/388184?v=3","gravatar_id":"","url":"https://api.github.com/users/ajgarlag","html_url":"https://github.com/ajgarlag","followers_url":"https://api.github.com/users/ajgarlag/followers","following_url":"https://api.github.com/users/ajgarlag/following{/other_user}","gists_url":"https://api.github.com/users/ajgarlag/gists{/gist_id}","starred_url":"https://api.github.com/users/ajgarlag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajgarlag/subscriptions","organizations_url":"https://api.github.com/users/ajgarlag/orgs","repos_url":"https://api.github.com/users/ajgarlag/repos","events_url":"https://api.github.com/users/ajgarlag/events{/privacy}","received_events_url":"https://api.github.com/users/ajgarlag/received_events","type":"User","site_admin":false},"created_at":"2015-03-05T07:57:47Z","updated_at":"2015-03-05T07:57:47Z","body":"Well, I'm a very newbie in VO. Here is the problem I see.\r\n\r\nLet's suppose, we decide that two `\\ValueObjects\\DateTime\\DateTime` have the same value if they represent the same timestamp (although it breaks BC).\r\n ```php\r\n$nativeDateTime1 = new \\DateTime('2015-03-05 16:38:21', new \\DateTimeZone('Asia/Tokyo'));\r\n$nativeDateTime2 = new \\DateTime('2015-03-05 02:38:21', new \\DateTimeZone('America/New_York'));\r\nvar_dump($nativeDateTime1 == $nativeDateTime2); // bool(true)\r\n\r\n$voDateTime1 = \\ValueObjects\\DateTime\\DateTime::fromNativeDateTime($nativeDateTime1);\r\n$voDateTime2 = \\ValueObjects\\DateTime\\DateTime::fromNativeDateTime($nativeDateTime2);\r\n```\r\n\r\nNow, if we convert the native DateTime to 'UTC' before extracting values, we have:\r\n```php\r\nvar_dump($voDateTime1->sameValueAs($voDateTime2)); // bool(true)\r\nvar_dump($voDateTime1->getTime()->sameValueAs($voDateTime2->getTime())); // bool(true)\r\n```\r\nBut, if we choose to keep the values from the original timezone, we have :\r\n```php\r\nvar_dump($voDateTime1->sameValueAs($voDateTime2)); // bool(true)\r\nvar_dump($voDateTime1->getTime()->sameValueAs($voDateTime2->getTime())); // bool(false)\r\n```\r\nMaybe, the best option is to introduce a new `DateTimeWithTZ` VO without touching the `DateTime` implementation, so we avoid any BC break, and the user is aware of the consecuences of comparing subvalues of `DateTimeWithTZ`"}}