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

Deprecate then eliminate max/min #1548

Closed
icambron opened this issue Mar 25, 2014 · 2 comments
Closed

Deprecate then eliminate max/min #1548

icambron opened this issue Mar 25, 2014 · 2 comments

Comments

@icambron
Copy link
Member

@icambron icambron commented Mar 25, 2014

moment().min and moment().max were a good idea for helper functions, but combined with the mutability that most moment() methods have it turned out disasterously confusing.

So we're deprecating those two in favor of moment.min and moment.max, which are non-mutating and work on any number of objects:

// if a, b, c, d are moments ordered in time
moment.min(a, b);  // a
moment.min(a, b, c, d);  // a 
moment.min([a, b, c, d]);  // a
moment.max(a, b);  // b
moment.max(a, b, c, d);  // d
moment.max([a, b, c, d]);  // d
@ypresto
Copy link

@ypresto ypresto commented Mar 7, 2017

moment().min(start).max(end) was useful for clamping.
Now it is moment.max(start, moment.min(end, moment()) and has less readability and long code.
How about adding moment().clamp(start, end)?

@icambron
Copy link
Member Author

@icambron icambron commented Mar 8, 2017

That seems easy enough to add from userspace. Untested, but:

moment.fn.clamp = function(start, end){
   return moment.max(start, moment.min(end, moment());
}

Since I suspect this is relatively rare use case and it's easy to do from userspace, I'd prefer to keep out of the lib in the name of limiting the surface area.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.