Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: show correct upcoming/past tag for reminders on today

Abdullah Attafebf742ea277
diff --git a/packages/core/__tests__/reminders.test.js b/packages/core/__tests__/reminders.test.js
index e1b9464d9..1c2d3d445 100644
--- a/packages/core/__tests__/reminders.test.js
+++ b/packages/core/__tests__/reminders.test.js
@@ -86,11 +86,11 @@ describe("format reminder time", () => {
test("weekly reminder [current week, today]", () => {
const reminder = {
recurringMode: "week",
- date: new Date(0).setHours(3),
+ date: new Date(0).setHours(21),
selectedDays: [0, 1],
mode: "repeat"
};
- expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 03:00 AM");
+ expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("monthly reminder [current month]", () => {
@@ -120,11 +120,11 @@ describe("format reminder time", () => {
test("monthly reminder [current month, today]", () => {
const reminder = {
recurringMode: "month",
- date: new Date(0).setHours(3),
+ date: new Date(0).setHours(21),
selectedDays: [6],
mode: "repeat"
};
- expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 03:00 AM");
+ expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("today", () => {
@@ -150,4 +150,20 @@ describe("format reminder time", () => {
};
expect(formatReminderTime(reminder)).toBe("Last: Yesterday, 08:05 AM");
});
+
+ test("exactly on time", () => {
+ const reminder = {
+ date: new Date(2022, 5, 6, 5, 5).getTime(),
+ mode: "once"
+ };
+ expect(formatReminderTime(reminder)).toBe("Last: Today, 05:05 AM");
+ });
+
+ test("past but still on the same day", () => {
+ const reminder = {
+ date: new Date(2022, 5, 6, 3, 5).getTime(),
+ mode: "once"
+ };
+ expect(formatReminderTime(reminder)).toBe("Last: Today, 03:05 AM");
+ });
});
diff --git a/packages/core/collections/reminders.js b/packages/core/collections/reminders.js
index 0ab2202c9..df3bb9794 100644
--- a/packages/core/collections/reminders.js
+++ b/packages/core/collections/reminders.js
@@ -137,14 +137,13 @@ export function formatReminderTime(reminder) {
return `Last: Yesterday, ${dayjs(time).format("hh:mm A")}`;
}
+ const isPast = dayjs(time).isSameOrBefore(dayjs());
+ const tag = isPast ? "Last" : "Upcoming";
if (dayjs(time).isToday()) {
- return `Upcoming: Today, ${dayjs(time).format("hh:mm A")}`;
+ return `${tag}: Today, ${dayjs(time).format("hh:mm A")}`;
}
- const isPast = dayjs(time).isBefore(dayjs());
- return dayjs(time).format(
- `${isPast ? "[Last]:" : "[Upcoming]:"} ddd, YYYY-MM-DD hh:mm A`
- );
+ return dayjs(time).format(`[${tag}]: ddd, YYYY-MM-DD hh:mm A`);
}
/**