mirror of https://github.com/logseq/logseq
Fix date parsing
parent
ee56330264
commit
95c8c430ea
|
@ -226,7 +226,8 @@
|
|||
{:on-change
|
||||
(fn [e date]
|
||||
(util/stop e)
|
||||
(let [journal (date/journal-name (tc/to-date date))]
|
||||
(let [date (t/to-default-time-zone date)
|
||||
journal (date/journal-name date)]
|
||||
;; similar to page reference
|
||||
(insert-command! id
|
||||
(util/format "[[%s]]" journal)
|
||||
|
|
|
@ -501,7 +501,7 @@
|
|||
(rum/defc heading-checkbox
|
||||
[heading class]
|
||||
(case (:heading/marker heading)
|
||||
(list "DOING" "IN-PROGRESS" "TODO" "WAIT")
|
||||
(list "DOING" "IN-PROGRESS" "TODO" "WAIT" "WAITING")
|
||||
(ui/checkbox {:class class
|
||||
:style {:margin-top -2}
|
||||
:on-change (fn [_e]
|
||||
|
@ -525,7 +525,7 @@
|
|||
agenda? (= (:id config) "agenda")
|
||||
checkbox (heading-checkbox t
|
||||
(str "mr-1 cursor"))
|
||||
marker-cp (if (contains? #{"DOING" "IN-PROGRESS" "WAIT"} marker)
|
||||
marker-cp (if (contains? #{"DOING" "IN-PROGRESS" "WAIT" "WAITING"} marker)
|
||||
[:span {:class (str "task-status " (string/lower-case marker))
|
||||
:style {:margin-right 3.5}}
|
||||
(string/upper-case marker)])
|
||||
|
|
|
@ -16,6 +16,21 @@
|
|||
[clojure.string :as string]))
|
||||
|
||||
(rum/defc journal-cp < rum/reactive
|
||||
{:init (fn [state]
|
||||
(let [[[title format]] (:rum/args state)
|
||||
page (string/lower-case title)
|
||||
today? (= page (string/lower-case (date/journal-name)))]
|
||||
;; no contents yet
|
||||
(when today?
|
||||
(let [raw-headings (db/get-page-headings page)
|
||||
headings (db/with-dummy-heading raw-headings format nil true)]
|
||||
(when (= 1 (count raw-headings))
|
||||
(when-let [template (state/get-journal-template)]
|
||||
(handler/insert-new-heading!
|
||||
(first headings)
|
||||
(str (:heading/content (first headings)) "\n" template)
|
||||
false))))))
|
||||
state)}
|
||||
[[title format]]
|
||||
(let [;; Don't edit the journal title
|
||||
page (string/lower-case title)
|
||||
|
@ -26,13 +41,6 @@
|
|||
encoded-page-name (util/url-encode page)
|
||||
today? (= (string/lower-case title)
|
||||
(string/lower-case (date/journal-name)))]
|
||||
;; no contents yet
|
||||
(when (and today? (= 1 (count raw-headings)))
|
||||
(when-let [template (state/get-journal-template)]
|
||||
(handler/insert-new-heading!
|
||||
(first headings)
|
||||
(str (:heading/content (first headings)) "\n" template)
|
||||
false)))
|
||||
[:div.flex-1
|
||||
[:a.initial-color {:href (str "/page/" encoded-page-name)
|
||||
:on-click (fn [e]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns frontend.date
|
||||
(:require [cljs-time.core :as t]
|
||||
[cljs-time.coerce :as tc]
|
||||
[cljs-time.format :as tf]
|
||||
[frontend.state :as state]
|
||||
[cljs-bean.core :as bean]
|
||||
|
@ -14,6 +15,25 @@
|
|||
|
||||
(def custom-formatter (tf/formatter "yyyy-MM-dd HH:mm:ssZ"))
|
||||
|
||||
(defn journal-title-formatters
|
||||
[]
|
||||
(conj
|
||||
#{"MMM do, yyyy"
|
||||
"E, MM/dd/yyyy"
|
||||
"E, yyyy/MM/dd"
|
||||
"EEE, MM/dd/yyyy"
|
||||
"EEE, yyyy/MM/dd"
|
||||
"EEEE, MM/dd/yyyy"
|
||||
"EEEE, yyyy/MM/dd"
|
||||
"MM/dd/yyyy"
|
||||
"MM-dd-yyyy"
|
||||
"MM_dd_yyyy"
|
||||
"yyyy/MM/dd"
|
||||
"yyyy-MM-dd"
|
||||
"yyyy_MM_dd"
|
||||
"yyyy年MM月dd日"}
|
||||
(state/get-date-formatter)))
|
||||
|
||||
(defn get-date-time-string [date-time]
|
||||
(tf/unparse custom-formatter date-time))
|
||||
|
||||
|
@ -96,14 +116,40 @@
|
|||
|
||||
(defn journals-path
|
||||
[year month preferred-format]
|
||||
(let [month (if (< month 10) (str "0" month) month)]
|
||||
(str "journals/" year "_" month "." (string/lower-case (name preferred-format)))))
|
||||
(let [month (if (< month 10) (str "0" month) month)
|
||||
format (string/lower-case (name preferred-format))
|
||||
format (if (= format "markdown") "md" format)]
|
||||
(str "journals/" year "_" month "." format)))
|
||||
|
||||
(defn current-journal-path
|
||||
[preferred-format]
|
||||
(let [{:keys [year month]} (get-date)]
|
||||
(journals-path year month preferred-format)))
|
||||
|
||||
(defn valid?
|
||||
[s]
|
||||
(some
|
||||
(fn [formatter]
|
||||
(try
|
||||
(tf/parse (tf/formatter formatter) s)
|
||||
(catch js/Error _e
|
||||
false)))
|
||||
(journal-title-formatters)))
|
||||
|
||||
(defn journal-title->int
|
||||
[journal-title]
|
||||
(when-not (string/blank? journal-title)
|
||||
(let [time (->> (map
|
||||
(fn [formatter]
|
||||
(try
|
||||
(tf/parse (tf/formatter formatter) journal-title)
|
||||
(catch js/Error _e
|
||||
nil)))
|
||||
(journal-title-formatters))
|
||||
(filter some?)
|
||||
first)]
|
||||
(util/parse-int (tf/unparse (tf/formatter "yyyyMMdd") time)))))
|
||||
|
||||
(comment
|
||||
(def default-formatter (tf/formatter "MMM do, yyyy"))
|
||||
(def zh-formatter (tf/formatter "YYYY年MM月dd日"))
|
||||
|
|
|
@ -737,7 +737,9 @@
|
|||
(defn valid-journal-title?
|
||||
[title]
|
||||
(and title
|
||||
(not (js/isNaN (js/Date.parse title)))))
|
||||
(or
|
||||
(date/valid? (string/capitalize title))
|
||||
(not (js/isNaN (js/Date.parse title))))))
|
||||
|
||||
(defn get-heading-content
|
||||
[utf8-content heading]
|
||||
|
@ -751,12 +753,6 @@
|
|||
|
||||
;; file
|
||||
|
||||
(defn journal-page-name->int
|
||||
[page-name]
|
||||
(let [[m d y] (-> (last (string/split page-name #", "))
|
||||
(string/split #"/"))]
|
||||
(util/parse-int (str y m d))))
|
||||
|
||||
(defn extract-pages-and-headings
|
||||
[format ast directives file content utf8-content journal? pages-fn]
|
||||
(println "Parsing file: " file)
|
||||
|
@ -800,7 +796,7 @@
|
|||
:page/file [:file/path file]
|
||||
:page/journal? journal?
|
||||
:page/journal-day (if journal?
|
||||
(journal-page-name->int page)
|
||||
(date/journal-title->int (string/capitalize page))
|
||||
0)}
|
||||
(seq directives)
|
||||
(assoc :page/directives directives)
|
||||
|
@ -846,7 +842,8 @@
|
|||
headings)
|
||||
(remove nil?))))
|
||||
(catch js/Error e
|
||||
(prn "Parsing error: " e))))
|
||||
(prn "Parsing error: " e)
|
||||
(js/console.dir e))))
|
||||
|
||||
;; check journal formats and report errors
|
||||
(defn extract-headings-pages
|
||||
|
|
|
@ -159,6 +159,14 @@
|
|||
(range 1 (inc last-day)))
|
||||
(apply str))))
|
||||
|
||||
(defn re-render-root!
|
||||
[]
|
||||
(when-let [component (state/get-root-component)]
|
||||
(db/clear-query-state!)
|
||||
(rum/request-render component)
|
||||
(doseq [component (state/get-custom-query-components)]
|
||||
(rum/request-render component))))
|
||||
|
||||
(defn create-month-journal-if-not-exists
|
||||
[repo-url]
|
||||
(let [repo-dir (util/get-repo-dir repo-url)
|
||||
|
@ -171,6 +179,7 @@
|
|||
file-exists? (fs/create-if-not-exists repo-dir file-path default-content)]
|
||||
(when-not file-exists?
|
||||
(db/reset-file! repo-url path default-content)
|
||||
(re-render-root!)
|
||||
(git-add repo-url path)))))
|
||||
|
||||
(defn create-config-file-if-not-exists
|
||||
|
@ -193,14 +202,6 @@
|
|||
(ok-handler
|
||||
(zipmap files contents)))))
|
||||
|
||||
(defn re-render-root!
|
||||
[]
|
||||
(when-let [component (state/get-root-component)]
|
||||
(db/clear-query-state!)
|
||||
(rum/request-render component)
|
||||
(doseq [component (state/get-custom-query-components)]
|
||||
(rum/request-render component))))
|
||||
|
||||
(defn load-repo-to-db!
|
||||
[repo-url diffs first-clone?]
|
||||
(let [load-contents (fn [files delete-files delete-headings re-render?]
|
||||
|
@ -247,6 +248,9 @@
|
|||
[repo-url diffs first-clone?]
|
||||
(when (or diffs first-clone?)
|
||||
(p/let [_ (load-repo-to-db! repo-url diffs first-clone?)]
|
||||
(create-month-journal-if-not-exists repo-url)
|
||||
(create-config-file-if-not-exists repo-url)
|
||||
|
||||
(history/clear-specific-history! [:git/repo repo-url])
|
||||
(history/add-history!
|
||||
[:git/repo repo-url]
|
||||
|
|
Loading…
Reference in New Issue