{"action":"created","issue":{"url":"https://api.github.com/repos/briannesbitt/Carbon/issues/841","repository_url":"https://api.github.com/repos/briannesbitt/Carbon","labels_url":"https://api.github.com/repos/briannesbitt/Carbon/issues/841/labels{/name}","comments_url":"https://api.github.com/repos/briannesbitt/Carbon/issues/841/comments","events_url":"https://api.github.com/repos/briannesbitt/Carbon/issues/841/events","html_url":"https://github.com/briannesbitt/Carbon/issues/841","id":199235479,"number":841,"title":"[In need of a little guidance] Playing with TZ and DST...","user":{"login":"jpmurray","id":1550428,"avatar_url":"https://avatars1.githubusercontent.com/u/1550428?v=4","gravatar_id":"","url":"https://api.github.com/users/jpmurray","html_url":"https://github.com/jpmurray","followers_url":"https://api.github.com/users/jpmurray/followers","following_url":"https://api.github.com/users/jpmurray/following{/other_user}","gists_url":"https://api.github.com/users/jpmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/jpmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpmurray/subscriptions","organizations_url":"https://api.github.com/users/jpmurray/orgs","repos_url":"https://api.github.com/users/jpmurray/repos","events_url":"https://api.github.com/users/jpmurray/events{/privacy}","received_events_url":"https://api.github.com/users/jpmurray/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-06T16:39:48Z","updated_at":"2018-03-14T17:32:08Z","closed_at":"2018-03-14T17:32:08Z","author_association":"NONE","body":"All right, first things first: i did try to _Google-fu_ my way out of this, but there is so much ideas, and advices, and never a clear answer really, so I decided to try around here hoping that fellow users of Carbon could have encountered the same problematic.\r\n\r\nWhat I'm working with : Laravel, MySQL and Carbon. What I want to get is the date/time a user saves (in local tz, in a point in time), regardless of DST setting at the moment that I fetch the data.\r\n\r\nFor the sake of example, let's say that what I have is a form that a user can enter a date and time for an event in time, and that I know the user's timezone because I stored the user's choice of TZ in the database. How would I achieve a \"DST aware\" getting and setting of date and time? What I currently do is as follow:\r\n\r\nIf today, I store an event for \"Jan 6 at 10am\" (`Jan 6 10:00:00 EST`) in database, I do `Carbon::parse($time, 'America/Toronto')->tz('UTC')->toDatetimeString()` then save to database in a datetime field. The value saved to database is now equivalent to `JAN 6 15:00:00 UTC`. If I try to fetch this value today, or tomorrow, I would do `Carbon::parse($db_value, 'UTC')->tz('America/Toronto')` and work with the data that would then be equivalent to `Jan 6, 10:00:00 EST`.\r\n\r\nBut if I try to fetch the data, say next summer, the DST will be in effect and the date/time returned will be equivalent to `Jan 6 11:00:00 EST`, knowing that PHP's DateTime() (and so I guess Carbon!) is taking care of DST conversion. But what I would really need to have returned is the original date/time that was saved, and not it's value for \"now\" because I need to operate some logic on the time the user gave back when it was saved to database.\r\n\r\nMy first thought was \"just get rid of timezone data altogether\", so an event for Jan 6 at 10am would be saved to database as \"Jan 6 10:00:00 UTC\" and always assume that \"UTC\" is the local timezone, that way I'd just always get the date/time as `Carbon::parse($value, $user_tz)` but it feels... I don't know, clunky?\r\n\r\nAny advice on how to play with this correctly? Was I on the correct path with this last thought?"},"comment":{"url":"https://api.github.com/repos/briannesbitt/Carbon/issues/comments/373108716","html_url":"https://github.com/briannesbitt/Carbon/issues/841#issuecomment-373108716","issue_url":"https://api.github.com/repos/briannesbitt/Carbon/issues/841","id":373108716,"user":{"login":"kylekatarnls","id":5966783,"avatar_url":"https://avatars1.githubusercontent.com/u/5966783?v=4","gravatar_id":"","url":"https://api.github.com/users/kylekatarnls","html_url":"https://github.com/kylekatarnls","followers_url":"https://api.github.com/users/kylekatarnls/followers","following_url":"https://api.github.com/users/kylekatarnls/following{/other_user}","gists_url":"https://api.github.com/users/kylekatarnls/gists{/gist_id}","starred_url":"https://api.github.com/users/kylekatarnls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylekatarnls/subscriptions","organizations_url":"https://api.github.com/users/kylekatarnls/orgs","repos_url":"https://api.github.com/users/kylekatarnls/repos","events_url":"https://api.github.com/users/kylekatarnls/events{/privacy}","received_events_url":"https://api.github.com/users/kylekatarnls/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T17:32:08Z","updated_at":"2018-03-14T17:32:08Z","author_association":"COLLABORATOR","body":"Hi,\r\n\r\nI know it's a bit old but I will answer for acknowledge and close this issue. If you still need, please tell me, I'll re-open.\r\n\r\n`Carbon::parse($time, 'America/Toronto')->tz('UTC')->toDatetimeString()` seems right to me, it's better to store UTC dates.\r\n\r\nBut for DST (with the current version), you will not have such shifting. `JAN 6 15:00:00 UTC` will remain a fixed moment in your DB and setting the TZ on this date, will always produce `Jan 6 10:00:00 EST` because it does not take the current DST but the DST of `JAN 6 15:00:00 UTC`."}}
{"actor":{"display_login":"kylekatarnls"}}