Lightbox popup between certain times

Hi,

Looking to add code to page to have a one time popup for site visitors between 3pm and 9am PST.

Thanks

One time ? Or one time per day?
Let’s say one time per day.
So:

import wixWindow from 'wix-window';
import {local} from 'wix-storage';
let now = new Date();
let PST = (now.getUTCHours() + 16) % 24;
if (local.getItem("status") !== "done" && (PST >= 15 || PST < 9)){
    local.setItem("status", "done");
    wixWindow.openLightbox("Lightbox Name");
}

[had a typo. fixed]

amazing JD, if we wanted each time someone navigated to a page in that time range would we take away the local.setltem line?

@alistair yes, and the local.getItem condition.

@alistair forgot to subtract from the utc.
It should be:
let PST = now.getUTCHours() - 8 ;
because this is the difference between utc and pst.

Or more correct (to cover all the options), I think:
let PST = (now.getUTCHours() + 16) % 24;

@J. D. thanks again for the help on this.

There is just one catch - at the moment the I am getting an " parsing error: unexpected token" on line 15 for the } at the end. It looks like this close the { on line 12 so should be working… any thoughts? - the code is below for reference.

import wixWindow from ‘wix-window’;
import {local} from ‘wix-storage’;
$w.onReady( function () {
//TODO: write your page related code here…
let now = new Date();
let PST = (now.getUTCHours() + 16) % 24;
if (local.getItem(“status”) !== “done” && (PST >= 15 || PST < 9)){
local.setItem(“status”, “done”);
wixWindow.openLightbox(“CUT OFF”);
}

You should close the $w.onReady function i.e. add:
})
in the end of your code.