Просмотр исходного кода

fix: Task doesn't repeat with a user :date property

Tienson Qin 1 год назад
Родитель
Сommit
e522c73fe2

+ 7 - 8
deps/common/src/logseq/common/util/date_time.cljs

@@ -1,6 +1,7 @@
 (ns logseq.common.util.date-time
   "cljs-time util fns for deps"
-  (:require [cljs-time.format :as tf]
+  (:require [cljs-time.coerce :as tc]
+            [cljs-time.format :as tf]
             [clojure.string :as string]
             [logseq.common.util :as common-util]))
 
@@ -89,10 +90,8 @@
    (string/replace (ymd date) "/" "")))
 
 (defn journal-day->ms
-  "Convert :block/journal-day int to ms timestamp in current timezone"
-  [journal-day]
-  (let [journal-day' (str journal-day)
-        year (js/parseInt (subs journal-day' 0 4))
-        month (dec (js/parseInt (subs journal-day' 4 6)))
-        day (js/parseInt (subs journal-day' 6 8))]
-    (.getTime (new js/Date year month day))))
+  "journal-day format yyyyMMdd"
+  [day]
+  (when day
+    (-> (tf/parse (tf/formatter "yyyyMMdd") (str day))
+        (tc/to-long))))

+ 3 - 4
src/main/frontend/components/property/value.cljs

@@ -332,9 +332,8 @@
         value (cond
                 (map? value)
                 (when-let [day (:block/journal-day value)]
-                  (let [t (tc/to-date-time (date/journal-day->ts day))]
-                    (js/Date.
-                     (get-local-journal-date-time (t/year t) (t/month t) (t/day t)))))
+                  (let [t (date/journal-day->utc-ms day)]
+                    (js/Date. t)))
 
                 (number? value)
                 (js/Date. value)
@@ -480,7 +479,7 @@
           (ui/icon "repeat" {:size 14 :class "opacity-40"}))
         (cond
           (map? value)
-          (let [date (tc/to-date-time (date/journal-day->ts (:block/journal-day value)))
+          (let [date (tc/to-date-time (date/journal-day->utc-ms (:block/journal-day value)))
                 compare-value (some-> date
                                       (t/plus (t/days 1))
                                       (t/minus (t/seconds 1)))

+ 1 - 6
src/main/frontend/date.cljs

@@ -136,12 +136,7 @@
    journal-title
    (date-time-util/safe-journal-title-formatters (state/get-date-formatter))))
 
-(defn journal-day->ts
-  "journal-day format yyyyMMdd"
-  [day]
-  (when day
-    (-> (tf/parse (tf/formatter "yyyyMMdd") (str day))
-        (tc/to-long))))
+(def journal-day->utc-ms date-time-util/journal-day->ms)
 
 (defn journal-title->long
   [journal-title]

+ 1 - 1
src/main/frontend/db/async.cljs

@@ -234,7 +234,7 @@
           future-day (some->> future-date
                               (tf/unparse date-format)
                               (parse-long))
-          start-time (date/journal-day->ts date)
+          start-time (date/journal-day->utc-ms date)
           future-time (tc/to-long future-date)]
       (when-let [repo (and future-day (state/get-current-repo))]
         (p/let [result

+ 9 - 9
src/main/frontend/handler/common.cljs

@@ -1,16 +1,16 @@
 (ns frontend.handler.common
   "Common fns for handlers"
-  (:require [cljs-bean.core :as bean]
+  (:require ["ignore" :as Ignore]
+            [cljs-bean.core :as bean]
             [cljs.reader :as reader]
             [frontend.date :as date]
+            [frontend.db :as db]
+            [frontend.handler.property :as property-handler]
             [frontend.state :as state]
             [frontend.util :as util]
-            [frontend.handler.property :as property-handler]
-            [goog.object :as gobj]
             [goog.dom :as gdom]
-            ["ignore" :as Ignore]
             [goog.functions :refer [debounce]]
-            [frontend.db :as db]))
+            [goog.object :as gobj]))
 
 (defn copy-to-clipboard-without-id-property!
   [repo format raw-text html blocks]
@@ -47,21 +47,21 @@
   [pages]
   (map (fn [{:block/keys [created-at updated-at journal-day] :as p}]
          (cond->
-           p
+          p
 
            (nil? created-at)
            (assoc :block/created-at
                   (if journal-day
-                    (date/journal-day->ts journal-day)
+                    (date/journal-day->utc-ms journal-day)
                     (util/time-ms)))
 
            (nil? updated-at)
            (assoc :block/updated-at
                   ;; Not exact true
                   (if journal-day
-                    (date/journal-day->ts journal-day)
+                    (date/journal-day->utc-ms journal-day)
                     (util/time-ms)))))
-    pages))
+       pages))
 
 (defn listen-to-scroll!
   [element]

+ 13 - 7
src/main/frontend/worker/commands.cljs

@@ -154,17 +154,23 @@
                            :logseq.task/scheduled)
         frequency (db-property/property-value-content (:logseq.task/recur-frequency entity))
         unit (:logseq.task/recur-unit entity)
-        current-value (get entity property-ident)]
+        property (d/entity db property-ident)
+        date? (= :date (get-in property [:block/schema :type]))
+        current-value (cond->
+                       (get entity property-ident)
+                        date?
+                        (#(date-time-util/journal-day->ms (:block/journal-day %))))]
     (when (and frequency unit)
       (when-let [next-time-long (get-next-time current-value unit frequency)]
         (let [journal-day (outliner-pipeline/get-journal-day-from-long db next-time-long)
-              create-journal-page (when-not journal-day
-                                    (let [formatter (:logseq.property.journal/title-format (d/entity db :logseq.class/Journal))
-                                          title (date-time-util/format (t/to-default-time-zone (tc/to-date-time next-time-long)) formatter)]
-                                      (worker-db-page/create db title {:create-first-block? false})))
-              value next-time-long]
+              {:keys [tx-data page-uuid]} (if journal-day
+                                            {:page-uuid (:block/uuid (d/entity db journal-day))}
+                                            (let [formatter (:logseq.property.journal/title-format (d/entity db :logseq.class/Journal))
+                                                  title (date-time-util/format (t/to-default-time-zone (tc/to-date-time next-time-long)) formatter)]
+                                              (worker-db-page/create db title {:create-first-block? false})))
+              value (if date? [:block/uuid page-uuid] next-time-long)]
           (concat
-           (:tx-data create-journal-page)
+           tx-data
            (when value
              [[:db/add (:db/id entity) property-ident value]])))))))