Created
July 11, 2016 20:41
-
-
Save miclaus/bbb3e32e83725b45d69fbe469d6e97d2 to your computer and use it in GitHub Desktop.
FB birthday split helper in ES6
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
| const bsplit = (birthday) => { | |
| if ( typeof birthday === 'string' ) { | |
| const data = birthday.split('/') | |
| let birthdayObj = { day: null, month: null, year: null } | |
| switch (data.length) { | |
| case 1: | |
| birthdayObj.year = Number( data[0] ) | |
| break | |
| case 2: | |
| birthdayObj.day = Number( data[1] ) | |
| birthdayObj.month = Number( data[0] ) | |
| break | |
| case 3: | |
| default: | |
| birthdayObj.day = Number( data[1] ) | |
| birthdayObj.month = Number( data[0] ) | |
| birthdayObj.year = Number( data[2] ) | |
| break | |
| } | |
| return birthdayObj | |
| } | |
| return birthday | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment