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
Add clamp function #2498
Add clamp function #2498
Conversation
For the curried version of this function. Currying from the right makes sense for my use case. I have an interval that I want to clamp multiple values to. const contractInterval = {start, end}
const clampToContract = clamp(allowed)
const queryStartDate = new Date();
const queryEndDate = new Date();
const start = clampToContract(queryStartDate)
const end = clampToContract(queryEndDate) |
Sorry @tan75, I accidentally closed the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Liam-Tait
this function is a great idea and it might be very useful! Thank you for your PR! 👍
Could you please make the examples consistent with our current example convention - e.g. see this one below:
Next Monday example
Now the convention is to use const
and please delete the 'javascript' mention.
As well, please format the examples and the 'Docs' part of the file - it's good to have them consistent with the nextMonday
example. Let us know if anything is unclear.
@Liam-Tait |
a675ee4
to
26a1d49
Compare
Thanks!
I think I have matched the convention. Let me know if this correct
|
My use case is for querying a list of data based on a contract. The query has a minDate and maxDate I only want to retrieve the data within the period of a contract. Ideally this would be done at the database layer, however that option is not available to me. const minDate = clamp(requestedMin, contractInterval)
const maxDate = clamp(requestedMax, contractInterval)
const result = query(minDate, maxDate) Useful for when there is an allowed period of time (interval) and a user input of date and instead of causing an error bounding to the allowed range |
Updated! Please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Liam-Tait Thank you for this PR! 👍
Assigned to @kossnocorp for release
8f1fdf0
to
d83b5a3
Compare
Add a function to clamp a date based on an interval.
This function ensures that a date is bounded by a minimum and maximum