mirror of https://github.com/logseq/logseq
Proper handle repeated timestamps
parent
6ef40e674b
commit
c2a710b3d4
|
@ -97,9 +97,9 @@
|
|||
["A" (->priority "A")]
|
||||
["B" (->priority "B")]
|
||||
["C" (->priority "C")]
|
||||
["Deadline" [[:editor/input "DEADLINE: "]
|
||||
["Deadline" [[:editor/clear-current-slash]
|
||||
[:editor/show-date-picker]]]
|
||||
["Scheduled" [[:editor/input "SCHEDULED: "]
|
||||
["Scheduled" [[:editor/clear-current-slash]
|
||||
[:editor/show-date-picker]]]
|
||||
["Draw" [[:editor/input "/draw "]
|
||||
[:editor/show-input [{:command :draw
|
||||
|
|
|
@ -71,8 +71,8 @@
|
|||
(if (= (:label item) kind)
|
||||
(assoc item :selected "selected")
|
||||
item))
|
||||
[{:label "+"}
|
||||
{:label ".+"}
|
||||
[{:label ".+"}
|
||||
{:label "+"}
|
||||
{:label "++"}])
|
||||
(fn [value]
|
||||
(swap! *timestamp assoc-in [:repeater :kind] value)))
|
||||
|
@ -112,15 +112,17 @@
|
|||
[:p.mt-4
|
||||
(ui/button "Submit"
|
||||
:on-click (fn [e]
|
||||
(if-let [block (state/get-timestamp-block)]
|
||||
(do
|
||||
(let [{:keys [block typ show?]} block]
|
||||
(editor-handler/set-block-timestamp! (:block/uuid block)
|
||||
typ
|
||||
text)
|
||||
(reset! show? false)))
|
||||
(when-let [input-id (state/get-edit-input-id)]
|
||||
(commands/simple-insert! input-id text nil)))
|
||||
(let [block-data (state/get-timestamp-block)]
|
||||
(let [{:keys [block typ show?]} block-data
|
||||
block-id (or (:block/uuid (state/get-edit-block))
|
||||
(:block/uuid block))
|
||||
typ (or typ @commands/*current-command)]
|
||||
(editor-handler/set-block-timestamp! block-id
|
||||
typ
|
||||
text)
|
||||
(state/clear-edit!)
|
||||
(when show?
|
||||
(reset! show? false))))
|
||||
(clear-timestamp!)
|
||||
(state/set-editor-show-date-picker false)))]]))
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
(let [command-steps (get (into {} matched) chosen)
|
||||
restore-slash? (and
|
||||
(not (contains? (set (map first command-steps)) :editor/input))
|
||||
(not (contains? #{"Date Picker" "Template"} chosen)))]
|
||||
(not (contains? #{"Date Picker" "Template" "Deadline" "Scheduled"} chosen)))]
|
||||
(editor-handler/insert-command! id command-steps
|
||||
format
|
||||
{:restore? restore-slash?})))
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
(when (seq scheduled-or-deadlines)
|
||||
(ui/foldable
|
||||
[:h2.font-bold.opacity-50 (let []
|
||||
"Scheduled AND Deadline")]
|
||||
"SCHEDULED AND DEADLINE")]
|
||||
[:div.references-blocks.mb-6
|
||||
(let [ref-hiccup (hiccup/->hiccup scheduled-or-deadlines
|
||||
{:id (str encoded-page-name "-agenda")
|
||||
|
|
|
@ -481,7 +481,7 @@
|
|||
:end-pos new-end-pos})
|
||||
(block/parse-block block format))
|
||||
block-retracted-attrs (when-not pre-block?
|
||||
(let [id (:db/id block)]
|
||||
(when-let [id (:db/id block)]
|
||||
[[:db/retract id :block/priority]
|
||||
[:db/retract id :block/deadline]
|
||||
[:db/retract id :block/deadline-ast]
|
||||
|
|
|
@ -65,6 +65,26 @@
|
|||
""
|
||||
(str " " time-repeater))))))
|
||||
|
||||
(defn- repeat-until-future-timestamp
|
||||
[datetime now delta keep-week?]
|
||||
(let [result (loop [result datetime]
|
||||
(if (t/after? result now)
|
||||
result
|
||||
(recur (t/plus result delta))))
|
||||
w1 (t/day-of-week datetime)
|
||||
w2 (t/day-of-week result)]
|
||||
(reset! debug-data {:w1 w1
|
||||
:w2 w2
|
||||
:result result
|
||||
:datetime datetime
|
||||
:now now})
|
||||
(if (and keep-week? (not= w1 w2))
|
||||
;; next week
|
||||
(if (> w2 w1)
|
||||
(t/plus result (t/days (- 7 (- w2 w1))))
|
||||
(t/plus result (t/days (- w1 w2))))
|
||||
result)))
|
||||
|
||||
;; Fro https://www.reddit.com/r/orgmode/comments/hr2ytg/difference_between_the_repeaters_orgzly/fy2izqx?utm_source=share&utm_medium=web2x&context=3
|
||||
;; I use these repeaters for habit tracking and it can get a little tricky to keep track. This is my short form understanding:
|
||||
;; ".+X" = repeat in X d/w/m from the last time I marked it done
|
||||
|
@ -79,29 +99,15 @@
|
|||
[duration-f _] (get-duration-f-and-text duration)
|
||||
delta (duration-f num)
|
||||
today (date/get-local-date)
|
||||
[year month day hour min] (cond
|
||||
(or (string/blank? kind)
|
||||
(= kind "Plus"))
|
||||
[year month day hour min]
|
||||
|
||||
;; FIXME: check hour and min, find the nearest time which is after the previous time.
|
||||
(and
|
||||
(= kind "Dotted")
|
||||
(t/after? (tl/local-now) (t/local-date-time year month day hour min)))
|
||||
[(:year today) (:month today) (:day today) hour min]
|
||||
|
||||
:else ; FIXME: DoublePlus
|
||||
(if (t/before? (t/local-date year month day)
|
||||
(t/local-date (:year today)
|
||||
(:month today)
|
||||
(:day today)))
|
||||
(let [{:keys [year month day hour minute]} today]
|
||||
[year month day hour minute])
|
||||
[year month day hour min]))
|
||||
start-time (t/local-date-time year month day hour min)
|
||||
start-time' (if (and (= kind "Dotted")
|
||||
(t/before? (tl/local-now) start-time))
|
||||
start-time
|
||||
start-time' (if (or (= kind "Dotted")
|
||||
(= kind "DoublePlus"))
|
||||
(if (t/before? (tl/local-now) start-time)
|
||||
start-time
|
||||
|
||||
;; Repeatedly add delta to make it a future timestamp
|
||||
(repeat-until-future-timestamp start-time (tl/local-now) delta
|
||||
(= kind "DoublePlus")))
|
||||
(t/plus start-time delta))]
|
||||
(timestamp->text timestamp start-time')))
|
||||
|
||||
|
|
Loading…
Reference in New Issue