Last active
June 28, 2019 14:54
-
-
Save ashour/c58413ea1b266f03dde9ce8dd76dcbc8 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
| /** | |
| * 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