{"action":"closed","issue":{"url":"https://api.github.com/repos/elixir-lang/elixir/issues/6283","repository_url":"https://api.github.com/repos/elixir-lang/elixir","labels_url":"https://api.github.com/repos/elixir-lang/elixir/issues/6283/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/elixir/issues/6283/comments","events_url":"https://api.github.com/repos/elixir-lang/elixir/issues/6283/events","html_url":"https://github.com/elixir-lang/elixir/issues/6283","id":239993996,"number":6283,"title":"DateTime.convert/2 does not preserve target calendar in returned %DateTime{}","user":{"login":"kipcole9","id":15895,"avatar_url":"https://avatars1.githubusercontent.com/u/15895?v=3","gravatar_id":"","url":"https://api.github.com/users/kipcole9","html_url":"https://github.com/kipcole9","followers_url":"https://api.github.com/users/kipcole9/followers","following_url":"https://api.github.com/users/kipcole9/following{/other_user}","gists_url":"https://api.github.com/users/kipcole9/gists{/gist_id}","starred_url":"https://api.github.com/users/kipcole9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kipcole9/subscriptions","organizations_url":"https://api.github.com/users/kipcole9/orgs","repos_url":"https://api.github.com/users/kipcole9/repos","events_url":"https://api.github.com/users/kipcole9/events{/privacy}","received_events_url":"https://api.github.com/users/kipcole9/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-02T07:09:45Z","updated_at":"2017-07-02T08:10:49Z","closed_at":"2017-07-02T08:10:49Z","body":"In Elixir 1.5.0-rc.0  the `DateTime.convert/2` function does not populate the `:calendar` element so all conversions are tagged with the default `Calendar.ISO` thereby producing an incorrect return.\r\n\r\nExample:\r\n```\r\niex> dt1\r\n%DateTime{calendar: Calendar.ISO, day: 29, hour: 23, microsecond: {0, 0},\r\n minute: 0, month: 2, second: 7, std_offset: 0, time_zone: \"America/Manaus\",\r\n utc_offset: -14400, year: 2000, zone_abbr: \"AMT\"}\r\niex> DateTime.convert(dt1, Calendrical.Calendar.Julian)\r\n{:ok,\r\n %DateTime{calendar: Calendar.ISO, day: 16, hour: 23, microsecond: {0, 6},\r\n  minute: 0, month: 2, second: 7, std_offset: 0, time_zone: \"America/Manaus\",\r\n  utc_offset: -14400, year: 2000, zone_abbr: \"AMT\"}}\r\n```\r\nNote that the conversion has been performed correctly but the calendar is not tagged with the target.\r\n\r\nThe relevant source is (line 626 in date_time.ex)\r\n\r\n```\r\n  defp from_rata_die(rata_die, time_zone, zone_abbr, utc_offset, std_offset, calendar) do\r\n    {year, month, day, hour, minute, second, microsecond} = calendar.naive_datetime_from_rata_die(rata_die)\r\n    %DateTime{year: year, month: month, day: day,\r\n              hour: hour, minute: minute, second: second, microsecond: microsecond,\r\n              time_zone: time_zone, zone_abbr: zone_abbr, utc_offset: utc_offset, std_offset: std_offset}\r\n  end\r\n```\r\nThe fix is simple and I'll open and PR with a test if thats helpful:\r\n\r\n```  \r\ndefp from_rata_die(rata_die, time_zone, zone_abbr, utc_offset, std_offset, calendar) do\r\n    {year, month, day, hour, minute, second, microsecond} = calendar.naive_datetime_from_rata_die(rata_die)\r\n    %DateTime{year: year, month: month, day: day,\r\n              hour: hour, minute: minute, second: second, microsecond: microsecond,\r\n              time_zone: time_zone, zone_abbr: zone_abbr, utc_offset: utc_offset, std_offset: std_offset\r\n              calendar: calendar}\r\n  end\r\n```\r\n"}}
{"actor":{"display_login":"kipcole9"}}