update date logic to account for timezones (#3840)
parent
051e897a2b
commit
a5511e3c22
|
@ -118,16 +118,15 @@ export function MessageItemMetadata({
|
|||
}
|
||||
|
||||
// if in the last day
|
||||
if (now.toISOString().slice(0, 10) === date.toISOString().slice(0, 10)) {
|
||||
if (localDateString(now) === localDateString(date)) {
|
||||
return time
|
||||
}
|
||||
|
||||
// if yesterday
|
||||
const yesterday = new Date(now)
|
||||
yesterday.setDate(yesterday.getDate() - 1)
|
||||
if (
|
||||
yesterday.toISOString().slice(0, 10) === date.toISOString().slice(0, 10)
|
||||
) {
|
||||
|
||||
if (localDateString(yesterday) === localDateString(date)) {
|
||||
return _(msg`Yesterday, ${time}`)
|
||||
}
|
||||
|
||||
|
@ -164,3 +163,12 @@ export function MessageItemMetadata({
|
|||
</TimeElapsed>
|
||||
)
|
||||
}
|
||||
|
||||
function localDateString(date: Date) {
|
||||
// can't use toISOString because it should be in local time
|
||||
const mm = date.getMonth()
|
||||
const dd = date.getDate()
|
||||
const yyyy = date.getFullYear()
|
||||
// not padding with 0s because it's not necessary, it's just used for comparison
|
||||
return `${yyyy}-${mm}-${dd}`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue