From ec06314c98ad1bbf9f1c29a0df8e74920436639b Mon Sep 17 00:00:00 2001 From: Bram van der Veen <96aa48@gmail.com> Date: Thu, 13 Aug 2015 22:00:36 +0200 Subject: [PATCH] Added a function to check if it's schooltime --- time.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 } +