Created
June 10, 2014 15:54
-
-
Save sclarson/1b8523540c1bffaa517f to your computer and use it in GitHub Desktop.
Sometimes JS is beautiful, sometimes it is this.
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
function determineDateInYesMoveAndUpperCaseFirstWord(yesMove) { | |
var retVal = yesMove; | |
if (yesMove.charAt(0) != null | |
&& !isNaN(parseInt(yesMove.charAt(0),10))) { | |
var parsedTime; | |
if (yesMove.indexOf('/') > 0) { | |
if (yesMove.split('/').length < 3) { // split is one higher than the count of things split on | |
parsedTime = new moment(yesMove, 'MM/DD'); | |
} else { | |
if (yesMove.split('/')[2].trim().length < 3) { // if the format has only two days on the year | |
parsedTime = new moment(yesMove, 'MM/DD/YY'); | |
} else { | |
parsedTime = new moment(yesMove, 'MM/DD/YYYY'); | |
} | |
} | |
} else { | |
if (yesMove.indexOf('-') > 0) { | |
if (yesMove.split('-').length < 3) { | |
parsedTime = new moment(yesMove, 'MM-DD'); | |
} else { | |
if (yesMove.split('-')[2].trim().length < 3) { // if the format has only two days on the year | |
parsedTime = new moment(yesMove, 'MM-DD-YY'); | |
} else { | |
parsedTime = new moment(yesMove, 'MM-DD-YYYY'); | |
} | |
} | |
} | |
} | |
retVal = parsedTime.format('MM/DD/YYYY'); | |
} else { | |
var spaceSplit = retVal.split(' ').length; | |
if (spaceSplit.length > 1) { | |
spaceSplit[0] = spaceSplit[0].toUpperCase(); | |
retVal = spaceSplit.join(' '); | |
} else { | |
retVal = retVal.toUpperCase(); | |
} | |
} | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment