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

cljs-time.extend Equiv and cljs-time.core/= return different results #138

Open
zalky opened this issue Feb 19, 2019 · 3 comments
Open

cljs-time.extend Equiv and cljs-time.core/= return different results #138

zalky opened this issue Feb 19, 2019 · 3 comments

Comments

@zalky
Copy link

zalky commented Feb 19, 2019

Hi, thanks for all the work done on this excellent library!

I'm wondering if there's a reason that the Equiv implementation in cljs-time.extend and cljs-time.core/= return different results?

(require '[cljs-time.extend])

(cljs-time.core/= (t/now) (t/time-now))
;; true

(cljs.core/= (t/now) (t/time-now))
;; false

Looking at the implementation in IEquiv, it seems the behaviour is conditional on the types (in the example above, (instance? goog.date.UtcDateTime other) on L51 would return false), whereas cljs-time.core/= coerces everything to a timestamp and compares that.

Is this intentional?

@zalky
Copy link
Author

zalky commented Feb 19, 2019

Also, note that the IComparable implementation uses the cljs-time.core/= approach, but with no type check.

@andrewmcveigh
Copy link
Owner

I don't remember the exact reason that IEquiv ended up checking for exact types, it didn't start out that way (see c0c43b8). But I do remember some weirdness around

(and (instance? goog.date.Date other)
not returning true anymore.

The fact that the functionality is different is not intentional, most likely I forgot cljs-time.core/= even existed. I'd have removed cljs-time.core/= a long time ago, but people were using it.

Not sure that a subtle behaviour change at this point is a great idea though.

@zalky
Copy link
Author

zalky commented Feb 20, 2019

I see. Another thing I noticed is that cljs-time.core/equal? and IEquiv are different:

cljs.user> (binding [t/*ms-fn* (constantly (t/*ms-fn*))]
             (let [t1 (t/now)
                   t2 (t/time-now)]
               [(t/equal? t1 t2)
                (t/equal? t2 t1)]))
[true true]
cljs.user> (binding [t/*ms-fn* (constantly (t/*ms-fn*))]
             (let [t1 (t/now)
                   t2 (t/time-now)]
               [(= t1 t2)
                (= t2 t1)]))
[false false]

Also, is there any particular reason that (.equals t1 t2) is not used everywhere?

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