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

clj-time.core/overlaps? provides inconsistent results. #264

Closed
HennieLouw opened this issue May 25, 2019 · 1 comment
Closed

clj-time.core/overlaps? provides inconsistent results. #264

HennieLouw opened this issue May 25, 2019 · 1 comment

Comments

@HennieLouw
Copy link

The overlaps function in core has a 'convenience' operation to provide four ReadablePartial instances instead of two Interval instances.

(defn overlaps? [^ReadablePartial start-a ^ReadablePartial end-a  start-b ^ReadablePartial end-b])

However, the implementation is not following the rules of Joda Time.

Intervals are inclusive of the start instant and exclusive of the end.
* An interval overlaps another if it shares some common part of the
* datetime continuum.

Can be reproduced with:

(let [a-start (clj-time.coerce/to-date-time "2019-05-25T00:30:00.000-00:00")
      a-end   (clj-time.coerce/to-date-time "2019-05-25T02:30:00.000-00:00")
      b-start (clj-time.coerce/to-date-time "2019-05-25T02:30:00.000-00:00")
      b-end   (clj-time.coerce/to-date-time "2019-05-25T04:30:00.000-00:00")
      a-iter  (clj-time.core/interval a-start a-end)
      b-inter (clj-time.core/interval b-start b-end)]
  {:overlaps-interval? (clj-time.core/overlaps? a-iter b-inter)
   :overlaps-dates?    (clj-time.core/overlaps? a-start a-end b-start b-end)
   :abuts?             (clj-time.core/abuts? a-iter b-inter)
   })
=> {:overlaps-interval? false, :overlaps-dates? true, :abuts? true}

Note, I'm aware that clj-time is not actively maintained due to Joda Time being replaced with Java Time, However, I suspect that like myself many developers still rely on clj-time because of the existence of cljs-time

@seancorfield
Copy link
Member

Good catch. There are two tests for this and they're both wrong.

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

2 participants