var jsonHoursArray = [];
var jsonHoursObject = {};
var weekdayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var customWeekdayNames = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var processedHours = [];
var currDate = new Date();
currDate.setHours(0,0,0,0);
var yesterday = new Date();
yesterday.setHours(0,0,0,0);
yesterday.setDate(currDate.getDate() - 1);
var today = new Date();
today.setHours(0,0,0,0);
today.setDate(currDate.getDate());
var weekdayNumber = today.getDay();
var overrideDayLimit = new Date();
function mergeHours() {
for(lid in hours) {
for(weekdays in weekdayNames) {
if(typeof hours[lid][hourSetName]['days'] != 'undefined' && typeof hours[lid][hourSetName]['days'][weekdayNames[weekdays]] == 'undefined') {
hours[lid][hourSetName]['days'][weekdayNames[weekdays]] = 'closed';
}
}
if(hoursType == 2 && hasChildHours(hours[lid][hourSetName], 'alternates')) {
//Alternate or Supplemental
hours[lid][hourSetName] = getChildHours(hours[lid][hourSetName], 'alternates');
}
if(hasChildHours(hours[lid][hourSetName], 'overrides')) {
//Exception Hours
hours[lid][hourSetName] = getChildHours(hours[lid][hourSetName], 'overrides');
}
}
}
Date.prototype.addHours= function(h){
this.setHours(this.getHours()+h);
return this;
}
function getRearrangedDays(timeZoneOffset, startDay, days) { //Arrange Days properly after 5PM since it is displaying UTC time.
timeZoneOffset = parseInt(timeZoneOffset);
timeZoneOffset = timeZoneOffset >= 0 ? "+" + timeZoneOffset : timeZoneOffset;
var currDate = new Date();
var currTimezoneOffset = currDate.getTimezoneOffset() / 60;
var adjustHours = parseFloat(currTimezoneOffset) + parseFloat(timeZoneOffset);
if(startDay !== '' && startDay !== false) {
weekday = startDay;
} else {
weekday = new Date().addHours(adjustHours).getDay();
}
tempDays = [];
for(i = 0; i < 7; i++) {
tempDays[weekdayNames[(i + weekday) % 7]] = days[(i + weekday) % 7];
}
return tempDays;
}
function printHoursTable() {
var now = new Date();
for(lid in hours) {
for(type in hours[lid]) {
var isRearranged = false;
var timezone = hours[lid].timezone;
var days = dictionary['DAYS_JS'][urlCountryCode];
var html = '
';
if(typeof timezone == 'undefined' || timezone == '') {
timezone = hours[lid][type].timezone;
}
if(hoursType == 2 && hasChildHours(hours[lid][type], 'alternates')) {
//Alternate or Supplemental
if(isRearranged == false && rearrangeHours == true) {
days = getRearrangedDays(timezone, false, days);
isRearranged = true;
}
}
if(hasChildHours(hours[lid][type], 'overrides')) {
//Exception Hours
if(isRearranged == false && rearrangeHours == true) {
days = getRearrangedDays(timezone, false, days);
isRearranged = true;
}
}
if(isRearranged == false) {
days = getRearrangedDays(timezone, startDay, days);
}
if(collapseHours == true && hasChildHours(hours[lid][type], 'overrides') == false && hasChildHours(hours[lid][type], 'alternates') == false) {
days = getCollapsedDays(hours[lid][type], days);
}
var closedCounter = 0;
var noHoursCounter = 0;
for(day in days) {
if(weekdayNames[now.getDay()] == customWeekdayNames[day]) {
html += '
';
} else {
html += '
';
}
html += '
' + days[day] + hoursDivider + '';
html += '
';
if(typeof hours[lid][type]['days'] == 'undefined') {
html += '' + dictionary['CLOSED'][urlCountryCode] + '';
noHoursCounter++;
} else if(typeof hours[lid][type]['days'][day] == 'undefined') {
html += '' + dictionary['CLOSED'][urlCountryCode] + '';
noHoursCounter++;
} else if(hours[lid][type]['days'][day] == "closed") {
html += '' + dictionary['CLOSED'][urlCountryCode] + '';
closedCounter++;
} else if(hours[lid][type]['days'][day] == "open24") {
html += '' + dictionary['OPEN_24_HOURS'][urlCountryCode] + '';
} else {
for(i = 0; i < hours[lid][type]['days'][day].length; i++) {
var openTime = hours[lid][type]['days'][day][i].open.split(":");
var closeTime = hours[lid][type]['days'][day][i].close.split(":");
now.setHours(openTime[0]);
now.setMinutes(openTime[1]);
openTime = dateCustom(timeFormat, now);
now.setHours(closeTime[0]);
now.setMinutes(closeTime[1]);
closeTime = dateCustom(timeFormat, now);
timeRow = hours[lid][type]['days'][day].length > 1 ? (i + 1) : '';
html += '';
html += '' + openTime + '';
html += ' - ';
html += '' + closeTime + '';
html += '';
}
}
html += '';
html += '
';
html += '
';
}
html += "
";
if(noHoursCounter >= 6) {
jQuery_3_5('.js-hours-' + type + '-' + lid).html("
" + dictionary['NO_HOURS_MESSAGE'][urlCountryCode] + "
").addClass('has-no-hours');
} else if(closedCounter >= 6) {
jQuery_3_5('.js-hours-' + type + '-' + lid).html("
" + dictionary['TEMPORARILY_CLOSED'][urlCountryCode] + "
").addClass('has-no-hours');
} else {
jQuery_3_5('.js-hours-' + type + '-' + lid).html(html);
}
}
}
}
function printExceptionHoursTable(upcomingDaysLimit) {
var overrideDayLimit = new Date();
overrideDayLimit.setHours(0,0,0,0);
overrideDayLimit.setDate(overrideDayLimit.getDate() + upcomingDaysLimit);
for(lid in hours) {
for(type in hours[lid]) {
if(hasChildHours(hours[lid][type], 'overrides', upcomingDaysLimit)) {
var tempHours = hours[lid][type];
var html = '
';
for(var subset in tempHours.children) {
if(tempHours.children[subset].type == "1" && typeof tempHours.children[subset].overrides != 'undefined') {
for(var key in tempHours.children[subset].overrides) {
//Since there are no hours in key, we need to set hours to 00:00;
overrideDate = getValidDateFormat(key + " 00:00");
overrideWeekday = overrideDate.getDay();
if(overrideDate >= today && overrideDate < overrideDayLimit && typeof tempHours['days'] != 'undefined') {
if(typeof tempHours['days'] != "undefined" && tempHours['days'][weekdayNames[overrideWeekday]]) {
if(weekdayNames[currDate.getDay()] == customWeekdayNames[day]) {
html += '
';
} else {
html += '';
}
var exceptionDay = new Date(key + ' 00:00');
html += '' + dateCustom("l, m/d", exceptionDay) + '';
html += '';
if(tempHours.children[subset].overrides[key] == 'closed') {
html += '' + dictionary['CLOSED'][urlCountryCode] + '';
} else if (tempHours.children[subset].overrides[key] == 'open24') {
html += '' + dictionary['OPEN_24_HOURS'][urlCountryCode] + '';
} else {
var openTime = tempHours.children[subset].overrides[key][0]['open'].split(":");
var closeTime = tempHours.children[subset].overrides[key][0]['close'].split(":");
var tempDate = new Date();
tempDate.setHours(openTime[0]);
tempDate.setMinutes(openTime[1]);
openTime = dateCustom(timeFormat, tempDate);
tempDate.setHours(closeTime[0]);
tempDate.setMinutes(closeTime[1]);
closeTime = dateCustom(timeFormat, tempDate);
html += '';
html += '' + openTime + '';
html += ' - ';
html += '' + closeTime + '';
html += '';
}
html += '';
html += '';
html += '';
}
}
}
}
}
html += '
';
jQuery_3_5('.js-hours-' + type + '-exception-' + lid).html(html);
} else {
jQuery_3_5('.js-hours-' + type + '-exception-title-' + lid).hide();
}
}
}
}
function printSmartSentence(processedHours, printSmartSentenceCallback) {
var currentDateUTC = getTimeUTC();
var currentTimestampUTC = currentDateUTC.getTime();
var now = new Date();
var weekday = now.getDay();
for(var i = 0; i < processedHours.length; i++) {
weekday = now.getDay();
var showTimezone = getTimezoneText(processedHours[i]);
var incrementByOne = 0;
var openTimestampUTC = processedHours[i].processedHours[weekday].openingTimestamp;
var closeTimestampUTC = processedHours[i].processedHours[weekday].closingTimestamp;
var openTimePretty = processedHours[i].processedHours[weekday].openingTimePretty;
var closeTimePretty = processedHours[i].processedHours[weekday].closingTimePretty;
var rollingHours = false;
var nextDay = 0;
if(weekday != 6) {
nextDay = (weekday + 1) % 7;
}
if(closeTimestampUTC == processedHours[i].processedHours[nextDay].openingTimestamp || (closeTimePretty == '12' + dictionary['AM'][urlCountryCode] && processedHours[i].processedHours[nextDay].open24 == 'open24')) {
rollingHours = true;
}
if(processedHours[i].processedHours[weekday].open24 == 'open24') {
html = dictionary['OPEN_24_HOURS'][urlCountryCode];
className = 'is-open';
} else if (((closeTimestampUTC - currentTimestampUTC) <= (60*60*1000)) && ((closeTimestampUTC - currentTimestampUTC) >= 0 && !rollingHours)) {
var minutes = parseInt((closeTimestampUTC - currentTimestampUTC) / 1000 / 60)
html = minutes == 1 ? dictionary['CLOSING_IN_MINUTE'][urlCountryCode] : dictionary['CLOSING_IN_MINUTES'][urlCountryCode];
html = html.replace('%minutes', minutes);
className = 'is-closing-soon';
} else if (currentTimestampUTC > openTimestampUTC && currentTimestampUTC < closeTimestampUTC) {
if(rollingHours) {
closeTimePretty = processedHours[i].processedHours[nextDay].closingTimePretty;
closeTimePretty = closeTimePretty == '' ? "12AM" : closeTimePretty;
html = dictionary['OPEN_UNTIL_TOMORROW_AT'][urlCountryCode];
} else {
html = dictionary['OPEN_TODAY_UNTIL_TIME'][urlCountryCode];
}
html = html.replace('%time', closeTimePretty);
html = html.replace('%timezone', showTimezone);
className = 'is-open';
} else if(currentTimestampUTC < getYesterdayCloseTimeStamp(processedHours[i], weekday)) { //The store is still open from yesterday
weekday = weekday == 0 ? 6 : weekday - 1;
closeTimePretty = processedHours[i].processedHours[weekday].closingTimePretty;
html = dictionary['OPEN_TODAY_UNTIL_TIME'][urlCountryCode];
html = html.replace('%time', closeTimePretty);
html = html.replace('%timezone', showTimezone);
className = 'is-open';
}else if (currentTimestampUTC < openTimestampUTC) {
html = dictionary['REOPENING_TODAY_AT_TIME'][urlCountryCode]
html = html.replace('%time', openTimePretty);
html = html.replace('%timezone', showTimezone);
className = 'is-closed';
} else if (currentTimestampUTC < closeTimestampUTC) {
html = dictionary['OPEN_TODAY_UNTIL_TIME'][urlCountryCode];
html = html.replace('%time', openTimePretty);
html = html.replace('%timezone', showTimezone);
className = 'is-open';
} else {
var nextOpenWeekday = getNextOpeningDay(processedHours[i], weekday);
var hasHours = doesLocationHaveHours(processedHours[i]);
className = 'is-closed';
if(!hasHours) {
html = dictionary['NO_HOURS_MESSAGE'][urlCountryCode];
className = 'is-closed has-no-hours';
} else if(nextOpenWeekday == 7) {
html = dictionary['TEMPORARILY_CLOSED'][urlCountryCode];
className = 'is-closed temporarily-closed';
} else {
if(processedHours[i].processedHours[nextOpenWeekday].openingTimePretty == '') {
if(nextOpenWeekday == (weekday + 1) % 7) {
html = dictionary['CLOSED_UNTIL_MIDNIGHT'][urlCountryCode];
} else {
nextOpenDay = dictionary['DAYS'][urlCountryCode][nextOpenWeekday];
html = dictionary['CLOSED_UNTIL_DAY_AT_MIDNIGHT'][urlCountryCode];
html = html.replace('%day', nextOpenDay);
}
} else {
if(nextOpenWeekday == ((weekday + 1) % 7)) {
html = dictionary['CLOSED_UNTIL_TOMORROW_AT_TIME'][urlCountryCode];
html = html.replace('%time', processedHours[i].processedHours[nextOpenWeekday].openingTimePretty);
html = html.replace('%timezone', showTimezone);
} else {
nextOpenDay = dictionary['DAYS'][urlCountryCode][nextOpenWeekday];
html = dictionary['CLOSED_UNTIL_DAY_AT_TIME'][urlCountryCode];
html = html.replace('%day', nextOpenDay);
html = html.replace('%time', processedHours[i].processedHours[nextOpenWeekday].openingTimePretty);
html = html.replace('%timezone', showTimezone);
}
}
}
}
//Replaced left over () from international timezones
html = html.replace('()', '');
//Hightlight Current Weekday within Time Table
jQuery_3_5('.hours[data-hours-lid="' + processedHours[i].lid + '"]').find('.daypart').each(function() {
var dayOfWeek = jQuery_3_5(this).attr('data-daypart');
if (typeof dayOfWeek != 'undefined' && dayOfWeek.indexOf(weekdayNames[weekday]) > -1) {
jQuery_3_5(this).parent('.day-hour-row').addClass('active');
if(printInline == true) {
jQuery_3_5(this).parent('.day-hour-row').addClass(className);
jQuery_3_5(this).next().text(html).addClass(className);
}
}
});
if(printHoursType == true) {
for(hourType in hourTypes) {
if(processedHours[i].type == hourType) {
html = hourTypes[hourType] + " " + html;
}
}
}
if(processedHours[i].timezoneOffsetDefined == true || nextOpenWeekday == 7) {
jQuery_3_5('.status-'+ processedHours[i].type +'-' + processedHours[i].lid).html(html).addClass(className);
}
}
printSmartSentenceCallback();
}
function getNextOpeningDay(hour, weekday) {
//Get Next Opening Day
for(weekdayCounter = 1; weekdayCounter <= 7; weekdayCounter++) {
var z = ((weekdayCounter + weekday) % 7)
if(hour.processedHours[z].openingTimePretty != '' || hour.processedHours[z].open24== 'open24') {
weekday = z;
break;
}
if(weekdayCounter == 7) {
weekday = weekdayCounter; //Return 7 as closed
}
}
return weekday;
}
function doesLocationHaveHours(hour) {
var hasNoHours = 0;
//Get Next Opening Day
for(var i = 0; i < 7; i++) {
if(hour.processedHours[i].hasNoHours == 'has-no-hours') {
hasNoHours++;
}
}
return hasNoHours == 7 ? false : true;
}
function getYesterdayCloseTimeStamp(hour, weekday) {
var closingTime = new Date();
//Get Next Opening Day
if(weekday > 0) {
weekday = weekday - 1;
if(hour.processedHours[weekday].closingTimestamp != '') {
return hour.processedHours[weekday].closingTimestamp;
}
} else {
if(hour.processedHours[6].closingTimestamp != '') {
closingTime.setTime(parseInt(hour.processedHours[6].closingTimestamp) - ((24 * 60 * 60 * 1000) * 7));
return closingTime.getTime();
}
}
return;
}
function getDaylightSavingsFromProfileField(hours) {
var timezoneAbbreviations = {"HAW": 1, "MST": 1, "MSTNO": 0, "CST": 1, "CSTNO": 0, "EST": 1, "AST": 1, "ALA": 1, "PST": 1};
if(typeof(timezoneAbbreviations[hours.timezone]) != "undefined" && timezoneAbbreviations[hours.timezone] != '') {
return timezoneAbbreviations[hours.timezone];
} else {
return hours.dst;
}
}
function getTimezoneOffsetFromProfileField(timezone) {
var timezoneAbbreviations = {"HAW": "-10", "MST": "-7", "MSTNO": "-7", "CST": "-6", "CSTNO": "-6", "EST": "-5", "AST": "-4", "ALA": "-9", "PST": "-8"};
if(typeof(timezoneAbbreviations[timezone]) != "undefined" && timezoneAbbreviations[timezone] != '') {
return timezoneAbbreviations[timezone];
} else {
return timezone;
}
}
function getProcessedHours() {
var processedHours = [];
//Empty jsonHoursArray for next search
jsonHoursArray = [];
var dayOfTheWeek = weekdayNumber
if (hours.length == 0) return processedHours;
for(var lid in hours) {
for(var type in hours[lid]){
if (type == "timezone" || type == "dst") {
continue;
}
var temp = {};
var daylightSavingsOffset = 0;
// Set known values for lid, timezone offset, and observes daylight savings
if(typeof hours[lid].dst != 'undefined' && hours[lid].dst != null && hours[lid].dst != '') {
temp.observesDLS = getDaylightSavingsFromProfileField(hours[lid]);
} else if((typeof hours[lid][type].dst == 'undefined' || hours[lid][type].dst == null) && typeof hours[lid]['primary'] != 'undefined' && hours[lid]['primary'].dst != null){
temp.observesDLS = hours[lid]['primary'].dst;
} else if(typeof hours[lid][type].dst != 'undefined' && hours[lid][type].dst != null){
temp.observesDLS = hours[lid][type].dst;
} else {
temp.observesDLS = 0;
}
temp.timezoneOffsetDefined = true;
if(typeof hours[lid].timezone != 'undefined' && hours[lid].timezone != null && hours[lid].timezone != '') {
temp.timezoneOffset = getTimezoneOffsetFromProfileField(hours[lid].timezone);
} else if((typeof hours[lid][type].timezone == 'undefined' || hours[lid][type].timezone == null) && typeof hours[lid]['primary'] != 'undefined' && hours[lid]['primary'].timezone != null){
temp.timezoneOffset = hours[lid]['primary'].timezone;
} else if(typeof hours[lid][type].timezone != 'undefined' && hours[lid][type].timezone != null) {
temp.timezoneOffset = hours[lid][type].timezone;
} else {
temp.timezoneOffset = 0;
temp.timezoneOffsetDefined = false;
}
temp.lid = lid;
temp.timezone = dictionary['TIME_ZONE_ABBREVIATIONS'][urlCountryCode][temp.timezoneOffset];
temp.processedHours = [];
temp.type = type;
//Since we need to convert the regular time
if(getDaylightSavings() && temp.observesDLS == 1) daylightSavingsOffset = 1;
timezoneAdjustment = parseInt(temp.timezoneOffset) + parseInt(daylightSavingsOffset);
// Iterate through all hours from JSON object and setup processedHours */
for (var weekday in weekdayNames) {
if(typeof hours[lid][type].days == 'undefined' || typeof hours[lid][type].days[weekdayNames[weekday]] == 'undefined' || hours[lid][type].days[weekdayNames[weekday]] == 'open24' || hours[lid][type].days[weekdayNames[weekday]] == 'closed') {
openingTimePretty = '';
openingTimestamp = '';
closingTimePretty = '';
closingTimestamp = '';
openingDate = '';
closingDate = '';
} else {
var timeOpen = hours[lid][type].days[weekdayNames[weekday]][0].open;
var timeClose = hours[lid][type].days[weekdayNames[weekday]][0].close;
//Only add Siests Hours if they exist and are needed for today.
if(hours[lid][type].days[weekdayNames[weekday]].length > 1 && weekday == currDate.getDay()) {
for(i = 1; i < hours[lid][type].days[weekdayNames[weekday]].length; i++) {
var currentDateUTC = getTimeUTC();
timeCloseHour = parseInt(timeClose.split(':')[0]);
timeCloseMin = parseInt(timeClose.split(':')[1]);
closingTimeSiesta = new Date();
closingTimeSiesta.setDate(closingTimeSiesta.getDate() + (weekday - dayOfTheWeek));
closingTimeSiesta.setMinutes(timeCloseMin);
closingTimeSiesta.setHours(timeCloseHour - timezoneAdjustment);
if(currentDateUTC > closingTimeSiesta) {
timeOpen = hours[lid][type].days[weekdayNames[weekday]][i].open;
timeClose = hours[lid][type].days[weekdayNames[weekday]][i].close;
}
}
}
if(timeOpen == '00:00') timeOpen = '24:00';
if(timeClose == '00:00') timeClose = '24:00';
var timeOpenHour = parseInt(timeOpen.split(':')[0]);
var timeOpenMin = parseInt(timeOpen.split(':')[1]);
var timeCloseHour = parseInt(timeClose.split(':')[0]);
var timeCloseMin = parseInt(timeClose.split(':')[1]);
openingTime = new Date();
if(timeOpenHour == '24') {
//We need to subtract one additional day from the time since setting it to 24 adds it to the end of the day
openingTime.setDate(openingTime.getDate() + (weekday - dayOfTheWeek - 1));
} else {
openingTime.setDate(openingTime.getDate() + (weekday - dayOfTheWeek));
}
openingTime.setMinutes(timeOpenMin);
openingTime.setHours(timeOpenHour - timezoneAdjustment);
closingTime = new Date();
closingTime.setDate(closingTime.getDate() + (weekday - dayOfTheWeek));
closingTime.setMinutes(timeCloseMin);
closingTime.setHours(timeCloseHour - timezoneAdjustment);
if(timeOpenHour != 24 && timeOpenHour > timeCloseHour) {
closingTime.setDate(closingTime.getDate() + 1);
}
//Setup Opening Timestamp
openingTimestamp = isNaN(timeOpenHour) || timeOpenHour === '' ? '' : openingTime.getTime();
openingDate = (openingTime.getMonth() + 1) + '/' + openingTime.getDate() + '/' + openingTime.getFullYear() + ' ' + openingTime.getHours() + ':' + openingTime.getMinutes();
//Setup Closing Timestamp
closingTimestamp = isNaN(timeCloseHour) || timeCloseHour === '' ? '' : closingTime.getTime();
closingDate = (closingTime.getMonth() + 1) + '/' + closingTime.getDate() + '/' + closingTime.getFullYear() + ' ' + closingTime.getHours() + ':' + closingTime.getMinutes();
//Setup Opening Time Pretty for French or English style
if(dictionary['HOUR_FORMAT'][urlCountryCode] == 12) {
if(timeOpenHour == 24) {
openingTimePretty = 12;
meridiem = dictionary['AM'][urlCountryCode];
} else if (timeOpenHour > 12) {
openingTimePretty = isNaN(timeOpenHour) ? '' : (timeOpenHour % 12);
openingTimePretty += timeOpenMin > 0 ? ':' + timeOpenMin : '';
meridiem = dictionary['PM'][urlCountryCode];
} else if (timeOpenHour == 12) {
openingTimePretty = timeOpenHour;
openingTimePretty += timeOpenMin > 0 ? ':' + timeOpenMin : '';
meridiem = dictionary['PM'][urlCountryCode];
} else {
openingTimePretty = isNaN(timeOpenHour) ? '' : timeOpenHour;
openingTimePretty += timeOpenMin > 0 ? ':' + timeOpenMin : '';
meridiem = dictionary['AM'][urlCountryCode];
}
openingTimePretty = openingTimePretty == '' ? '' : openingTimePretty + meridiem;
//Setup Closing Time Pretty
if(timeCloseHour == 24) {
closingTimePretty = 12;
meridiem = dictionary['AM'][urlCountryCode];
} else if (timeCloseHour > 12) {
closingTimePretty = isNaN(timeCloseHour) ? '' : (timeCloseHour % 12);
closingTimePretty += timeCloseMin > 0 ? ':' + timeCloseMin : '';
meridiem = dictionary['PM'][urlCountryCode];
} else if (timeCloseHour == 12) {
closingTimePretty = timeCloseHour;
closingTimePretty += timeCloseMin > 0 ? ':' + timeCloseMin : '';
meridiem = dictionary['PM'][urlCountryCode];
} else {
if(timeCloseHour == 0) {
closingTimePretty = '12';
meridiem = dictionary['AM'][urlCountryCode];
} else {
closingTimePretty = isNaN(timeCloseHour) ? '' : timeCloseHour;
closingTimePretty += timeCloseMin > 0 ? ':' + timeCloseMin : '';
meridiem = dictionary['AM'][urlCountryCode];
}
}
closingTimePretty = closingTimePretty == '' ? '' : closingTimePretty + meridiem;
} else {
//Use dictionary AM as a suffix for the hours.
openingTimePretty = dictionary['AM'][urlCountryCode] == '' ? timeOpenHour : timeOpenHour + ' ' + dictionary['AM'][urlCountryCode];
openingTimePretty += timeOpenMin > 0 ? timeOpenMin : '';
closingTimePretty = dictionary['AM'][urlCountryCode] == '' ? timeCloseHour : timeCloseHour + ' ' + dictionary['AM'][urlCountryCode];
closingTimePretty += timeCloseMin > 0 ? timeCloseMin : '';
}
}
// Create hours object and append proper data.
var open24 = '';
var closed = '';
var hasNoHours = '';
if(typeof hours[lid][type].days != 'undefined' && typeof hours[lid][type].days[weekdayNames[weekday]] != 'undefined'
&& hours[lid][type].days[weekdayNames[weekday]] == 'open24') {
open24 = "open24";
}
if(typeof hours[lid][type].days == 'undefined' || typeof hours[lid][type].days[weekdayNames[weekday]] == 'undefined'
|| (typeof hours[lid][type].days[weekdayNames[weekday]] != 'undefined' && hours[lid][type].days[weekdayNames[weekday]].length == 0)) {
closed = "closed";
hasNoHours = 'has-no-hours';
}
var hoursObj = {};
hoursObj.openingTimePretty = openingTimePretty;
hoursObj.closingTimePretty = closingTimePretty;
hoursObj.openingTimestamp = openingTimestamp;
hoursObj.closingTimestamp = closingTimestamp;
hoursObj.openingDate = openingDate;
hoursObj.closingDate = closingDate;
hoursObj.open24 = open24;
hoursObj.closed = closed;
hoursObj.hasNoHours = hasNoHours;
hoursObj.weekday = weekdayNames[weekday];
temp.processedHours.push(hoursObj);
}
if(type != 'timezone' && type != 'dst'){
processedHours.push(temp);
}
}
}
return processedHours;
}
//returns a timezone abbreviation for a given timezone offset
function getTZAbbreviation(offset) {
var timeZones = {'-8': 'PT','-7': 'MT','-6': 'CT','-5': 'ET' };
return timeZones[offset];
}
//return the timezone abbreviation if the user is NOT in the location timezone
function getTimezoneText(hour) {
var showTimezone = '';
var incrementByOne = getDaylightSavings() && hour.observesDLS ? 1 : 0;
var currentTimezone = -((new Date().getTimezoneOffset() / 60) + incrementByOne);
timezoneText = currentTimezone != hour.timezoneOffset ? hour.timezone : ''
if(typeof timezoneText == 'undefined' || timezoneText == null) {
timezoneText = '';
}
return timezoneText;
}
//returns the current UTC time
function getTimeUTC() {
var now = new Date();
var nowUTC = new Date(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds()
);
return nowUTC;
}
//t is the date object to check, returns true if daylight saving time is in effect.
function getDaylightSavings() {
var t = new Date();
var jan = new Date(t.getFullYear(),0,1);
var jul = new Date(t.getFullYear(),6,1);
return Math.min(jan.getTimezoneOffset(),jul.getTimezoneOffset()) == t.getTimezoneOffset();
}
function hasChildHours(tempHours, overrideType, upcomingDaysLimit) {
if(typeof upcomingDaysLimit == 'undefined') {
upcomingDaysLimit = 7;
}
var overrideDayLimit = new Date();
overrideDayLimit.setHours(0,0,0,0);
overrideDayLimit.setDate(currDate.getDate() + upcomingDaysLimit);
if(typeof tempHours['children'] != 'undefined') {
for(sub_hours in tempHours['children']) {
if(typeof tempHours['children'][sub_hours][overrideType] != 'undefined') {
for(key in tempHours['children'][sub_hours][overrideType]) {
//Since there are no hours in key, we need to set hours to 00:00;
overrideDate = getValidDateFormat(key + " 00:00");
overrideWeekday = overrideDate.getDay();
if(overrideDate >= today && overrideDate < overrideDayLimit && typeof tempHours['days'] != 'undefined') {
if(typeof tempHours['days'] != "undefined" && tempHours['days'][weekdayNames[overrideWeekday]]) {
return true;
}
} else if (overrideDate < today && overrideDate >= yesterday) {
//Check if opening time from yesterday is greater than current time. This only happens when closing time falls onto next day
if(tempHours.children[sub_hours][overrideType][key] != "open24" && tempHours.children[sub_hours][overrideType][key] != "closed" && typeof tempHours.children[sub_hours][overrideType][key][0].close != 'undefined') {
var closingTime = tempHours.children[sub_hours][overrideType][key][0].close.split(":");
var openingTime = tempHours.children[sub_hours][overrideType][key][0].close.split(":");
if(openingTime[0] > closingTime[0] && (closingTime[0] > currDate.getHours() || (closingTime[0] == currDate.getHours() && closingTime[1] > currDate.getMinutes()))) {
return true;
}
}
}
}
}
}
}
return false;
}
function getChildHours(tempHours, overrideType, upcomingDaysLimit) {
if(typeof upcomingDaysLimit == 'undefined') {
upcomingDaysLimit = 7;
}
var overrideDayLimit = new Date();
overrideDayLimit.setHours(0,0,0,0);
overrideDayLimit.setDate(currDate.getDate() + upcomingDaysLimit);
for(var subset in tempHours.children) {
if(typeof tempHours.children[subset][overrideType] != 'undefined') {
for(var key in tempHours.children[subset][overrideType]) {
//Since there are no hours in key, we need to set hours to 00:00;
overrideDate = getValidDateFormat(key + " 00:00");
overrideWeekday = overrideDate.getDay();
if(overrideDate >= today && overrideDate < overrideDayLimit && typeof tempHours['days'] != 'undefined') {
if(typeof tempHours['days'] != "undefined" && tempHours['days'][weekdayNames[overrideWeekday]]) {
tempHours['days'][weekdayNames[overrideWeekday]] = tempHours.children[subset][overrideType][key];
tempHours['days'][weekdayNames[overrideWeekday] + '_' + overrideType] = tempHours.children[subset].label;
}
} else if (overrideDate < today && overrideDate >= yesterday) {
//Check if opening time from yesterday is greater than current time. This only happens when closing time falls onto next day
if(tempHours.children[subset][overrideType][key] != "open24" && tempHours.children[subset][overrideType][key] != "closed" && typeof tempHours.children[subset][overrideType][key][0].close != 'undefined') {
var closingTime = tempHours.children[subset][overrideType][key][0].close.split(":");
var openingTime = tempHours.children[subset][overrideType][key][0].close.split(":");
if(openingTime[0] > closingTime[0] && (closingTime[0] > currDate.getHours() || (closingTime[0] == currDate.getHours() && closingTime[1] > currDate.getMinutes()))) {
tempHours['days'][weekdayNames[overrideWeekday]] = tempHours.children[subset][overrideType][key];
tempHours['days'][weekdayNames[overrideWeekday] + '_' + overrideType] = tempHours.children[subset].label;
}
}
}
}
}
}
return tempHours;
}
function getCollapsedDays(tempHours, days) {
previous_day_hours = '';
previous_day = '';
day_text = [];
days_array = [];
counter = 0;
previous_day_value = '';
for(day in days) {
//Get opening hours for current day
if(typeof tempHours['days'][day] == 'undefined' || tempHours['days'][day] == "closed") {
todays_hours = "closed";
} else if(tempHours['days'][day] == "open24") {
todays_hours = "open24";
} else {
todays_hours = tempHours['days'][day][0]["open"] + "-" + tempHours['days'][day][0]["close"];
}
//Get opening hours for previous day
if(counter > 0) {
if(typeof tempHours['days'][previous_day_key] == 'undefined' || tempHours['days'][previous_day_key] == "closed") {
previous_day_hours = "closed";
} else if(tempHours['days'][previous_day_key] == "open24") {
previous_day_hours = "open24";
} else {
previous_day_hours =tempHours['days'][previous_day_key][0]["open"] + "-" + tempHours['days'][previous_day_key][0]["close"];
}
previous_day = previous_day_value;
day_text.push(previous_day); //push the previous day to array of same day times
if(todays_hours == previous_day_hours && counter == (Object.keys(days).length) - 1) {
days_array[previous_day_key] = day_text[0] + "-" + days[day];
} else if(todays_hours != previous_day_hours) {
if(day_text.length == 1) {
days_array[previous_day_key] = day_text[0];
day_text = [];
} else {
days_array[previous_day_key] = day_text[0] + "-" + day_text[day_text.length - 1];
day_text = [];
}
if(counter == (Object.keys(days).length) - 1) {
days_array[day] = days[day];
day_text = [];
}
}
}
counter++;
previous_day_value = days[day];
previous_day_key = day;
}
return days_array;
}
function validDateFormat(dateRange) {
if (dateRange !== "") {
var currentDate = new Date();
var dates = dateRange.split("-");
if (dates.length === 2) {
var dateStart = new Date(dates[0]);
var dateEnd = new Date(dates[1]);
if (dateStart.getFullYear() < 1970) {
dateStart.setFullYear(dateStart.getFullYear() + 100);
}
if (dateEnd.getFullYear() < 1970) {
dateEnd.setFullYear(dateEnd.getFullYear() + 100);
}
return (!isNaN(dateStart.getTime()) && !isNaN(dateEnd.getTime()) && currentDate >= dateStart && currentDate < dateEnd);
} else {
var dateStart = new Date(dates[0].trim());
if (!isNaN(dateStart.getTime())) {
var dateEnd = new Date(dates[0].trim());;
dateEnd.setDate(dateEnd.getDate() + 1);
dateEnd.setHours(0);
dateEnd.setMinutes(0);
return (currentDate >= dateStart && currentDate < dateEnd);
}
}
}
return false;
}
function getValidDateFormat(date) {
//We have to replace all '-' with '/' and make sure we do not include any .000000 miliseconds.
var tempDate = date.replace(/-/g,'/').replace('.000000', '');
var newDate = new Date(tempDate);
newDate.setHours(0,0,0,0);
return newDate;
}