Created
May 9, 2018 21:39
-
-
Save lmccart/669278f9f495b35a1630de31b8471dbc to your computer and use it in GitHub Desktop.
timetest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// library to use: https://momentjs.com/docs/#/query/ | |
var data = [{ts: "5/8/blah" , secret:"i washed jeans", value:"immediately"}, {}]; | |
function getAllReady(arr) { | |
var newArr = []; | |
for (var i=0; i<data.length; i++) { | |
var now = new Date().getTime(); | |
var ts = data[i].ts; | |
// preparing the test time | |
var ready_time; | |
if (data[i].value === 'immediately') { | |
ready_time = ts; | |
} | |
else if (data[i].value === '10 minutes') { | |
ready_time = moment(ts).add(10, 'minutes'); | |
} | |
// checking if the test time has passed | |
if (ready_time.isBefore(now)) { | |
newArr.push(data[i]); | |
} | |
} | |
return newArr; | |
} | |
var okData = getAllReady(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment