Logseq Query to Track Overtime

A method for using Logseq to track overtime hours in your job.

Here’s how I’m using Logseq to track overtime in my job:

  1. Create a query in Journal:

    template:: overtime table
    #+BEGIN_QUERY
    {
     :title [:h3 "Overtime"]
     :query
     [
        :find
        (pull ?b [*])
        :in $
        :where
        [?b :block/content ?content]
        [(clojure.string/includes? ?content "#overtime")]
        [?b :block/page ?p]
        [?p :page/journal? true]
        [?b :block/journal-day ?d]
     ]
     :result-transform
     (fn [result]
       (->> result
            (sort-by (fn [h] (get-in h [:block/page :block/journal-day])))
            reverse
            (take 5))) ; Take the top 5 results
     :view
     (fn [results]
       [:table.table-auto.w-full
        [:thead
         [:tr
          [:th.px-4.py-2 "Content"]
          [:th.px-4.py-2 "Date"]]]
        [:tbody
         (for [result results]
           [:tr
            [:td.border.p-2
             [:a {:href (str "#/page/" (:block/name (:block/page result)))}
              (:block/content result)]]
            [:td.border.p-2
             (let [date-int (get-in result [:block/page :block/journal-day])
                   year (subs (str date-int) 0 4)
                   month (subs (str date-int) 4 6)
                   day (subs (str date-int) 6 8)]
              (str year "-" month "-" day))]])]])
    }
    #+END_QUERY
    
  2. Use the template in the Contents page: /template > overtime table.

  3. End each workday with a Journal entry of #overtime +30m indicating total overtime you have accumulated until this day.

  4. The table will show the 5 most recent records of overtime you have created in this way. If you keep the Contents page open in the sidebar, you’ll know this at a glance.