Skip to content

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

core: add support for yearly reminders

Abdullah Atta9edf6d165dd5
diff --git a/packages/core/package.json b/packages/core/package.json
index d24ecc1e2..7571fdbc8 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -38,6 +38,7 @@
"ws": "^8.13.0"
},
"scripts": {
+ "postinstall": "patch-package",
"prebuild": "node scripts/prebuild.mjs",
"pretest": "node scripts/prebuild.mjs",
"pretest:e2e": "node scripts/prebuild.mjs",
diff --git a/packages/core/src/collections/reminders.ts b/packages/core/src/collections/reminders.ts
index 9bfe47f4f..1e42bd793 100644
--- a/packages/core/src/collections/reminders.ts
+++ b/packages/core/src/collections/reminders.ts
@@ -181,16 +181,32 @@ export function isReminderToday(reminder: Reminder) {
export function getUpcomingReminderTime(reminder: Reminder) {
if (reminder.mode === "once") return reminder.date;
- // this is only the time (hour & minutes); date is not included
+
+ const isDay = reminder.recurringMode === "day";
+ const isWeek = reminder.recurringMode === "week";
+ const isMonth = reminder.recurringMode === "month";
+ const isYear = reminder.recurringMode === "year";
+
+ // this is only the time (hour & minutes) unless it is a
+ // yearly reminder
const time = dayjs(reminder.date);
const now = dayjs();
- const relativeTime = now.clone().hour(time.hour()).minute(time.minute());
+ const relativeTime = isYear
+ ? now
+ .clone()
+ .hour(time.hour())
+ .minute(time.minute())
+ .month(time.month())
+ .date(time.date())
+ : now.clone().hour(time.hour()).minute(time.minute());
const isPast = relativeTime.isSameOrBefore(now);
- const isDay = reminder.recurringMode === "day";
- const isWeek = reminder.recurringMode === "week";
- const isMonth = reminder.recurringMode === "month";
+ if (isYear) {
+ if (isPast) return relativeTime.add(1, "year").valueOf();
+ else return relativeTime.valueOf();
+ }
+
if (isDay) {
if (isPast) return relativeTime.add(1, "day").valueOf();
else return relativeTime.valueOf();
diff --git a/packages/core/src/common.ts b/packages/core/src/common.ts
index 963946a2c..1982d33d2 100644
--- a/packages/core/src/common.ts
+++ b/packages/core/src/common.ts
@@ -124,23 +124,27 @@ export const EVENTS = {
};
const separators = ["-", "/"];
+const DD = "DD";
+const MM = "MM";
+const YYYY = "YYYY";
export const DATE_FORMATS = [
...separators
- .map((sep) => {
- const DD = "DD";
- const MM = "MM";
- const YYYY = "YYYY";
-
- return [
- [DD, MM, YYYY].join(sep),
- [MM, DD, YYYY].join(sep),
- [YYYY, MM, DD].join(sep)
- ];
- })
+ .map((sep) => [
+ [DD, MM, YYYY].join(sep),
+ [MM, DD, YYYY].join(sep),
+ [YYYY, MM, DD].join(sep)
+ ])
.flat(),
"MMM D, YYYY"
];
+export const DATE_FORMATS_WITHOUT_YEAR = [
+ ...separators
+ .map((sep) => [[DD, MM].join(sep), [MM, DD].join(sep), [MM, DD].join(sep)])
+ .flat(),
+ "MMM D"
+];
+
export const TIME_FORMATS = ["12-hour", "24-hour"];
export const CURRENT_DATABASE_VERSION = 6.0;
diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts
index 7958365d1..a667e22b1 100644
--- a/packages/core/src/types.ts
+++ b/packages/core/src/types.ts
@@ -351,7 +351,7 @@ export interface Reminder extends BaseItem<"reminder"> {
priority: "silent" | "vibrate" | "urgent";
date: number;
mode: "repeat" | "once" | "permanent";
- recurringMode?: "week" | "month" | "day";
+ recurringMode?: "week" | "month" | "day" | "year";
selectedDays?: number[];
localOnly?: boolean;
disabled?: boolean;
diff --git a/packages/core/src/utils/date.ts b/packages/core/src/utils/date.ts
index 8f88981f8..c1446c529 100644
--- a/packages/core/src/utils/date.ts
+++ b/packages/core/src/utils/date.ts
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dayjs from "dayjs";
+import { DATE_FORMATS, DATE_FORMATS_WITHOUT_YEAR } from "../common";
export type TimeFormat = "12-hour" | "24-hour";
@@ -69,7 +70,7 @@ export type TimeOptions = {
timeFormat: TimeFormat;
};
export type DateOptions = {
- type: "date";
+ type: "date" | "date-without-year";
dateFormat: string;
};
export type DateTimeOptions = {
@@ -95,7 +96,13 @@ export function formatDate(
case "time":
return dayjs(date).format(getTimeFormat(options.timeFormat));
case "date":
- return dayjs(date).format(`${options.dateFormat}`);
+ return dayjs(date).format(options.dateFormat);
+ case "date-without-year": {
+ const format =
+ DATE_FORMATS_WITHOUT_YEAR[DATE_FORMATS.indexOf(options.dateFormat)];
+ if (!format) return dayjs(date).format("MM-DD");
+ return dayjs(date).format(format);
+ }
}
}