sample java code you can use the pabbly code feature -- to determine if the current time is in business hours, if not how many minutes to add to a delay step before business open time.
function getPacificTime() {
var now = new Date();
// Determine Pacific Time offset based on current date for DST (PDT or PST)
var isDST = now.getMonth() > 2 && now.getMonth() < 10; // Simple DST check (March to October)
var pacificOffset = isDST ? -7 : -8;
// Adjust UTC time to Pacific Time
var pacificTime = new Date(now.getTime() + pacificOffset * 60 * 60 * 1000);
return pacificTime;
}
function getBusinessAdjustedTime() {
var pacificTime = getPacificTime();
var pacificHour = pacificTime.getHours();
var pacificMinutes = pacificTime.getMinutes();
// Business hours: 9 AM - 6 PM
var startHour = 9;
var endHour = 18;
var nextOpen = new Date(pacificTime);
var diffMinutes;
if (pacificHour >= startHour && pacificHour < endHour) {
// Within business hours, 0 minutes until next opening
diffMinutes = 0;
} else {
// Calculate time until next business opening
if (pacificHour >= endHour) {
// Move to the next day at 9 AM
nextOpen.setDate(nextOpen.getDate() + 1);
}
nextOpen.setHours(startHour, 0, 0, 0);
// Calculate the difference in milliseconds
var diffMs = nextOpen - pacificTime;
diffMinutes = Math.floor(diffMs / (1000 * 60));
}
// Output two variables
var currentTime = pacificTime.toLocaleString('en-US');
return { diffMinutes, currentTime };
}
// Run the function to get the result
var result = getBusinessAdjustedTime();
var minutesUntilNextOpen = result.diffMinutes;
var currentDateTime = result.currentTime;
return { minutesUntilNextOpen, currentDateTime };
The code outputs two separate variables—minutesUntilNextOpen and currentDateTime that you can use.