Created
June 11, 2016 11:42
-
-
Save mrahul17/3a05e0a95246b86585fec580004c5ff8 to your computer and use it in GitHub Desktop.
parsing date
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
date_options = { | |
"today" : 0, | |
"yesterday" : 24*60*60*1000 , | |
"day" : 24*60*60*1000, | |
"week" : 7*24*60*60*1000, | |
"weeks" :7*24*60*60*1000 | |
} | |
if (expenseObject.date) { | |
var dateRe = /(\d{4})-(\d{2})-(\d{2})/; | |
var matchObject = expenseObject.date.match(dateRe); | |
if (!matchObject) { | |
var datesplit = expenseObject.date.split(" ") | |
if (isNaN(parseInt(datesplit[0]))) { | |
if(date_options.slice(0,2).indexOf(datesplit[0])==-1) { | |
throw new Error(Consts.MSG_INVALID_DATE); | |
} else { | |
expenseObject.date = require('date-format').asString('yyyy-MM-dd', new Date().setTime((new Date()).getTime()-datesplit[0])); | |
} | |
} else { | |
if(date_options.slice(2).indexOf(datesplit[1])==-1) { | |
throw new Error(Consts.MSG_INVALID_DATE); | |
} else { | |
expenseObject.date = require('date-format').asString('yyyy-MM-dd', new Date().setTime((new Date()).getTime()-datesplit[1])); | |
} | |
} | |
} | |
} else { | |
expenseObject.date = require('date-format').asString('yyyy-MM-dd', new Date()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment