{"action":"opened","issue":{"url":"https://api.github.com/repos/lifthrasiir/rust-chrono/issues/104","repository_url":"https://api.github.com/repos/lifthrasiir/rust-chrono","labels_url":"https://api.github.com/repos/lifthrasiir/rust-chrono/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/lifthrasiir/rust-chrono/issues/104/comments","events_url":"https://api.github.com/repos/lifthrasiir/rust-chrono/issues/104/events","html_url":"https://github.com/lifthrasiir/rust-chrono/issues/104","id":184756659,"number":104,"title":"Convert DateTime<Local> to DateTime<FixedOffset>","user":{"login":"canndrew","id":5555066,"avatar_url":"https://avatars.githubusercontent.com/u/5555066?v=3","gravatar_id":"","url":"https://api.github.com/users/canndrew","html_url":"https://github.com/canndrew","followers_url":"https://api.github.com/users/canndrew/followers","following_url":"https://api.github.com/users/canndrew/following{/other_user}","gists_url":"https://api.github.com/users/canndrew/gists{/gist_id}","starred_url":"https://api.github.com/users/canndrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/canndrew/subscriptions","organizations_url":"https://api.github.com/users/canndrew/orgs","repos_url":"https://api.github.com/users/canndrew/repos","events_url":"https://api.github.com/users/canndrew/events{/privacy}","received_events_url":"https://api.github.com/users/canndrew/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-24T06:09:12Z","updated_at":"2016-10-24T06:09:12Z","closed_at":null,"body":"Sorry if this is a silly question but I can't for the life of me figure out a better way to do this. I have a `DateTime<Local>` and I want to convert it to the equivalent `DateTime<FixedOffset>` (in the same timezone). Here is the simplest function I can find to implement this:\r\n\r\n```rust\r\nfn local_to_fixed(local_date_time: DateTime<Local>) -> DateTime<FixedOffset> {\r\n    let offset = local_date_time.offset();\r\n    let duration = offset.local_minus_utc();\r\n    let seconds = duration.num_seconds();\r\n    let fixed_offset = FixedOffset::east(seconds as i32);\r\n    let naive_time = local_date_time.naive_local();\r\n    let fixed_date_time = fixed_offset.from_local_datetime(&naive_time).unwrap();\r\n    fixed_date_time\r\n}\r\n```\r\n\r\nIs there a better way to do this? Maybe some one-liner that doesn't involve truncating subseconds and unwrapping an operation that can maybe(?) fail?"}}
{"actor":{"display_login":"canndrew"}}