core: fix upcoming reminder time calculation (#3341)

* core: added missing equality sign

* core: added test
This commit is contained in:
Muhammad Ali
2023-09-21 14:04:20 +05:00
committed by GitHub
parent c42dc0f12e
commit abc3b5569c
2 changed files with 22 additions and 2 deletions

View File

@@ -94,6 +94,16 @@ describe("format reminder time", () => {
expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("weekly reminder [current week, today with multiple days]", () => {
const reminder = {
recurringMode: "week",
date: new Date(5).setHours(21),
selectedDays: [1, 2, 5, 6],
mode: "repeat"
};
expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("monthly reminder [current month]", () => {
const reminder = {
recurringMode: "month",
@@ -128,6 +138,16 @@ describe("format reminder time", () => {
expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("monthly reminder [current month, today with multiple days]", () => {
const reminder = {
recurringMode: "month",
date: new Date(0).setHours(21),
selectedDays: [6, 7, 8],
mode: "repeat"
};
expect(formatReminderTime(reminder)).toBe("Upcoming: Today, 09:00 PM");
});
test("today", () => {
const reminder = {
date: new Date(2022, 5, 6, 8, 5).getTime(),

View File

@@ -227,14 +227,14 @@ function getUpcomingReminderTime(reminder) {
return relativeTime.day(sorted[0]).add(1, "week").valueOf();
else {
for (const day of reminder.selectedDays)
if (now.day() < day) return relativeTime.day(day).valueOf();
if (now.day() <= day) return relativeTime.day(day).valueOf();
}
} else if (isMonth) {
if (now.date() > lastSelectedDay || isPast)
return relativeTime.date(sorted[0]).add(1, "month").valueOf();
else {
for (const day of reminder.selectedDays)
if (now.date() < day) return relativeTime.date(day).valueOf();
if (now.date() <= day) return relativeTime.date(day).valueOf();
}
}