Check If Current Time Falls Within A Specific Date Range Now Open - Download Check If Current Time Falls Within A Specific Date Range - Now Open

Download Check If Current Time Falls Within A Specific Date Range – Now Open

Posted on

This time I will share jQuery Plugin and tutorial about Check If Current Time Falls Within A Specific Date Range – Now Open, hope it will help you in programming stack.

Check If Current Time Falls Within A Specific Date Range Now Open - Download Check If Current Time Falls Within A Specific Date Range - Now Open

File Size: 15 KB
Views Total: 1242
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Now Open is a small jQuery plugin that makes it possible to check if current time falls in a time range you specify. Supports week days and exclude days/times. Typical use cases for this plugin include live chat, customer service and more.

Basic usage:

1. Insert jQuery library and the jQuery Now Open plugin’s script into the html file:

1 <script src="//code.jquery.com/jquery.min.js"></script>
2 <script src="js/now_open.js"></script>

2. Set the datetime range and exclude days/times as these:

01 var myWeek = [
02     {'1':[8.5,20]},
03     {'2':[8.5,20]},
04     {'3':[8.5,20]},
05     {'4':[8.5,20]},
06     {'5':[8.5,20]},
07     {'6':[10,20]}
08   ];
09   
10 var myExcludes = [
11     [1,1],
12     [1,6]
13 ];

3. Initialize the plugin by calling the function on the desired element.

1 $('#element').now_open({
2   week: myWeek,
3   excludes: myExcludes
4 });

4. Do something if the current time is in the datetime range.

01 $('#element').now_open({
02   week: myWeek,
03   excludes: myExcludes,
04   callback: myCallback,
05 });
06 function myCallback(element, isOpen){
07   if(isOpen){
08     element.html('<i class="fa fa-phone-square"></i> We are open... call us!');
09   } else {
10     element.html('<i class="fa fa-phone-square"></i> Live Chat Offline');
11   }
12 }

5. Set the latency time in minutes to keep checking the current time.

1 $('#element').now_open({
2   week: myWeek,
3   excludes: myExcludes,
4   callback: myCallback,
5   latency: 1
6 });

6. You can also specify the current time instead of the local time.

1 $('#element').now_open({
2   week: myWeek,
3   excludes: myExcludes,
4   callback: myCallback,
5   latency: 1,
6   currentDate: "June 9, 2017 11:00:00"
7 });

This awesome jQuery plugin is developed by alotropico. For more Advanced Usages, please check the demo page or visit the official website.

source : jqueryscript.net