1 import { c, msgid } from 'ttag';
3 import { fromLocalDate, toUTCDate } from '../../date/timezone';
4 import type { NotificationModel } from '../../interfaces/calendar';
5 import { NOTIFICATION_UNITS, NOTIFICATION_WHEN } from '../constants';
7 const getNotificationString = (notification: NotificationModel, formatTime: (date: Date) => string) => {
8 const { value = 0, unit, when, at, isAllDay } = notification;
10 if (!isAllDay || !at) {
12 return c('Notifications').t`At time of event`;
15 if (when === NOTIFICATION_WHEN.BEFORE) {
16 if (unit === NOTIFICATION_UNITS.MINUTE) {
17 return c('Notifications').ngettext(msgid`${value} minute before`, `${value} minutes before`, value);
19 if (unit === NOTIFICATION_UNITS.HOUR) {
20 return c('Notifications').ngettext(msgid`${value} hour before`, `${value} hours before`, value);
22 if (unit === NOTIFICATION_UNITS.DAY) {
23 return c('Notifications').ngettext(msgid`${value} day before`, `${value} days before`, value);
25 if (unit === NOTIFICATION_UNITS.WEEK) {
26 return c('Notifications').ngettext(msgid`${value} week before`, `${value} weeks before`, value);
30 if (when === NOTIFICATION_WHEN.AFTER) {
31 if (unit === NOTIFICATION_UNITS.MINUTE) {
32 return c('Notifications').ngettext(msgid`${value} minute after`, `${value} minutes after`, value);
34 if (unit === NOTIFICATION_UNITS.HOUR) {
35 return c('Notifications').ngettext(msgid`${value} hour after`, `${value} hours after`, value);
37 if (unit === NOTIFICATION_UNITS.DAY) {
38 return c('Notifications').ngettext(msgid`${value} day after`, `${value} days after`, value);
40 if (unit === NOTIFICATION_UNITS.WEEK) {
41 return c('Notifications').ngettext(msgid`${value} week after`, `${value} weeks after`, value);
45 return c('Notifications').t`Unknown`;
48 const modifiedAt = toUTCDate(fromLocalDate(at));
49 const time = formatTime(modifiedAt);
52 return c('Notifications').t`On the same day at ${time}`;
55 if (when === NOTIFICATION_WHEN.BEFORE) {
56 if (unit === NOTIFICATION_UNITS.MINUTE) {
57 return c('Notifications').ngettext(
58 msgid`${value} minute before at ${time}`,
59 `${value} minutes before at ${time}`,
63 if (unit === NOTIFICATION_UNITS.HOUR) {
64 return c('Notifications').ngettext(
65 msgid`${value} hour before at ${time}`,
66 `${value} hours before at ${time}`,
70 if (unit === NOTIFICATION_UNITS.DAY) {
71 return c('Notifications').ngettext(
72 msgid`${value} day before at ${time}`,
73 `${value} days before at ${time}`,
77 if (unit === NOTIFICATION_UNITS.WEEK) {
78 return c('Notifications').ngettext(
79 msgid`${value} week before at ${time}`,
80 `${value} weeks before at ${time}`,
86 if (when === NOTIFICATION_WHEN.AFTER) {
87 if (unit === NOTIFICATION_UNITS.MINUTE) {
88 return c('Notifications').ngettext(
89 msgid`${value} minute after at ${time}`,
90 `${value} minutes after at ${time}`,
94 if (unit === NOTIFICATION_UNITS.HOUR) {
95 return c('Notifications').ngettext(
96 msgid`${value} hour after at ${time}`,
97 `${value} hours after at ${time}`,
101 if (unit === NOTIFICATION_UNITS.DAY) {
102 return c('Notifications').ngettext(
103 msgid`${value} day after at ${time}`,
104 `${value} days after at ${time}`,
108 if (unit === NOTIFICATION_UNITS.WEEK) {
109 return c('Notifications').ngettext(
110 msgid`${value} week after at ${time}`,
111 `${value} weeks after at ${time}`,
118 export default getNotificationString;