Enforcing offline hours
Olark will automatically detect when you have agents available to chat.
However, there may be cases where you want to force Olark to display as unavailable even when you have available agents - for example, if you want to enforce particular off-hours in the evening.
You’ll want to get the get the current time. The quickest way to do this is to get the visitor’s browser time:
var now = new Date(); var hourOfDayInUTC = now.getUTCHours();
Be aware, however, that a visitor’s browser time may not be accurate. For a more robust solution, you may wish to use your server time or find an alternative method.
In our case, we want to calculate the time relative to San Francisco.
// PST is 8 hours behind GMT so we use -8. Change the -8 to // your timezones difference from GMT. var differenceFromUTC = -8; var currentHour = hourOfDayInUTC + differenceFromUTC;