1(function ($) { 2//version 3. 2017-08-13 3function timeit() { 4 console.log("in timeit"); 5 var next_run_array = []; //array of dates/time on a page used to rerun function if a change should happen during the session 6 var curDate = new Date(); 7 Date.prototype.yyyymmdd = function() { 8 var mm = this.getMonth() + 1; 9 var dd = this.getDate(); 10 return [this.getFullYear(), 11 (mm > 9 ? '' : '0') + mm, 12 (dd > 9 ? '' : '0') + dd 13 ].join('-'); 14 }; 15 var curDateYMD = curDate.yyyymmdd(); 16 17 $('.timeit').each(function() { 18 var end = $(this).data('end'), 19 start = $(this).data('start'); 20 // var end = $(this).attr('data-end'), 21 // start = $(this).attr('data-start'); 22 23 //check if date or time value has valid format and push it to the list of refresh anchors 24 var startDate = checkdate(start, this); 25 var endDate = checkdate(end, this); 26 nextrun(startDate); 27 nextrun(endDate); 28 29 //add a datetime when the page needs to be refreshed (now+24 hrs time span only) 30 function nextrun(date) { 31 var nextruntimeout = date - curDate; 32 if (nextruntimeout < 1000 * 60 * 60 * 24 && nextruntimeout > 1000) { 33 next_run_array.push(nextruntimeout); 34 } 35 } 36 37 // Main Function 38 //check if the evend outside of a desired time span 39 if (((startDate < endDate) && (startDate > curDate || endDate < curDate)) || 40 ((startDate > endDate) && (startDate >= curDate) && (endDate <= curDate)) 41 ) { 42 43 $(this).addClass('d-none'); // Changed from hidden for bootstrap 4/5 compatibility issues 44 } else { 45 $(this).removeClass('d-none'); // Changed from hidden bootstrap 4/5 compatibility issues 46 } 47 48 //Support Functions 49 //correct data creation from a string. accepted format YYYY-MM-DD HH:MM 50 function parseISO8601(d) { 51 var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)?.(\d\d)?.(\d\d)\s*$/, 52 date = new Date(NaN), 53 datenew, 54 month, 55 dateString=d.substr(0, d.indexOf(' ')); 56 parts = isoExp.exec(d); 57 58 if(parts) { 59 month = +parts[2]; 60 date.setFullYear(parts[1], month - 1, parts[3]); 61 if(month != date.getMonth() + 1) { 62 date.setTime(NaN); 63 } 64 date = new Date(parts[1], month - 1, parts[3], parts[4], parts[5]) 65 } 66 return date; 67 } 68 69 //unification of the date string to the format YYYY-MM-DD HH:MM 70 function checkdate(date, obj) { 71 if (date) { 72 //check if only time is set (HH:MM); if so, add today's date 73 if (String(date).length < 6 && String(date).indexOf(":") > -1) { 74 date = curDateYMD + ' ' + String(date); 75 } 76 //check if only date is set; if so add 00:00 to the end of date 77 if (String(date).indexOf(":") == -1) { 78 date = date + ' 00:00'; 79 } 80 //check if date is valid (avoid valid time) 81 var res = date.split(":"), 82 h = String(res.slice(0, 1)), 83 hours = h.substr(h.length - 2), 84 minutes = res.slice(1); 85 var timetest = (hours < 24 && minutes < 60) ? true : false; 86 87 //check if date is could be created from a value; if fails try to parse a string to a format 88 var returndate = new Date(date); 89 if (returndate == 'Invalid Date') { 90 var returndate = parseISO8601(date); 91 }; 92 93 94 if (returndate == 'Invalid Date' || !timetest) { 95 //highlight the element if the is an error. use own \.error class if needed 96 $(obj).addClass("error").attr('title', '"' + date + '" date is incorrect; please use YYYY-MM-DD HH:MM format'); 97 } 98 return returndate.getTime(); 99 } else { 100 //if datetime is not set, just return current date-time 101 return curDate.getTime(); 102 } 103 } 104 }); 105 106 /* Schedule next runs */ 107 if (next_run_array.length > 0) { 108 var nextruntime = Math.min.apply(null, next_run_array); 109 console.log("next run of timeit function is in " + nextruntime / 1000 + "seconds"); 110 setTimeout(function() { 111 timeit(); 112 }, nextruntime); 113 } 114} 115timeit(); 116//******CLOSE WRAP FOR CUSTOM JS WITH THE FOLLOWING FOR DRUPAL 8 ************** 117}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.