2 things.
- user preference. Personally for readability I prefer date format
EEE dd MMM yyyy
myself (it isn’t officially supported even ) - thinkering is only required as we’re talking about a property value which points to a journal page. When we talk about a block on a journal page it is much more straight forward.
Because it is not something your query is currently returning as a result.
You return the block:
{:block/properties-text-values
{:due-by "[[Friday, 26.04.2024]]", :status "#defacut"},
:block/uuid #uuid "662f6f55-48f2-431c-a227-59f81b7df483",
:block/properties
{:due-by #{"Friday, 26.04.2024"}, :status #{"defacut"}},
:block/left {:db/id 21},
:block/refs [{:db/id 4} {:db/id 22} {:db/id 24}],
:block/properties-order (:due-by :status),
:block/format :markdown,
:block/content
"TODO Task to do\ndue-by:: [[Friday, 26.04.2024]]\nstatus:: #defacut",
:db/id 41,
:block/path-refs [{:db/id 4} {:db/id 21} {:db/id 22} {:db/id 24}],
:block/parent {:db/id 21},
:block/page {:db/id 21},
:block/marker "TODO"}
Nowhere in this data is the information we need for sorting.
For that we would need the page data for that Friday date:
{:db/id 22,
:block/created-at 1714384725767,
:block/journal-day 20240426,
:block/journal? true,
:block/name "friday, 26.04.2024",
:block/original-name "Friday, 26.04.2024",
:block/updated-at 1714384725767,
:block/uuid #uuid "662f6f55-8420-436c-9129-ded978361bc2"}
Here we find the :block/journal-day
which can be used.
We just don’t have this information available to us in the block data. So we will need to add that.
Which is where my examples came in
So taking the query you posted earlier we can add to it for this purpose.
#+BEGIN_QUERY
{:title [:h3 "Soon... (7-30 days):"]
:inputs [:-7d :+30d]
:query [:find ?d (pull ?b [*])
:keys date block ;bind :find output to keys: the ?d variable to date and the block data to block
:in $ ?start ?next
:where
[?b :block/properties-text-values ?textprop] ;get plain text of the properties
[(get ?textprop :status) ?stat] ;get the status property
[(contains? #{"#defacut" "determinat"} ?stat)]
[?b :block/properties ?prop]
[(get ?prop :due-by) ?due] ;get the due-by property
[?b :block/refs ?j] ;get the block references
[?j :block/original-name ?journal] ;get the page name of the reference
[(contains? ?due ?journal)] ;check that the reference is actually present in the property
[?j :block/journal-day ?d] ;get the date of the journal page
[(<= ?start ?d ?next)] ;check that the journal page is in range
; [(get ?prop :priority) ?stat] ;get the status property
]
:breadcrumb-show? false
:result-transform (fn [result] (sort-by ;sort the result by the :date key through some functions
(fn [r] (get-in r [:block/properties :date])) ;use the binding from the map below
(map ;make a new map from the result set
(fn [r]
(update (:block r) :block/properties ;we're going to update the values for the block attribute :block/properties
(fn [u] (assoc u :date (get-in r [:date]) ) ) ;putting the :date key/value pair from the results into the :block/properties attribute.
)
)
result
)
))
}
#+END_QUERY
(had to comment out the last line of the where as that is not a property I have in my test data )