Last active
April 29, 2018 17:02
-
-
Save andreasvirkus/2fbe1d2977fc8115838bc6eaf2e49204 to your computer and use it in GitHub Desktop.
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
/* | |
A date formatter filter for SSGs/templating languages | |
*/ | |
module.exports = (date) => { | |
const month = [ | |
"January", | |
"February", | |
"March", | |
"April", | |
"May", | |
"June", | |
"July", | |
"August", | |
"September", | |
"October", | |
"November", | |
"December" | |
] | |
const ordinal = { | |
1 : "st", | |
2 : "nd", | |
3 : "rd", | |
21 : "st", | |
22 : "nd", | |
23 : "rd", | |
31 : "st" | |
} | |
const d = new Date(date) | |
return `${month[d.getMonth()]} ${d.getDate()}${ordinal[d.getDate()] || "th"} ${d.getUTCFullYear()}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment