Created
June 30, 2019 14:16
-
-
Save danfascia/676f203d23045892f0c3938d7893d324 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
// Stolen from https://stackoverflow.com/a/31615643 | |
const appendSuffix = n => { | |
var s = ['th', 'st', 'nd', 'rd'], | |
v = n % 100; | |
return n + (s[(v - 20) % 10] || s[v] || s[0]); | |
}; | |
module.exports = function dateFilter(value) { | |
const dateObject = new Date(value); | |
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
const dayWithSuffix = appendSuffix(dateObject.getDate()); | |
return `${dayWithSuffix} ${months[dateObject.getMonth()]} ${dateObject.getFullYear()}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment