How would I be able to display a spoiler alert on tiddlers based on date

I want to be able to have a spoiler alert warning appear on tiddlers based on a field called original-air-date, using the format YYYY-0MM-0DD. The warning should last seven days from the date in the field.

@RedAsset consider using the days operator.

I could write a solution but I would in part need to design it because you dont spell out what you want.

For example Just display a message or hide the text until +7 days pass…

Compare with today using the now macro.

The days filter operator requires a 17-digit “system datestamp” value stored in a tiddler field (e.g., the value stored in a tiddler’s created or modified field).

To compare a date that uses “YYYY-0MM-0DD” format, you can use my TiddlyTools Time convertdate[timestamp] filter:

https://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FConvertDate%2FFilter

After copying the above tiddler into your TiddlyWiki (plus save-and-reload for it to take effect),
you can write something like this:

original-air-date: <$edit-text field="original-air-date"/>

<$let
   original={{{ [<currentTiddler>get[original-air-date]convertdate[timestamp]] }}}
      today={{{ [<now "YYYY-0MM-0DD">convertdate[timestamp]] }}}
   duration={{{ [[7]multiply[24]multiply[60]multiply[60]multiply[1000]] }}}
 is_spoiler={{{ [<original>add<duration>compare:integer:gteq<today>then[yes]else[no]] }}}>

<$list filter="[<is_spoiler>match[yes]]">@@color:red;SPOILER WARNING!@@</$list>

Notes:

  • First, convert the original air date and today’s date to standardized “epoch timestamps” (the number of milliseconds since January 1st, 1970).
  • Next, calculate the number of milliseconds duration of the spoiler (i.e., 7 days)
  • Then, if the original air date + duration is greater than today’s date, the spoiler warning is still in effect.

enjoy,
-e

4 Likes