Skip to content

Commit

Permalink
Merge pull request #17 from atabary/master
Browse files Browse the repository at this point in the history
Fix bug in Date.diff/3 with :timestamp
  • Loading branch information
bitwalker committed Oct 3, 2014
2 parents dcdf31b + 1497f74 commit 1862999
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/date/date.ex
Expand Up @@ -18,6 +18,7 @@ defmodule Timex.Date do
"""
require Record
alias Timex.DateTime, as: DateTime
alias Timex.Time, as: Time
alias Timex.Timezone, as: Timezone
alias Timex.TimezoneInfo, as: TimezoneInfo

Expand Down Expand Up @@ -887,7 +888,7 @@ defmodule Timex.Date do
@spec diff(DateTime.t, DateTime.t, :secs | :days | :weeks | :months | :years) :: integer

def diff(this, other, :timestamp) do
diff(this, other, :secs) |> Time.from_sec
diff(this, other, :secs) |> Time.from(:secs)
end
def diff(this, other, :secs) do
to_secs(other, :zero) - to_secs(this, :zero)
Expand Down
2 changes: 2 additions & 0 deletions test/date_test.exs
Expand Up @@ -295,6 +295,8 @@ defmodule DateTests do
assert D.diff(date1, date2, :months) === -D.diff(date2, date1, :months)
assert D.diff(date1, date2, :years) === -D.diff(date2, date1, :years)

assert D.diff(date1, date2, :timestamp) === {0, 63, 158400}

assert D.diff(epoch, date1, :days) === 365
assert D.diff(epoch, date1, :secs) === 365 * 24 * 3600
assert D.diff(epoch, date1, :years) === 1
Expand Down

0 comments on commit 1862999

Please sign in to comment.