Skip to content

Commit 027db4a

Browse files
committed
fix reported difference in datetime when passed in a date in the future;
we do this by simply "coercing" the :now-dt argument to be ~at midnight as well~ when then-dt is a java.time.LocalDate
1 parent 911c2bc commit 027db4a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/clj_commons/humanize.cljc

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[clj-commons.humanize.inflect :refer [pluralize-noun in?]]
55
[clj-commons.humanize.time-convert :refer [coerce-to-local-date-time]]
66
[cljc.java-time.duration :as jt.duration]
7+
[cljc.java-time.extn.predicates :as jt.predicates]
78
[cljc.java-time.local-date-time :as jt.ldt]
89
[clojure.string :as string :refer [join]]
910
#?@(:cljs [[goog.string :as gstring]
@@ -292,8 +293,16 @@
292293
:or {now-dt (jt.ldt/now)
293294
suffix "ago"
294295
prefix "in"}}]
295-
(let [then-dt (coerce-to-local-date-time then-dt)
296+
(let [local-date? (jt.predicates/local-date? then-dt)
297+
then-dt (coerce-to-local-date-time then-dt)
296298
now-dt (coerce-to-local-date-time now-dt)
299+
now-dt (if local-date?
300+
(-> now-dt
301+
(jt.ldt/with-hour 0)
302+
(jt.ldt/with-minute 0)
303+
(jt.ldt/with-second 0)
304+
(jt.ldt/with-nano 0))
305+
now-dt)
297306
future-time? (jt.ldt/is-after then-dt now-dt)
298307
;; get the Duration between the two times
299308
time-between (-> (jt.duration/between then-dt now-dt)
@@ -342,6 +351,9 @@
342351
future-time?
343352
(str prefix " a moment")
344353

354+
local-date?
355+
"today"
356+
345357
:else
346358
(str "a moment " suffix))))
347359

0 commit comments

Comments
 (0)