Last active
March 30, 2020 12:15
-
-
Save manakuro/d9a32fd6505bc691c25786b7ab2c24bf 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
export const formatDate = (date) => { | |
let result | |
if (date) { | |
const dateObj = new Date(date) | |
if (isToday(dateObj)) { | |
result = 'Today' | |
} else if (isYesterday(dateObj)) { | |
result = 'Yesterday' | |
} else if (!isThisYear(dateObj)) { | |
result = format(dateObj, 'MMMM d, yyyy') | |
} else { | |
result = format(dateObj, 'MMMM d') | |
} | |
} else { | |
throw new Error('No date') | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment