Created
August 23, 2021 13:49
-
-
Save snewcomer/cdcf65cac697a87194ab09071af97318 to your computer and use it in GitHub Desktop.
Last Modified Date
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
function lastModifiedDate(updatedDate, intl) { | |
const today = new Date(); | |
const yesterday = subDays(today, 1); | |
const aWeekAgo = subDays(today, 7); | |
const twoWeeksAgo = subDays(today, 14); | |
const threeWeeksAgo = subDays(today, 21); | |
const locNamespace = 'Last Updated'; | |
// Get the date in English locale to match English day of week keys | |
const compare = parseISO(updatedDate); | |
let result = ''; | |
if (isSameDay(compare, today)) { | |
result = intl.t(`${locNamespace}Today`); | |
} else if (isSameDay(compare, yesterday)) { | |
result = intl.t(`${locNamespace}Yesterday`); | |
} else if (isAfter(compare, aWeekAgo)) { | |
result = intl.t(`${locNamespace}${formatDate(compare, 'EEEE')}`); | |
} else if (isAfter(compare, twoWeeksAgo)) { | |
result = intl.t(`${locNamespace}LastWeek`); | |
} else if (isAfter(compare, threeWeeksAgo)) { | |
result = intl.t(`${locNamespace}TwoWeeksAgo`); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment