Skip to content

Instantly share code, notes, and snippets.

@miclaus
Created July 11, 2016 20:41
Show Gist options
  • Select an option

  • Save miclaus/bbb3e32e83725b45d69fbe469d6e97d2 to your computer and use it in GitHub Desktop.

Select an option

Save miclaus/bbb3e32e83725b45d69fbe469d6e97d2 to your computer and use it in GitHub Desktop.
FB birthday split helper in ES6
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