Add date to lightbox

hello, I’m quite new to coding and I need help.
I’ve got a lightbox that I made using Wix tools that says “The shop is closed for this weekend, we will reopen on Sunday at 20:00”
the lightbox is automatically shown on the weekend using a code I got from this forum.

is there a way I can integrate the Sunday date automatically into the lightbox text using corvid code? so it will say something like
“The shop is closed for this weekend, we will reopen on Sunday, November 22 at 20:00”

thank you very much!

const date = new Date();
const todayDay = date.getDay();
let distanceFromSunday;
todayDay === 0 ?  distanceFromSunday = 0 : distanceFromSunday =  7 - todayDay;
const sundayDate = new Date(Date.now() + distanceFromSunday * 86400000);
const formattedDate = sundayDate.toLocaleDateString('en-US', {month: 'long', day: 'numeric'});
$w("#text1").text = `The shop is closed for this weekend, we will reopen on Sunday, ${formattedDate} at 20:00`;

[FIXED]

@jonatandor35 thank you very much, it works great.
another question, wouldn’t it work with only this:

distanceFromSunday =  7 - todayDay;

instead of the whole line

todayDay === 0 ?  distanceFromSunday = 0 : distanceFromSunday =  7 - todayDay;

thank you again

@asafhel The line you suggested will work well except if today is Sunday.
If today is Sunday, it’ll show the date of next Sunday (since the value of Sunday is 0, and 7 - 0 equal 7, you’ll add 7 day to the current date) .
The line I suggested addresses this issue and shows today date (if it’s Sunday).

But if you prefer a shorter line you can use:

let distanceFromSunday = (7 - todayDay) % 7;

and delete the following line:

todayDay === 0 ?  distanceFromSunday = 0 : distanceFromSunday =  7 - todayDay;

@jonatandor35 if i used any other day than sunday then it will be ok?

@asafhel You’ll have to make adjustments:

const dueDay = 2;//Sunday is 0, Monday is 1, Saturday is 6. 
const todayDay = new Date().getDay();
const distanceFromDueDay = (14 - todayDay + dueDay) % 7;
const dueDate = new Date(Date.now() + distanceFromDueDay * 86400000);
const formattedDate = dueDate .toLocaleDateString('en-US', {month: 'long', day: 'numeric'});
$w("#text1").text = `The shop is closed for this weekend, we will reopen on Sunday, ${formattedDate} at 20:00`;