Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created October 10, 2022 15:57
Show Gist options
  • Save IrhaAli/71bf1ff766ebf0ba6dfcdf36f8be1566 to your computer and use it in GitHub Desktop.
Save IrhaAli/71bf1ff766ebf0ba6dfcdf36f8be1566 to your computer and use it in GitHub Desktop.
Given a date in dd/mm/year format returns the date in month day, year format
const talkingCalendar = function(date) {
//assign the year
let year = date.substring(0,4);
let month;
let day;
//determine the month
switch (date.substring(5,7)){
case '01':
month = 'January';
break;
case '02':
month = 'February';
break;
case '03':
month = 'March';
break;
case '04':
month = 'April';
break;
case '05':
month = 'May';
break;
case '06':
month = 'June';
break;
case '07':
month = 'July';
break;
case '08':
month = 'August';
break;
case '09':
month = 'September';
break;
case '10':
month = 'October';
break;
case '11':
month = 'November';
break;
case '12':
month = 'December';
}
//determine the day
switch (date.substring(9,10)){
case '1':
day = `${date.substring(8,10)}st`;
break;
case '2':
day = `${date.substring(8,10)}nd`;
break;
case '3':
day = `${date.substring(8,10)}rd`;
break;
default:
day = `${date.substring(8,10)}th`;
}
//remove 0 if day is between 1 to 9
if (day[0] === '0'){
day = day.substring(1);
}
return `${month} ${day}, ${year}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment