Created
May 24, 2019 11:53
-
-
Save GergKllai1/f584b9cb2a281e0cb485d4880f3f98c6 to your computer and use it in GitHub Desktop.
This file contains 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 dateParseHelper = sessions => { | |
let options = { | |
day: "numeric", | |
month: "short", | |
year: "numeric", | |
hour: "2-digit", | |
minute: "2-digit", | |
hourCycle: "h24" | |
}; | |
const convertedSessions = sessions.map(session => { | |
let startDate = new Date(session.startDate); | |
let endDate = new Date(session.endDate); | |
[ | |
session.startDate, | |
session.startYear, | |
session.startTime | |
] = startDate.toLocaleDateString("EN", options).split(", "); | |
[ | |
session.endDate, | |
session.startYear, | |
session.endTime | |
] = endDate.toLocaleDateString("EN", options).split(", "); | |
session.startDate = convertDateFormat(session.startDate) | |
session.endDate = convertDateFormat(session.endDate) | |
return session; | |
}); | |
return convertedSessions; | |
}; | |
const convertDateFormat = date => { | |
const [month, day] = date.split(" "); | |
switch (day) { | |
case "1": | |
case "21": | |
case "31": | |
return `${day}st ${month}`; | |
case "2": | |
case "22": | |
return `${day}nd ${month}`; | |
case "3": | |
return `${day}rd ${month}`; | |
default: | |
return `${day}th ${month}`; | |
} | |
}; | |
export default dateParseHelper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment