Added a function to check if it's schooltime
This commit is contained in:
parent
6a082e4156
commit
ec06314c98
25
time.js
25
time.js
|
@ -1,4 +1,5 @@
|
|||
//time.js
|
||||
var config = require('./configuration');
|
||||
|
||||
//Function for getting the time, with minutes as a fracture.
|
||||
function get() {
|
||||
|
@ -6,12 +7,34 @@ function get() {
|
|||
return time.getHours() + (time.getMinutes() / 60);
|
||||
}
|
||||
|
||||
//Function for convert hh:mm to fractured time
|
||||
function parse(timestr) {
|
||||
var parsed = timestr.match(/\d{1,2}:\d+/g);
|
||||
var array = [];
|
||||
|
||||
for (time of parsed) {
|
||||
array.push(parseInt(time.split(':')[0]) + (parseInt(time.split(':')[1]) / 60));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
//Function for parsing and checking if the currrent time is within the parsed string.
|
||||
function within_timespan(timespan) {
|
||||
|
||||
}
|
||||
|
||||
function during_school() {
|
||||
var start = parse(config().hour_times[0])[0];
|
||||
var end = parse(config().hour_times[config().hour_times.length - 1])[1];
|
||||
|
||||
if (get() > start && get() < end) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
'get': get,
|
||||
'within_timespan': within_timespan
|
||||
'within_timespan': within_timespan,
|
||||
'during_school': during_school
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue