diff --git a/time.js b/time.js index 43f232d..a27df6d 100644 --- a/time.js +++ b/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 } +