Hello, there! I’ve been using TW for a while now, and I’m grateful for the software and the helpful community, whose messages have helped me solve problems I’ve encountered. However, I’m pretty stuck with this one, and I’d like to ask for your help.
Here is some background info:
- A tiddler tagged
Personmay have abirthdayfield - The
birthdayfield is in a timestamp format, eg.20000101120000000 - I’m trying to display a list of people whose birthday is this month. This is working. (Thank you to @KrisadaFantasy for your comments in this thread; this was very helpful!)
- I also want to display a list of people whose birthday is next month. This is not working.
A. Macros & Functions
<!-- stop-gap for now; ideally would work for all months -->
\function get-next-month-string(month) [<month>compare:number:eq[12]]:then[[01]] :else[[02]]
\define get-next-month() <<get-next-month-string $(month)$>>
<!-- Expects variable: `month` -->
<!-- Finds tiddlers with the `birthday` tag, -->
<!-- whose birthday starts with any four digits, -->
<!-- then matches the value for the `month` variable -->
\define birthdays-month-filter() [has[birthday]regexp:birthday[^\d{4}$(month)$]]:sort:string[get[birthday]splitregexp[^\d{4}|\d{9}$]!is[blank]]
<!-- This works: it displays a list of the expected tiddlers -->
\define birthdays-this-month()
<$let month={{{ [<now 0MM>] }}}>
<$list filter=<<birthdays-month-filter>>>
<<birthdayForPerson>>
</$list>
</$let>
\end
<!-- This doesn't work: it displays nothing -->
\define birthdays-next-month()
<!-- Creating a variable, `month`, as the next month after the current one -->
<$let month={{{ [<now 0MM>] }}} next-month={{{ [<get-next-month>] }}} month={{{ [<next-month>] }}}>
<$list filter=<<birthdays-month-filter>>>
<<birthdayForPerson>>
</$list>
</$let>
\end
\define birthdayForPerson()
<div>
🎂 <$view field=birthday format=date template="MMM DDth" />: {{!!title}}
</div>
\end
B. Data
Assuming I have the following Person tiddlers, and that today is a date in December:
- Alice: birthday
20201201120000000(current month) - Bob: birthday
20201209120000000(current month) - Charlie: birthday
20200105120000000(next month) - Dee: birthday
20200124120000000(next month)
C. Output
If this is the tiddler where I want to display the birthday info:
!! Birthdays this month
<<birthdays-this-month>>
!! Birthdays next month
<<birthdays-next-month>>
The following is displayed:
Birthdays this month
1st December: Alice
9th December: Bob
Birthdays next month
(empty – should show Charlie and Dee)
D. Questions
- What am I doing wrong?
- I struggled with finding a way to get the next month. I wanted to use a function, but then it got tricky passing in the parameter, because that itself would have to come from a variable, and I got snarled up in the syntax.
- Is there a better way of organizing my macros and functions? A better way to pass the information around? A more elegant way of calculating ‘next month’ without resorting to having to counting month days and considering leap years, etc.? I’d be quite happy to write JavaScript code to accomplish this
1st December: Alice