List and Count Tiddlers by Date

Considering the powerful filter operators in 5.1.23+ how list and count tiddlers created by date?

I mean something like Recent tab, but I like to have the number of tiddlers also!

31th August 2021 (3)
Tiddler One
Another Tiddler
Tiddler Three
30th August 2021 (2)
This Tiddler
That Tiddler

I know some solutions, but I am looking for concise short ones using new 5.1.23+ features!

Mohammad,

I am not sure about the new methods but I chaved the same result editing $:/core/macros/timeline (or you could clone and rename the macro)

\define timeline(limit:"100",format:"DDth MMM YYYY",subfilter:"",dateField:"modified")
<div class="tc-timeline">
<$list filter="[!is[system]$subfilter$has[$dateField$]!sort[$dateField$]limit[$limit$]eachday[$dateField$]]">
<div class="tc-menu-list-item">
<$view field="$dateField$" format="date" template="$format$"/> ({{{ [sameday:$dateField${!!$dateField$}!is[system]$subfilter$count[]] }}})
<$list filter="[sameday:$dateField${!!$dateField$}!is[system]$subfilter$!sort[$dateField$]]">
<div class="tc-menu-list-subitem">
<$link to={{!!title}}><<timeline-title>></$link>
</div>
</$list>
</div>
</$list>
</div>
\end

All I did was add
({{{ [sameday:$dateField${!!$dateField$}!is[system]$subfilter$count[]] }}})
which if you look closely is the next filter after removing the sort and adding the count[]

I suspect you are however wondering if a simpler macro could be written with the new filters?

And here is a little more refined counter display - only if 2 or more tiddlers.

<$text text={{{ [sameday:$dateField${!!$dateField$}!is[system]$subfilter$count[]compare:number:gt[1]addprefix[(]addsuffix[)]] }}}/>

1 Like

Thank you Tones! It works nicely! I think if I want to renew my Recent tab, your solution is a good alternative!

Added to TW-Scripts!

1 Like

it is a great idea!
But if I want to get the number of the tiddlers that the timeline macro returns at the top of the tiddler,how can I get it?
just like this:

5 matches
31th August 2021 (3)
Tiddler One
Another Tiddler
Tiddler Three
30th August 2021 (2)
This Tiddler
That Tiddler

But you’ll get performance problems if you run the same filter 2 times, just to be able to display the counter. I’d suggest to calculate the list elements first and then reuse them to be counted.

None of the operators used in the timeline macro are cached and using the “old” text substitution will also disable macro caching.

I think as Mohammad wrote the whole thing should be rewritten using v5.3.x functions procedures and the new substitute functionality.

1 Like

Welcome @yuholqjn

In the above macro I limit the total number to 100 so over time the count will equal 100, and a total count does not add much value in my use case, compared to the total per day.

thanks!
I would like to ask for advice:
I created a tiddler,input
<<timeline dateField:“modified” format:“YYYY-0MM-0DD” limit:1000 subfilter:“keyword[aaaaa]”>>,and made this tiddler a timeline macro to return some tiddlers with the keyword aaaaa。
I am new to tiddlywiki,now I want this timeline macro to show the total number of the tiddlers it returns at the tiddler top,what should I do?
Would you please give me some advice
just like this:

5 matches
31th August 2021 (3)
Tiddler One
Another Tiddler
Tiddler Three
30th August 2021 (2)
This Tiddler
That Tiddler

Sure @yuholqjn

We need to return to the timeline macro definition, find the filter used to list all the tiddlers, and use it again in the count widget eg; <$count filter="filter"/> or in the above macro;

  • Perhaps where the filter is; [!is[system]$subfilter$has[$dateField$]limit[$limit$]]
    • I removed the sort and eachday as I don’t think that is needed

I have not tested this but can tomorrow 14+ hours


Thanks very much!
It works great well,and so beautiful!

Ah. You are right I did overlook the 100 limit. So it should be OK.

I think I learn this from some gg thread or ask this before in this forum…

Count days in last year using all[]days:startDate[-365] and sum[], add condition by xxx[]then[1]else[0]

<$let
	AllDays={{{[all[]days:startDate[-365]field:calendarEntry[yes]tag[Sleeping]then[1]sum[]]}}}
	DaysThatStayUpLate={{{ 
[all[]days:startDate[-365]field:calendarEntry[yes]tag[Sleeping]get[startDate]parsedate[0hh]]
 :map[compare:number:gt[1]compare:number:lt[20]then[1]else[0]]
 :and[sum[]]
}}}
  SttayUpLatePercentage={{{[<DaysThatStayUpLate>divide<AllDays>]}}}
>

https://wiki.onetwo.ren/#最近一年熬夜的天数

Feel like this in local environment with private data, which is not available in online version:

2 Likes