Implementing a countdown bbcode

AI-generated summary

marcozambi is seeking help to develop a “countdown” bbcode for Discourse that converts [countdown=<iso date and time>] into a live textual countdown (ddd:hh:mm:ss). They’ve successfully tested JavaScript for calculating time intervals in the theme header but are stuck on detecting the bbcode in post raw text, validating the ISO date, and dynamically replacing the cooked text with the countdown. They’re considering mimicking Discourse’s built-in [date ...] functionality but ask if there’s a better approach. pfaffman suggests looking at the calendar plugin, which performs similar dynamic date/time rendering.

Hi all!
I would like some help for starting the development of a “countdown” bbcode that, as the name says, will display a countdown in a post.
The idea is to translate something like this [countdown=<iso date and time>] into a simple textual countdown of the format ddd:hh:mm:ss where d is days, h is hours, m is minutes and s is seconds.

The experiments I did so far was inserting some js code to calculate the amount of days, hours and so on. I inserted it in the header part of the theme through the theme editing interface, and I can display the countdown in the js console no probs.

The tricky part, even after having read the Developing Discourse Themes & Theme Components , is to find a way to:

  • find whether the post raw text contains a [countdown ...] tag
  • get the iso date in it and validate it
  • if validation succeeds, start the countdown js function and perform text substitution in the post cooked text

I was thinking to get some inspiration from the code that performs the [date ...] function provided by Discourse. Would that be a valid choice? Could you suggest any better alterntive?

Thanks in advance!

I would look at the calendar plugin that does something similar.