Created
December 18, 2015 16:02
-
-
Save mickelsonm/adc7a8949df56c1e6d11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where does the local 'expiration' go after you assign to it?