scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
320 lines • 11.5 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { AbsReminder } from "scriptable-abstract";
const DEFAULT_STATE = {
identifier: "",
title: "",
notes: "",
dueDate: null,
dueDateIncludesTime: false,
isCompleted: false,
isOverdue: false,
priority: 0,
calendar: null,
recurrenceRules: [],
completionDate: null,
creationDate: /* @__PURE__ */ new Date()
};
const _MockReminder = class _MockReminder extends AbsReminder {
static get instance() {
if (!this._instance) {
this._instance = new _MockReminder();
}
return this._instance;
}
constructor() {
super(DEFAULT_STATE);
}
// Basic properties
get identifier() {
return this.state.identifier;
}
get title() {
return this.state.title;
}
set title(value) {
this.setState({ title: value });
}
get notes() {
return this.state.notes;
}
set notes(value) {
this.setState({ notes: value });
}
get dueDate() {
return this.state.dueDate ? new Date(this.state.dueDate) : null;
}
set dueDate(value) {
this.setState({
dueDate: value ? new Date(value) : null
});
}
get dueDateIncludesTime() {
return this.state.dueDateIncludesTime;
}
set dueDateIncludesTime(value) {
this.setState({ dueDateIncludesTime: value });
}
get isCompleted() {
return this.state.isCompleted;
}
set isCompleted(value) {
this.setState({
isCompleted: value,
completionDate: value ? /* @__PURE__ */ new Date() : null
});
}
get isOverdue() {
if (!this.dueDate) return false;
return this.dueDate < /* @__PURE__ */ new Date() && !this.isCompleted;
}
get priority() {
return this.state.priority;
}
set priority(value) {
this.setState({ priority: value });
}
get calendar() {
return this.state.calendar;
}
set calendar(value) {
this.setState({ calendar: value });
}
get completionDate() {
return this.state.completionDate ? new Date(this.state.completionDate) : null;
}
get creationDate() {
return new Date(this.state.creationDate);
}
// Recurrence rules
addRecurrenceRule(recurrenceRule) {
this.setState((state) => ({
recurrenceRules: [...state.recurrenceRules, recurrenceRule]
}));
}
removeAllRecurrenceRules() {
this.setState({ recurrenceRules: [] });
}
// Save and remove
save() {
_MockReminder._reminders.push(this);
}
remove() {
const index = _MockReminder._reminders.indexOf(this);
if (index > -1) {
_MockReminder._reminders.splice(index, 1);
}
}
// Static methods for fetching reminders
static async filterReminders(calendars, predicate) {
const reminders = this._reminders.filter((reminder) => {
if (calendars && calendars.length > 0) {
return calendars.includes(reminder.calendar) && predicate(reminder);
}
return predicate(reminder);
});
return reminders;
}
// Due Today
static async allDueToday(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= today && dueDate < tomorrow;
});
}
static async completedDueToday(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= today && dueDate < tomorrow && reminder.isCompleted;
});
}
static async incompleteDueToday(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= today && dueDate < tomorrow && !reminder.isCompleted;
});
}
// Due Tomorrow
static async allDueTomorrow(calendars) {
const tomorrow = /* @__PURE__ */ new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
const dayAfter = new Date(tomorrow);
dayAfter.setDate(dayAfter.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= tomorrow && dueDate < dayAfter;
});
}
static async completedDueTomorrow(calendars) {
const tomorrow = /* @__PURE__ */ new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
const dayAfter = new Date(tomorrow);
dayAfter.setDate(dayAfter.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= tomorrow && dueDate < dayAfter && reminder.isCompleted;
});
}
static async incompleteDueTomorrow(calendars) {
const tomorrow = /* @__PURE__ */ new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
const dayAfter = new Date(tomorrow);
dayAfter.setDate(dayAfter.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= tomorrow && dueDate < dayAfter && !reminder.isCompleted;
});
}
// Due Yesterday
static async allDueYesterday(calendars) {
const yesterday = /* @__PURE__ */ new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= yesterday && dueDate < today;
});
}
static async completedDueYesterday(calendars) {
const yesterday = /* @__PURE__ */ new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= yesterday && dueDate < today && reminder.isCompleted;
});
}
static async incompleteDueYesterday(calendars) {
const yesterday = /* @__PURE__ */ new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday.setHours(0, 0, 0, 0);
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= yesterday && dueDate < today && !reminder.isCompleted;
});
}
// Due This Week
static async allDueThisWeek(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const startOfWeek = new Date(today);
startOfWeek.setDate(today.getDate() - today.getDay());
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(endOfWeek.getDate() + 7);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startOfWeek && dueDate < endOfWeek;
});
}
static async completedDueThisWeek(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const startOfWeek = new Date(today);
startOfWeek.setDate(today.getDate() - today.getDay());
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(endOfWeek.getDate() + 7);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startOfWeek && dueDate < endOfWeek && reminder.isCompleted;
});
}
static async incompleteDueThisWeek(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const startOfWeek = new Date(today);
startOfWeek.setDate(today.getDate() - today.getDay());
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(endOfWeek.getDate() + 7);
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startOfWeek && dueDate < endOfWeek && !reminder.isCompleted;
});
}
// Due Between
static async allDueBetween(startDate, endDate, calendars) {
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startDate && dueDate < endDate;
});
}
static async completedDueBetween(startDate, endDate, calendars) {
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startDate && dueDate < endDate && reminder.isCompleted;
});
}
static async incompleteDueBetween(startDate, endDate, calendars) {
return this.filterReminders(calendars, (reminder) => {
const dueDate = reminder.dueDate;
return dueDate !== null && dueDate >= startDate && dueDate < endDate && !reminder.isCompleted;
});
}
// Completed
static async completedToday(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return this.filterReminders(calendars, (reminder) => {
const completionDate = reminder.completionDate;
return completionDate !== null && completionDate >= today && completionDate < tomorrow;
});
}
static async completedThisWeek(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const startOfWeek = new Date(today);
startOfWeek.setDate(today.getDate() - today.getDay());
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(endOfWeek.getDate() + 7);
return this.filterReminders(calendars, (reminder) => {
const completionDate = reminder.completionDate;
return completionDate !== null && completionDate >= startOfWeek && completionDate < endOfWeek;
});
}
static async completedLastWeek(calendars) {
const today = /* @__PURE__ */ new Date();
today.setHours(0, 0, 0, 0);
const endOfLastWeek = new Date(today);
endOfLastWeek.setDate(today.getDate() - today.getDay());
const startOfLastWeek = new Date(endOfLastWeek);
startOfLastWeek.setDate(endOfLastWeek.getDate() - 7);
return this.filterReminders(calendars, (reminder) => {
const completionDate = reminder.completionDate;
return completionDate !== null && completionDate >= startOfLastWeek && completionDate < endOfLastWeek;
});
}
// Helper method to clear all reminders (for testing)
static clearAll() {
this._reminders = [];
}
};
__publicField(_MockReminder, "_instance", null);
__publicField(_MockReminder, "_reminders", []);
let MockReminder = _MockReminder;
export {
MockReminder
};
//# sourceMappingURL=reminder.js.map