Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MoneyRange implementation #514

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jaikdean
Copy link
Contributor

@jaikdean jaikdean commented Nov 6, 2018

We're using this library in a couple of projects, and have hit upon the need for a monetary range a number of times. While we can work around this, it's much cleaner using a MoneyRange value object.

I'm aware this is slightly extending the scope of this library, so it perhaps doesn't belong here and should be in a separate library, but it's been a useful addition for us.

Examples

$range = MoneyRange::GBP(100, 1000);

$range->contains(Money::GBP(200)); // returns true
$range->midPoint(); // returns Money::GBP(500)
$range->lessThan(Money::GBP(2000)); // returns true
$range->lessThan(MoneyRange::GBP(2000, 3000)); // returns true
$range->multiply(2); // returns MoneyRange::GBP(200, 2000)

I'd welcome feedback on this!

@frederikbosch frederikbosch added this to the 4.1.0 milestone May 5, 2021
@frederikbosch
Copy link
Member

I don't know if this should be part of this library. For now I tagged it for milestone 4.1.0. We will decide then to merge this or not. Thank you for sharing this idea and code.

@frederikbosch
Copy link
Member

have hit upon the need for a monetary range a number of times

Could you explain the use-case? It helps to accept the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants