moment-range
moment-range copied to clipboard
Suggested feature: allow range to explicitly direct itself
Now if interval is passed then it's implicitly directed: https://github.com/gf3/moment-range/blob/72e31df65da59e39dbde540c500d8d7da4f82995/lib/moment-range.js#L321-L323
but if 2 moment
objects are passed they are not. And there's no way to direct the range created that way.
It would be nice to be able to pass any 2 dates to range()
and call some method that will direct the dates so earlier date is start
and later date is end
no matter which order they were passed in to the range()
function.
It may work like this:
moment.range([
momentA,
momentB
].sort((a, b) => Math.sign(a.diff(b))))
Suggested api:
moment.range(momentA, momentB).direct()
optionally direct()
method might could take a parameter and if it's falsy or negative the range should be directed from later moment do earlier (Math.sign(b.diff(a))
)
the constructor could implicitly do this? thoughts?
this way it will not be backwards compatible (although logical). IMO Either a method or on next major release
What about
moment.range(momentA, momentB, true);
That way in the next major version you can throw it away by ignoring the extra argument or exceptioning on === false.
We're looking at compiling all the breaking changes into the next major release (4.0.0) and I expect this feature will make a good candidate.
We thought the simplest approach was to make the constructor always perform this behaviour. I can't think of any reasons why you would ever want a reverse-time range? Even if a case does exist, it makes sense to keep the library working for forward ranges as the user can easily add their own application logic to keep track of it.
Our proposed solution: https://github.com/rotaready/moment-range/pull/201/