Thanks so much for this Eric, it's really helpful. Once I get my head 
around your script/code, with the help of your notes, I'll have a better 
understanding of how to do this sort of thing... I'll be playing with this 
for a while!

Take care,

Anthony

On Monday, 5 October 2020 at 13:54:48 UTC+1 Eric Shulman wrote:

> On Monday, October 5, 2020 at 3:32:51 AM UTC-7, Anthony wrote:
>>
>> 1. When one uses the '....MMDD' date format then the event (e.g. birth) 
>> is also included for years before that event - I can't quite decide whether 
>> it's okay for this to happen so I'm wondering whether there's a way to 
>> include a 'start date' for a re-occurring event?
>>
>
>
> The "event tiddler" format is a single tiddler containing multiple events 
> listed as one event per line of text.
> and the "start-date/end-date" fields are only used when creating 
> individual "Timelines and Journals" tiddlers.
>
> As you noted, the "....MMDD" date format is for annual events, regardless 
> of the year.
> You can, of course, specify repeating birthdays events using multiple 
> "YYYYMMDD" entries.
>
> Thus:
> ....0724;Eric's Birthday
> vs.
> 20200724;Eric's Birthday
> 20210724;Eric's Birthday
> 20220724;Eric's Birthday
> 20230724;Eric's Birthday
> 20240724;Eric's Birthday
>
> 2. I thought it would be appropriate to use a field to store, let's say, 
>> date of birth or death and then use some 'mechanism' to put the event into 
>> an events tagged tiddler. I'm still learning about what 'mechanism' might 
>> do this and I may be completely misunderstanding the use of fields but is 
>> this a reasonable approach?
>>
>
> You could use a button gets "birthdate" and "deathdate" values from 
> fields, and then generates an "events tiddler".
>
> Here's something I just cooked up:
> \define birthday_tiddler() BirthdayList
> \define lifetime()         [range[$(birthyear)$,$(deathyear)$]]
> \define makebirthdays()
> <$vars newline="
> ">
> <$vars birthyear={{{ [{!!birthdate}split[]first[4]join[]] }}}>  <!-- YYYY 
> -->
> <$vars birthdate={{{ [{!!birthdate}split[]rest[4]join[]]  }}}>  <!-- MMDD 
> -->
> <$vars deathyear={{{ [{!!deathdate}split[]first[4]join[]] }}}>  <!-- YYYY 
> -->
> <$set name="deathyear" value=<<deathyear>> emptyValue={{{ 
> [<birthyear>add[100]] }}} >
> <$button> add birthdays to <$text text=<<birthday_tiddler>>/>
>    <$list filter=<<lifetime>> variable="year">
>       <$vars event={{{ [<year>addsuffix<birthdate>addsuffix[;Birthday: 
> ]addsuffix<currentTiddler>addsuffix<newline>] }}}>
>          <$list filter="[<birthday_tiddler>!search:text:literal<event>]">
>             <$action-setfield tag="events" type="text/plain" text={{{ 
> [{!!text}addsuffix<event>] }}}/>
>          </$list>
>       </$vars>
>    </$list>
> </$button>
> \end
> <$list filter="[<currentTiddler>has[birthdate]]"> <<makebirthdays>> 
> </$list>
>
> Place the above code into a tiddler, "MakeBirthdays", tagged with 
> "$:/tags/ViewTemplate".
> Then, create a tiddler, e.g, "John Smith" with a "birthdate" field 
> containing a YYYYMMDD
> value and an optional "deathdate" field containing another YYYYMMDD value
>
> Because "MakeBirthdays" is tagged with $:/tags/ViewTemplate and "John 
> Smith"
> contains a "birthdate" field, this will automaticaly show the "add 
> birthdays" button at
> the bottom of the "John Smith" tiddler.  When you press the button, it 
> will generate
> the birthday events based on the "birthdate" and "deathdate" values and 
> add them
> to the "BirthdayList" tiddler
>
> Here's how the code works:
> 1) First, we define a few "utility" macros:
> * birthday_tiddler() is just a convenience so we can easily change the 
> output tiddler name
> * lifetime() is used to construct the filter syntax needed to generate a 
> range of years, based on the birthdate and deathdate field values
>
> 2) Next, the makebirthdays() macro does the work:
> * $vars newline=... defines a variable for inserting a literal newline 
> into the output tiddler.  Note the linebreak in between the quotes is 
> important!
> * $vars birthyear=... extracts the YYYY from the "birthdate" field of the 
> current tiddler
> * $vars birthdate=... extracts the MMDD from the "birthdate" field of the 
> current tiddler
> * $vars deathyear=... extracts the YYYY from the "deathdate" field of the 
> current tiddler
> * $set name="deathyear" ... does a "fixup" if there is no defined 
> "deathdate" value, using birthyear+100 as a fallback value
> * $button starts the definition of the button
> * The first $list filter=<<lifetime>> ... loops through the range of years 
> from birthyear to deathyear
> * $vars event=... constructs the event syntax output for the current year
> * The second $list searches the birthday_tiddler text to make sure that 
> the event hasn't already been added
> * $action-setfield appends the event syntax for the current year to the 
> current content of the output tiddler
>
> 3) Following the macro:
> * $list filter="[<currentTiddler>has[birthdate]]" limits the 
> <<makebirthdays> button to only appear in tiddlers that have a non-blank 
> birthdate field
>
> Hope this all makes sense!
>
> enjoy,
> -e
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/fea64388-44ab-42ad-b9d7-c510b020eaa1n%40googlegroups.com.

Reply via email to