Skip to content

Commit

Permalink
Merge pull request #15 from atabary/master
Browse files Browse the repository at this point in the history
Fixed #14. Date.local does not shift the date properly.
  • Loading branch information
bitwalker committed Sep 22, 2014
2 parents de73670 + fba8a44 commit c15d667
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/date/date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ defmodule Timex.Date do
@spec local(date :: DateTime.t, tz :: TimezoneInfo.t) :: DateTime.t
def local(%DateTime{:timezone => tz} = date, localtz) do
if tz !== localtz do
Timezone.convert(date, localtz)
%{date | :timezone => localtz}
new_date = Timezone.convert(date, localtz)
%{new_date | :timezone => localtz}
else
date
end
Expand Down
12 changes: 12 additions & 0 deletions test/date_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ defmodule DateTests do
assert uni === D.universal(unidate)
end

test "local/2" do
uni_dt = D.from({{2014, 9, 22}, {12, 0, 0}})
assert uni_dt.hour === 12
assert uni_dt.minute === 0
assert uni_dt.timezone === D.timezone("UTC")

local_dt = D.local(uni_dt, D.timezone("JST"))
assert local_dt.hour === 21
assert local_dt.minute === 0
assert local_dt.timezone === D.timezone("JST")
end

test :zero do
zero = D.zero
{ date, time, tz } = zero |> DateConvert.to_gregorian
Expand Down

0 comments on commit c15d667

Please sign in to comment.