Skip to content

Instantly share code, notes, and snippets.

@mickelsonm
Created December 18, 2015 16:02
Show Gist options
  • Save mickelsonm/adc7a8949df56c1e6d11 to your computer and use it in GitHub Desktop.
Save mickelsonm/adc7a8949df56c1e6d11 to your computer and use it in GitHub Desktop.
var expiration = '0000-00-00 00:00:00';
if (body.expiration !== undefined) {
var arr = body.expiration;
//check to make sure it is an array
if (!Array.isArray(arr)) {
def.reject('expiration property is not a valid array');
return def.promise;
}
//check to make sure it is of the right length [d,h,m,s]
if (arr.length !== 4) {
def.reject('expiration array must have a length of 4');
return def.promise;
}
//validate each parameter
for (var i = 0; i < arr.length; i++) {
if (typeof arr[i] !== 'number' ||
typeof arr[i] === 'number' && arr[i] % 1 !== 0) {
def.reject('illegal index in expiration array');
return def.promise;
}
}
//construct the datetime string we use in query
var now = moment();
if (arr[0] > 0) now.add(arr[0], 'days');
if (arr[1] > 0) now.add(arr[1], 'hours');
if (arr[2] > 0) now.add(arr[2], 'minutes');
if (arr[3] > 0) now.add(arr[3], 'seconds');
expiration = now.format('YYYY-MM-DD HH:mm:ss');
}
@ryanwebjackson
Copy link

Where does the local 'expiration' go after you assign to it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment