Skip to content

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