diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-05-03 15:55:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 15:55:24 +0100 |
commit | a5511e3c22f357afac8ecd57fb12cc08e918df98 (patch) | |
tree | 73ac935b7a05a981172a0741d496d95d43512f49 /src/components | |
parent | 051e897a2b9a2dc60efe7b032b5496cdbcfd6374 (diff) | |
download | voidsky-a5511e3c22f357afac8ecd57fb12cc08e918df98.tar.zst |
update date logic to account for timezones (#3840)
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/dms/MessageItem.tsx | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/components/dms/MessageItem.tsx b/src/components/dms/MessageItem.tsx index 3a1d8eab7..a449c6ed1 100644 --- a/src/components/dms/MessageItem.tsx +++ b/src/components/dms/MessageItem.tsx @@ -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}` +} |