Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active June 28, 2019 14:54
Show Gist options
  • Save ashour/c58413ea1b266f03dde9ce8dd76dcbc8 to your computer and use it in GitHub Desktop.
Save ashour/c58413ea1b266f03dde9ce8dd76dcbc8 to your computer and use it in GitHub Desktop.
/**
* Past this number of hours we'll no longer display "hours
* ago" and instead we'll display "today"
*/
const TODAY_AT_THRESHOLD_IN_HOURS: number = 12;
function humanFriendlyDate(date: Date): string {
// ...
if (days === 1) {
return __("yesterday");
}
if (hours > TODAY_AT_THRESHOLD_IN_HOURS) {
return __("today at") + " " +
date.toLocaleTimeString(currentLocale,
{ hour: "numeric", minute: "2-digit" });
}
if (hours > 0) {
return _p("hours ago", hours);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment