瀏覽代碼

fix: date label

Tienson Qin 9 月之前
父節點
當前提交
17ee522779
共有 1 個文件被更改,包括 11 次插入10 次删除
  1. 11 10
      src/main/frontend/components/property/value.cljs

+ 11 - 10
src/main/frontend/components/property/value.cljs

@@ -382,19 +382,20 @@
 
 (defn- human-date-label
   [date]
-  (let [today (t/today)]
+  (let [today (t/today)
+        today-y (t/year today)
+        today-m (t/month today)
+        today-d (t/day today)
+        same-day? (fn [date]
+                    (and (= today-y (t/year date)) (= today-m (t/month date)) (= today-d (t/day date))))]
     (cond
-      (and (or (t/after? date today)
-               (t/equal? date today))
-           (t/before? date (t/plus today (t/days 1))))
+      (same-day? date)
       "Today"
-      (and (or (t/equal? date (t/plus today (t/days 1)))
-               (t/after? date (t/plus today (t/days 1))))
-           (t/before? date (t/plus today (t/days 2))))
+      (let [tomorrow (t/minus date (t/days 1))]
+        (same-day? tomorrow))
       "Tomorrow"
-      (and (or (t/equal? date (t/minus today (t/days 1)))
-               (t/after? date (t/minus today (t/days 1))))
-           (t/before? date today))
+      (let [yesterday (t/plus date (t/days 1))]
+        (same-day? yesterday))
       "Yesterday"
       :else
       nil)))