Skip to content

Commit

Permalink
Fix Money.within/2 when min and max are the same. Closes #177
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jan 22, 2025
1 parent 7dcf61c commit 7e0e017
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

**Note** `ex_money` 5.17.0 and later is supported on Elixir 1.12 and later versions only.

## Money v5.19.1

This is the changelog for Money v5.19.1 released on January 22nd, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)

### Bux Fixes

* Fixes `Money.within/3` when `min` and `max` are the same. Thanks to @joewunderlich for the report. Closes #177.

## Money v5.19.0

This is the changelog for Money v5.19.0 released on January 1st, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)
This is the changelog for Money v5.19.0 released on January 1st, 2025. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)

### Deprecations

Expand Down
8 changes: 7 additions & 1 deletion lib/money.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,12 @@ defmodule Money do
iex> Money.within?(Money.new(:USD, 10), Money.new(:USD, 50), Money.new(:USD, 200))
false
iex> Money.within?(Money.new(:USD, 10), Money.new(:USD, 50), Money.new(:USD, 50))
false
iex> Money.within?(Money.new(:USD, 50), Money.new(:USD, 50), Money.new(:USD, 50))
true
iex> Money.within?(Money.new(:USD, 100), Money.new(:USD, 300), Money.new(:USD, 200))
** (ArgumentError) Minimum must be less than maximum. Found Money.new(:USD, "300") and Money.new(:USD, "200")
Expand All @@ -1570,7 +1576,7 @@ defmodule Money do
%__MODULE__{currency: same_currency} = minimum,
%__MODULE__{currency: same_currency} = maximum
) do
if compare(minimum, maximum) == :lt do
if compare(minimum, maximum) in [:lt, :eq] do
compare(money, minimum) in [:gt, :eq] && compare(money, maximum) in [:lt, :eq]
else
raise ArgumentError,
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Money.Mixfile do
use Mix.Project

@version "5.19.0"
@version "5.19.1"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.1", "f41275a0354c736db4b1d255b5d2a27c91028e55c21ea3145b938e22649ffa3f", [:mix], [], "hexpm", "605e44204998f138d6e13be366c8e81af860e726c8177caf50067e1b618fe522"},
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
"phoenix_html": {:hex, :phoenix_html, "4.2.0", "83a4d351b66f472ebcce242e4ae48af1b781866f00ef0eb34c15030d4e2069ac", [:mix], [], "hexpm", "9713b3f238d07043583a94296cc4bbdceacd3b3a6c74667f4df13971e7866ec8"},
"poison": {:hex, :poison, "6.0.0", "9bbe86722355e36ffb62c51a552719534257ba53f3271dacd20fbbd6621a583a", [:mix], [{:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "bb9064632b94775a3964642d6a78281c07b7be1319e0016e1643790704e739a2"},
Expand Down

0 comments on commit 7e0e017

Please sign in to comment.