andrewmcveigh / cljs-time

A clj-time inspired date library for clojurescript.
342 stars 57 forks source link

Interval between days #83

Open edbond opened 7 years ago

edbond commented 7 years ago

I want to calculate number of days between two dates. What am I missing here?

cljs.user=> (time-core/today)
#object[Object 20170126]
cljs.user=> (time-core/local-date 2017 1 27)
#object[Object 20170127]
cljs.user=> (time-core/interval (time-core/today) (time-core/local-date 2017 1 27))
#cljs-time.core.Interval{:start #object[Object 20170126], :end #object[Object 20170127]}
cljs.user=> (time-core/in-hours (time-core/interval (time-core/today) (time-core/local-date 2017 1 27)))
13
edbond commented 7 years ago

I have solved using to/from-default-time-zone functions. Still looks not intuitive to me.

andrewmcveigh commented 7 years ago

(cljs-time.core/today) returns a UTC date, whereas local-* return dates in the user's timezone.

edbond commented 7 years ago

today is printed as a date without time. That's why it may be confusing. It would be nice to have Date without time for such calculations.

andrewmcveigh commented 7 years ago

Ah, just looking through the code. This is a bug I think, sorry.