瀏覽代碼

refactor: update review.md, update date_time.cljs

rcmerci 2 月之前
父節點
當前提交
9ac33d60c3
共有 2 個文件被更改,包括 9 次插入5 次删除
  1. 7 5
      deps/common/src/logseq/common/util/date_time.cljs
  2. 2 0
      prompts/review.md

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

@@ -6,6 +6,8 @@
             [clojure.string :as string]
             [logseq.common.util :as common-util]))
 
+(def ^:private yyyyMMdd-formatter (tf/formatter "yyyyMMdd"))
+
 ;; (tf/parse (tf/formatter "dd.MM.yyyy") "2021Q4") => 20040120T000000
 (defn safe-journal-title-formatters
   [date-formatter]
@@ -32,7 +34,7 @@
   (when journal-title
     (let [journal-title (common-util/capitalize-all journal-title)]
       (journal-title-> journal-title
-                       #(parse-long (tf/unparse (tf/formatter "yyyyMMdd") %))
+                       #(parse-long (tf/unparse yyyyMMdd-formatter %))
                        formatters))))
 
 (defn format
@@ -51,7 +53,7 @@
 (defn int->journal-title
   [day date-formatter]
   (when day
-    (format (tf/parse (tf/formatter "yyyyMMdd") (str day)) date-formatter)))
+    (format (tf/parse yyyyMMdd-formatter (str day)) date-formatter)))
 
 (defn- get-weekday
   [date]
@@ -94,7 +96,7 @@
   "Converts a journal's :block/journal-day integer into milliseconds"
   [day]
   (when day
-    (-> (tf/parse (tf/formatter "yyyyMMdd") (str day))
+    (-> (tf/parse yyyyMMdd-formatter (str day))
         (tc/to-long))))
 
 (defn ms->journal-day
@@ -103,5 +105,5 @@
   (some->> ms
            tc/from-long
            t/to-default-time-zone
-           (tf/unparse (tf/formatter "yyyyMMdd"))
-           parse-long))
+           (tf/unparse yyyyMMdd-formatter)
+           parse-long))

+ 2 - 0
prompts/review.md

@@ -3,3 +3,5 @@ You're Clojure(script) expert, you're responsible to check those common errors:
 - `empty?` should be used instead of `empty` when a boolean value is expected in an expression.
 
 - If a function does not use `d/transact!`, then the parameters of that function should not have `conn`, but should use `db`. `conn` is mutable, and `db` is immutable.
+
+- If the arguments of `cljs-time.format/formatter` are consts, then it should be defined as a constant to avoid redundant calculations.