You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've a set of datetimes which for the most part are comparing correctly. One specific one did not compare correctly.
The first date (a) is in Jan of 2017 while the second date (b) is Feb 2017 yet the first datetime is determined to be greater than the second datetime. I've a set of other datetime compares and all came back correctly.
Code to reproduce:
a = Timex.to_datetime({{2017, 1, 23}, {23, 43, 41}})
b = Timex.to_datetime({{2017, 2, 15}, {13, 26, 25}})
IO.puts a > b
>> true
a = Timex.to_datetime({{2017, 1, 23}, {23, 43, 41}})
b = Timex.to_datetime({{2017, 2, 15}, {13, 26, 25}})
IO.puts a < b
>> false
Contextual/System info
$ iex
Erlang/OTP 19 [erts-8.2.2] [source-1ca84a4] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.4.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
mix.exs
{:timex, "~> 3.0"},
{:timex_ecto, "~> 3.0"},
Possible test case
test "datetime compare" do
a = Timex.to_datetime({{2017, 1, 23}, {23, 43, 41}})
b = Timex.to_datetime({{2017, 2, 15}, {13, 26, 25}})
assert a < b
end
The text was updated successfully, but these errors were encountered:
Teifion
changed the title
Greater-than doesn't always evaluate correctly
Datetime compare doesn't always work correctly
Feb 16, 2017
Unfortunately you can't use the comparison operators with structs, as the comparison is done using absolute term order, but the order of fields in a struct are not guaranteed. Timex provides Timex.compare/2 and Timex.compare/3 for this purpose (amongst other functions for comparing/diffing two date/time objects).
I've a set of datetimes which for the most part are comparing correctly. One specific one did not compare correctly.
The first date (a) is in Jan of 2017 while the second date (b) is Feb 2017 yet the first datetime is determined to be greater than the second datetime. I've a set of other datetime compares and all came back correctly.
Code to reproduce:
Contextual/System info
mix.exs
Possible test case
The text was updated successfully, but these errors were encountered: