I created a random quote generator for my Angular app. The component code is as follows:
qotd = this.quotes[Math.floor(Math.random() * this.quotes.length)];
Extract data that looks like this:
quotes = [ { quote: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus euismod magna magna, euismod tincidunt libero dignis.", author: 'Sorato Violasa' }, { quote: "Nullam dignissim accumsan magna vitae rhoncus. Phasellus euismod magna magna, euismod tincidunt libero dignis.", author: 'Vito Dignaora' }, { quote: "In tincidunt imperdiet augue, quis sollicitudin mi tincidunt ut.", author: 'Hivalo Amettioa' }, { quote: "hasellus accumsan erat vitae enim blandit, quis euismod ipsum sollicitudin.", author: 'Grasha Plojiva' }, ];
And then, in my opinion, I do this:
<div class="quotes"> <p class="quote"> {{qotd.quote}} <br><br> ~ {{qotd.author}} </p> </div>
The fact is that now it will generate a new quote every time the component restarts, which can be several times in one session. Now I understand that itβs better to make this a daily quote generator. Therefore, when the date changes, a new quote will be generated. What is the easiest way to implement something like this? Itβs easy enough to create a date and day of the week, for example:
date = new Date(); dayNumber = this.date.getDay();
But how would I calculate when the day of the week changes to start a new instance?