M
M
mixejuxix2019-09-10 13:49:31
Algorithms
mixejuxix, 2019-09-10 13:49:31

How would you implement such a mechanism?

Hello, how would you implement the following trick:
There is a site engine with a bunch of different texts, I want to be able to insert some bbcode-like labels into these texts
For example:
5d777f17a712f764026385.png
The label should be converted to a date according to the principle "now + 3 days" and cached on 3 days
That is, if today's date is
01/01/2019: Promotion valid until 01/03/2019
01/02/2019: Promotion valid until 01/03/2019
01/03/2019: Promotion valid until 01/03/2019
01/04/2019: Promotion valid until 01/07/2 caching is reset, add 3 days to today's number and cache for another 3 days
The problem is that there is absolutely no desire to use any database for this
Maybe someone will tell you how to implement this mathematically, without saving the start date somewhere in the database?
For example, the start date could be stored in the text field itself, and then dance from this number, calculating in what numbers you need to "reset the cache"
5d777f2bdd317200190164.png
Tell me, please, can someone do something similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
denisromanenko, 2019-09-10
@denisromanenko

If you go crazy and don’t use a template engine on the backend, then just make a JS script that, using document.onload , will find tags with data-id=dateTmpl , get data from them and change their text.
Let's say there is a tag:
Promotion until

<span data-id="dateTmpl" data-start="10.09.2019" data-days="3"></span>

1. We are looking for all such tags on the page
2. Calculate the date for each tag
3. Change the text of the tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question