Skip to content

Instantly share code, notes, and snippets.

@lmccart
Created May 9, 2018 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmccart/669278f9f495b35a1630de31b8471dbc to your computer and use it in GitHub Desktop.
Save lmccart/669278f9f495b35a1630de31b8471dbc to your computer and use it in GitHub Desktop.
timetest.js
// 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