Skip to content

Commit

Permalink
Merge pull request #27 from totono/26-通知は時間でしか判定していないかも
Browse files Browse the repository at this point in the history
通知の日付チェックの不備を修正
  • Loading branch information
totono authored Mar 29, 2023
2 parents 5d7010d + 1d4276a commit 2a23c2d
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/components/interection/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,46 @@ const resetTimer = (timerId: number, sorted: Model[]) => {
return setInterval(notifier, 5000, sorted);
};

const isFuture = (date: string, time: string | null) => {
if (time == null) return false;
const isFuture = (e: Model) => {
if (e.limit_time == null) return false;

const targetTime = dayjs(date + time);
const targetTime = dayjs(e.limit_date + " " + e.limit_time);
const now = dayjs();

console.log(now);

return targetTime.isAfter(now);
};

const isDeltedOrCompleted = (e: Model) => {
const isDeletedOrCompleted = (e: Model) => {
return e.is_deleted === "Deleted" || e.is_completed === "Completed";
};

const isToday = (notifyTime: Dayjs) => {
const today = dayjs();
return notifyTime.isSame(today, "day");
};


const shouldNotify = (e: Model) => {

if (e.limit_time == null) return false;
if (e.is_deleted === "Deleted") return false;
if (e.is_completed === "Completed") return false;

const notifyTime = dayjs(e.limit_date + " " + e.limit_time);
const now = dayjs();
if (notifyTime.isBefore(now)) return false;
return isToday(notifyTime);
};



let timerId: number;

export const setAlarm = (projects: Model[]) => {
const filtered = projects.filter((obj) =>
isFuture(obj.limit_date!, obj.limit_time)
&& !isDeltedOrCompleted(obj)
shouldNotify(obj)
);

if (filtered.length < 0) return;
Expand Down

0 comments on commit 2a23c2d

Please sign in to comment.