Good day. Facebook has a nice feature. It allows you to track the time of the store relative to the time of the user. And accordingly write "Open now" or "open on Monday at 8-00."
How to implement this? Is there something similar?
Good day. Facebook has a nice feature. It allows you to track the time of the store relative to the time of the user. And accordingly write "Open now" or "open on Monday at 8-00."
How to implement this? Is there something similar?
I came up with such a solution. Days and time (hours and minutes) stored in json.
var utc_vendor = '+3'; var utc_user = '-1'; wt = { "days": { "2": {"1":"1","2":"2","4":"4","6":"6"}, "3": {"1":"1","3":"3","7":"7"} }, "time_from_h": { "2": {"1":"8","2":"9","4":"8","6":"10"}, "3": {"1":"8","3":"9","7":"8"} }, "time_from_m": { "2": {"1":"00","2":"05","4":"30","6":"50"}, "3": {"1":"10","3":"00","7":"10"} }, "time_to_h": { "2": {"1":"21","2":"20","4":"22","6":"18"}, "3": {"1":"19","3":"17","7":"19"} }, "time_to_m": { "2": {"1":"30","2":"40","4":"40","6":"52"}, "3": {"1":"59","3":"10","7":"40"} } }; var d = new Date(); var hours = d.getHours(); var minutes = d.getMinutes(); var w_day = [7, 1, 2, 3, 4, 5, 6][new Date(d).getDay()]; var wd_name = {"7": "воскресение", "1": "понедельник", "2": "вторник", "3": "среду", "4": "четверг", "5": "пятницу", "6": "субботу"}; function get_vendor_time_status(id) { var hv = 0; if(wt.days[id]) { if(wt.days[id][w_day] && ((wt.time_from_h[id][w_day] < hours && hours < wt.time_to_h[id][w_day]) || ((wt.time_from_h[id][w_day] == hours && wt.time_from_m[id][w_day] <= minutes) || (hours == wt.time_to_h[id][w_day] && minutes <= wt.time_to_m[id][w_day])))) { alert('Сейчас работает'); } else { if(w_day == 7) w_nd = 1; else w_nd = w_day + 1; for(i = 1; i < 8; i++) { if (wt.days[id][w_nd]) { if(w_nd == 2) { alert( 'Откроется во ' + wd_name[w_nd] + ' в ' + wt.time_from_h[id][w_nd] + ':' + wt.time_from_m[id][w_nd] + '.' ); } else { alert( 'Откроется в ' + wd_name[w_nd] + ' в ' + wt.time_from_h[id][w_nd] + ':' + wt.time_from_m[id][w_nd] + '.' ); } break; } if(w_nd == 7) w_nd = 1; else w_nd = w_nd + 1; } } } } get_vendor_time_status(2); Source: https://ru.stackoverflow.com/questions/581350/
All Articles
Dateobject to help) and put an inscription on the results. - user207618