{"action":"created","issue":{"url":"https://api.github.com/repos/haskell/time/issues/53","repository_url":"https://api.github.com/repos/haskell/time","labels_url":"https://api.github.com/repos/haskell/time/issues/53/labels{/name}","comments_url":"https://api.github.com/repos/haskell/time/issues/53/comments","events_url":"https://api.github.com/repos/haskell/time/issues/53/events","html_url":"https://github.com/haskell/time/issues/53","id":188911886,"number":53,"title":"TimeZone of a LocalTime","user":{"login":"guyonvarch","id":6768842,"avatar_url":"https://avatars.githubusercontent.com/u/6768842?v=3","gravatar_id":"","url":"https://api.github.com/users/guyonvarch","html_url":"https://github.com/guyonvarch","followers_url":"https://api.github.com/users/guyonvarch/followers","following_url":"https://api.github.com/users/guyonvarch/following{/other_user}","gists_url":"https://api.github.com/users/guyonvarch/gists{/gist_id}","starred_url":"https://api.github.com/users/guyonvarch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guyonvarch/subscriptions","organizations_url":"https://api.github.com/users/guyonvarch/orgs","repos_url":"https://api.github.com/users/guyonvarch/repos","events_url":"https://api.github.com/users/guyonvarch/events{/privacy}","received_events_url":"https://api.github.com/users/guyonvarch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-12T13:31:57Z","updated_at":"2016-11-14T05:03:16Z","closed_at":null,"body":"Hello,\r\n\r\nI want the `UTCTime` associated to a `LocalTime`. In order to convert a `LocalTime` to `UTCTime`, I need a `TimeZone`. But I can't figure out how to get the `TimeZone` associated to a `LocalTime`. In the following example, I use `getTimeZone` with the `UTCTime` constructed from the `Day` and `TimeOfDay`, but it does not relate to the same time as the `LocalTime`, that is why I don't get the final `UTCTime` I am searching for.\r\n\r\n``` haskell\r\nimport Data.Time.Clock (UTCTime(..))\r\nimport Data.Time.Calendar (fromGregorian)\r\nimport Data.Time.LocalTime (LocalTime(..), TimeOfDay(..), localTimeToUTC, getTimeZone, timeOfDayToTime)\r\n\r\nmain :: IO ()\r\nmain = do\r\n  let day = fromGregorian 2016 10 30\r\n  let timeOfDay = TimeOfDay 1 0 0\r\n  let localTime = LocalTime day timeOfDay\r\n  timeZone <- getTimeZone (UTCTime day (timeOfDayToTime timeOfDay))\r\n  let utcTime = localTimeToUTC timeZone localTime\r\n  putStrLn (show utcTime)\r\n```\r\n\r\nIt shows `2016-10-30 00:00:00 UTC` but I want `2016-10-29 23:00:00 UTC`. There is no problem with the time library, I just don't know how to get the correct time zone associated with my local time.\r\n\r\nIn France, on 2016-10-30 at 3 o'clock, the hour change and we get back at 2 o'clock. The time zone change from CEST to CET, the time library get this correctly:\r\n\r\n``` haskell\r\ngetTimeZone (UTCTime (fromGregorian 2016 10 30) (timeOfDayToTime (TimeOfDay 0 0 0))) -- 2h in France\r\nCEST\r\ngetTimeZone (UTCTime (fromGregorian 2016 10 30) (timeOfDayToTime (TimeOfDay 1 0 0))) -- 2h in France\r\nCET\r\n```\r\n\r\nI would need a function: \r\n\r\n``` haskell \r\ngetTimeZone :: LocalTime -> IO TimeZone\r\n```\r\n\r\nMy use case for this need is I want to get `UTCTime` at the beginning of the current week and the previous week, for notification purposes. I successfully get local times but can't get for sure correct utc times.\r\n\r\nIs this function missing or am I missing something ?"},"comment":{"url":"https://api.github.com/repos/haskell/time/issues/comments/260249124","html_url":"https://github.com/haskell/time/issues/53#issuecomment-260249124","issue_url":"https://api.github.com/repos/haskell/time/issues/53","id":260249124,"user":{"login":"AshleyYakeley","id":5609617,"avatar_url":"https://avatars.githubusercontent.com/u/5609617?v=3","gravatar_id":"","url":"https://api.github.com/users/AshleyYakeley","html_url":"https://github.com/AshleyYakeley","followers_url":"https://api.github.com/users/AshleyYakeley/followers","following_url":"https://api.github.com/users/AshleyYakeley/following{/other_user}","gists_url":"https://api.github.com/users/AshleyYakeley/gists{/gist_id}","starred_url":"https://api.github.com/users/AshleyYakeley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AshleyYakeley/subscriptions","organizations_url":"https://api.github.com/users/AshleyYakeley/orgs","repos_url":"https://api.github.com/users/AshleyYakeley/repos","events_url":"https://api.github.com/users/AshleyYakeley/events{/privacy}","received_events_url":"https://api.github.com/users/AshleyYakeley/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T05:03:16Z","updated_at":"2016-11-14T05:03:16Z","body":"AFAICT there's no direct way to do this with the libc time functions. However, it can be done iteratively:\r\n\r\n1. given a `TimeZone` (and your `LocalTime`) get the `UTCTime` (with `localTimeToUTC`)\r\n1. given a `UTCTime`, get the `TimeZone` (with `getTimeZone`)\r\n\r\nIf you start with an arbitrary `TimeZone`, e.g `utc`, the cycle should stabilise in one or two iterations."}}
{"actor":{"display_login":"AshleyYakeley"}}