Skip to content

Commit

Permalink
GOTH-610 Always display timestamps in ET (#299)
Browse files Browse the repository at this point in the history
* display timestamps in ET
* dont show ET on date only timestamps
  • Loading branch information
walsh9 authored Aug 2, 2023
1 parent 616388f commit bbb4329
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@vue/test-utils": "^2.0.0-rc.21",
"@vueuse/core": "^9.1.0",
"date-fns": "^2.28.0",
"date-fns-tz": "^2.0.0",
"gsap": "^3.10.4",
"howler": "^2.2.3",
"humps": "^2.0.1",
Expand Down
13 changes: 8 additions & 5 deletions utilities/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { format, differenceInMinutes, differenceInHours, getYear, isValid } from 'date-fns'
import { differenceInMinutes, differenceInHours, getYear, isValid } from 'date-fns'
import { formatInTimeZone } from 'date-fns-tz'

const TIMEZONE = 'America/New_York'

export const fuzzyDateTime = function (time: Date): string {
const JUST_NOW = 'Just now'
Expand All @@ -17,9 +20,9 @@ export const fuzzyDateTime = function (time: Date): string {
} else if (hours < 24) {
return `${hours} hour${hours > 1 ? 's' : ''} ago`
} else if (getYear(time) === getYear(now)) {
return format(time, TIMESTAMP_FORMAT_NO_YEAR)
return `${formatInTimeZone(time, TIMEZONE, TIMESTAMP_FORMAT_NO_YEAR)} ET`
}
return format(time, TIMESTAMP_FORMAT)
return `${formatInTimeZone(time, TIMEZONE, TIMESTAMP_FORMAT)} ET`

}

Expand All @@ -28,8 +31,8 @@ export const formatDateForByline = function (date) {
if (date) {
const dateObject = new Date(date)
const now = new Date()
const shortDate = format(dateObject, 'MMM d, y')
const longDate = format(dateObject, "MMM d, y 'at' h:mm aaaa")
const shortDate = formatInTimeZone(dateObject, TIMEZONE, 'MMM d, y')
const longDate = `${formatInTimeZone(dateObject, TIMEZONE, "MMM d, y 'at' h:mm aaaa")} ET`
return differenceInHours(now, dateObject) <= 12 ? longDate : shortDate
}
return null
Expand Down

0 comments on commit bbb4329

Please sign in to comment.