diff options
author | Christopher Ng <chrng8@gmail.com> | 2024-02-14 17:05:38 -0800 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2024-03-08 03:46:55 -0800 |
commit | 8f7829ea90ab8b716466369e6cf7d2f4a8e330d1 (patch) | |
tree | 6d5ac7ba667914cf29655608bcaebc09a15e5e1d /apps | |
parent | c9139c64ffde394a00ae5aed6bc95949b4f8a076 (diff) | |
download | nextcloud-server-8f7829ea90ab8b716466369e6cf7d2f4a8e330d1.tar.gz nextcloud-server-8f7829ea90ab8b716466369e6cf7d2f4a8e330d1.zip |
fix(files_reminders): Add year to date string if not in the same year
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_reminders/src/shared/utils.ts | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/apps/files_reminders/src/shared/utils.ts b/apps/files_reminders/src/shared/utils.ts index 86182ba5106..07142888e51 100644 --- a/apps/files_reminders/src/shared/utils.ts +++ b/apps/files_reminders/src/shared/utils.ts @@ -120,6 +120,13 @@ export const getDateString = (dueDate: Date): string => { } } + if (!dueDateMoment.isSame(today, 'year')) { + formatOptions = { + ...formatOptions, + year: 'numeric', + } + } + return dueDate.toLocaleString( getCanonicalLocale(), formatOptions, @@ -127,12 +134,22 @@ export const getDateString = (dueDate: Date): string => { } export const getVerboseDateString = (dueDate: Date): string => { - const formatOptions: Intl.DateTimeFormatOptions = { + let formatOptions: Intl.DateTimeFormatOptions = { + month: 'long', + day: 'numeric', weekday: 'long', hour: 'numeric', minute: '2-digit', - month: 'long', - day: 'numeric', + } + + const dueDateMoment = moment(dueDate) + const today = moment() + + if (!dueDateMoment.isSame(today, 'year')) { + formatOptions = { + ...formatOptions, + year: 'numeric', + } } return dueDate.toLocaleString( |