refactor: update review.md, update date_time.cljs

This commit is contained in:
rcmerci
2025-08-28 17:54:05 +08:00
parent d05be857f0
commit 9ac33d60c3
2 changed files with 9 additions and 5 deletions

View File

@@ -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))

View File

@@ -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.