Skip to content

Commit

Permalink
fix reported difference in datetime when passed in a date in the future;
Browse files Browse the repository at this point in the history
we do this by simply "coercing" the :now-dt argument to be ~at midnight
as well~ when then-dt is a java.time.LocalDate
  • Loading branch information
jf committed Nov 15, 2024
1 parent 911c2bc commit 027db4a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/clj_commons/humanize.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[clj-commons.humanize.inflect :refer [pluralize-noun in?]]
[clj-commons.humanize.time-convert :refer [coerce-to-local-date-time]]
[cljc.java-time.duration :as jt.duration]
[cljc.java-time.extn.predicates :as jt.predicates]
[cljc.java-time.local-date-time :as jt.ldt]
[clojure.string :as string :refer [join]]
#?@(:cljs [[goog.string :as gstring]
Expand Down Expand Up @@ -292,8 +293,16 @@
:or {now-dt (jt.ldt/now)
suffix "ago"
prefix "in"}}]
(let [then-dt (coerce-to-local-date-time then-dt)
(let [local-date? (jt.predicates/local-date? then-dt)
then-dt (coerce-to-local-date-time then-dt)
now-dt (coerce-to-local-date-time now-dt)
now-dt (if local-date?
(-> now-dt
(jt.ldt/with-hour 0)
(jt.ldt/with-minute 0)
(jt.ldt/with-second 0)
(jt.ldt/with-nano 0))
now-dt)
future-time? (jt.ldt/is-after then-dt now-dt)
;; get the Duration between the two times
time-between (-> (jt.duration/between then-dt now-dt)
Expand Down Expand Up @@ -342,6 +351,9 @@
future-time?
(str prefix " a moment")

local-date?
"today"

:else
(str "a moment " suffix))))

Expand Down

0 comments on commit 027db4a

Please sign in to comment.