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

Why don't ranges intersect on boundaries? #112

Closed
CExWHamdan opened this issue Mar 24, 2016 · 5 comments
Closed

Why don't ranges intersect on boundaries? #112

CExWHamdan opened this issue Mar 24, 2016 · 5 comments
Milestone

Comments

@CExWHamdan
Copy link

Consider the below example:

var a = moment('28-Mar-2016')
var b = moment('29-Mar-2016')
var c = moment('29-Mar-2016')
var d = moment('30-Mar-2016')

var range1 = moment.range(a, b)
var range2 = moment.range(c, d)

range1.intersect(range2) // returns null

One would assume that range1 and range2 actually intersect at '29-Mar-2016'. Is this behaviour intended and do you mind explaining why?

@StevenRKM
Copy link

It's an intersection if you include the endpoints.
An optional parameter for this inclusion could be provided, like it is used with the 'contains' method. However then it is very important to check the return value, it could be undefined, a Moment or a MomentRange.
To avoid this confusion it 's maybe better to provide an additional method that checks if two intervals touch eachother.

@stevesims
Copy link

+1 on this from me

would be very handy to find out if two moments are adjacent

gf3 added a commit that referenced this issue Dec 12, 2016
@gf3
Copy link
Contributor

gf3 commented Dec 12, 2016

great suggestions, i've added both an #adjacent method and an adjacent option to #overlaps in the upcoming release

@gf3 gf3 modified the milestone: 3.0.0 Jan 9, 2017
gf3 added a commit that referenced this issue Jan 10, 2017
* Go full-blown ES6 via webpack/babel
* Flow typing
* Better documentation
* Remove bower
* Remove grunt in favour of webpack
* Remove jshint in favour of eslint
* Remove mocha/should in favour of karma/mocha/expect.js
* New usage:
    import Moment from 'moment';
    import { DateRange, extendMoment } from 'moment-js';
    const moment = extendMoment(Moment);
* Add `by`, `reverseBy`, `byRange`, `reverseByRange` (#68)
    - Pass options as object
    - New methods use iterators
    - Added reversal methods
    - Discrete methods for different iterator types
* Fix issue with `moment#within` and moment-timezone (#127)
* Pass optional rounded argument in `diff` (#104)
* Add ability to iterate over a range by a step (#93)
* Add `adjacent` method and option to `overlaps` (#92 #112)
* Update short-hand units (#134)
* Add `duration` as an alias of `diff` (#64)
* Update packaging rules and scripts
* Fix typo in comment (#133)
* Update documentation
* Add documentation about range creation (thanks @seanwendt)
@gf3
Copy link
Contributor

gf3 commented Jan 10, 2017

just opened a PR for 3.0.0 which incorporates these changes. feel free to leave feedback or raise any questions you may have. thanks again for your contributions

@gf3 gf3 closed this as completed Jan 10, 2017
gf3 added a commit that referenced this issue Jan 10, 2017
* Go full-blown ES6 via webpack/babel
* Flow typing
* Better documentation
* Remove bower
* Remove grunt in favour of webpack
* Remove jshint in favour of eslint
* Remove mocha/should in favour of karma/mocha/expect.js
* New usage:
    import Moment from 'moment';
    import { DateRange, extendMoment } from 'moment-js';
    const moment = extendMoment(Moment);
* Add `by`, `reverseBy`, `byRange`, `reverseByRange` (#68)
    - Pass options as object
    - New methods use iterators
    - Added reversal methods
    - Discrete methods for different iterator types
* Fix issue with `moment#within` and moment-timezone (#127)
* Pass optional rounded argument in `diff` (#104)
* Add ability to iterate over a range by a step (#93)
* Add `adjacent` method and option to `overlaps` (#92 #112)
* Update short-hand units (#134)
* Add `duration` as an alias of `diff` (#64)
* Update packaging rules and scripts
* Fix typo in comment (#133)
* Update documentation
* Add documentation about range creation (thanks @seanwendt)
@tncbbthositg
Copy link

tncbbthositg commented Jan 8, 2021

I feel like I might be missing something. I still have this issue with 4.0.2.

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

No branches or pull requests

5 participants