how can insert tomorrow's day
's starttime
, endtime
content message setuporderingnotavailable
function if today's day
has endtime
has expired? right message setuporderingnotavailable
says "...again tomorrow 11:00am 9:00pm" not true every day; insert tomorrow's times.
code
var days = { '1': {starttime: '4:00 pm', endtime: '8:00 pm'}, '2': {starttime: '11:00 am', endtime: '9:00 pm'}, '3': {starttime: '11:00 am', endtime: '9:00 pm'}, '4': {starttime: '11:00 am', endtime: '4:00 pm'}, '5': {starttime: '11:00 am', endtime: '10:00 pm'}, '6': {starttime: '12:00 pm', endtime: '10:00 pm'}, '7': {starttime: '12:00 pm', endtime: '8:00 pm'}, }; var curr_day = new date().getday(); var curr_time = getval(); var orderisavailable = false; var day = days[curr_day]; // function setuporderingavailable() { document.queryselector('#alert-success').onclick = function() { $.sweetmodal({ content: '<h2>online ordering available!</h2>' + 'please click button below begin online order.' + '<div class="sweet-modal-buttons"><a href="http://pizzospizzeria.hungerrush.com" target="_blank" class="button greenb">start order</a></div>', // icon: $.sweetmodal.icon_success }); }; } // need make function inserts tomorrows starttime , endtime message if todays endtime has passed function setuporderingnotavailable() { document.queryselector('#alert-success').onclick = function() { $.sweetmodal({ content: '<h2>online ordering not available</h2>' + 'online ordering available again tomorrow 11:00am 9:00pm', buttons: [{ label: 'close', classes: 'redb' }] }); }; } if (day) { if (get24hr(curr_time) > get24hr(day.starttime) && get24hr(curr_time) < get24hr(day.endtime)) { orderingisavailable = true; } else { document.queryselector('#alert-success').onclick = function() { $.sweetmodal({ content: '<h2>online ordering not available</h2>' + 'online ordering available again tomorrow 11:00am 9:00pm', buttons: [{ label: 'close', classes: 'redb' }] }); } } } if (orderingisavailable) { setuporderingavailable(); } else { setuporderingnotavailable(); }
i cleaned time comparison code little determining time in ms start , end time. allows cleaner (imo) comparison of time right now number vs start , end times. day integer returned date object ranges 0-6, updated too.
from there comparison , if ordering can't happen now
here's fiddle, albeit sweetmodal aspect stripped out, string created same no matter how display it.
https://jsfiddle.net/wx97g6x1/2/
var days = { 0: { starttime: '4:00 pm', endtime: '8:00 pm' }, 1: { starttime: '11:00 am', endtime: '9:00 pm' }, 2: { starttime: '11:00 am', endtime: '9:00 pm' }, 3: { starttime: '11:00 am', endtime: '4:00 pm' }, 4: { starttime: '11:00 am', endtime: '10:00 pm' }, 5: { starttime: '12:00 pm', endtime: '10:00 pm' }, 6: { starttime: '12:00 pm', endtime: '8:00 pm' } }; var = new date(); var time = now.gettime(); var day = days[now.getday()]; var starttoday = date.parse(now.todatestring() + ' ' + day.starttime); var endtoday = date.parse(now.todatestring() + ' ' + day.endtime); function setuporderingavailable() { console.log('online ordering available!'); } function setuporderingnotavailable() { var tomorrow = days[now.getday() + 1]; console.log('online ordering available again tomorrow '+ tomorrow.starttime +' '+ tomorrow.endtime) } if (time > starttoday && time < endtoday) { setuporderingavailable(); } else { setuporderingnotavailable(); }
Comments
Post a Comment