Skip to content

Commit 9180279

Browse files
authored
Merge pull request #123 from hackberrydev/schedule-old-tasks
Don't schedule tasks older than 30 days
2 parents 1919ac1 + 546826c commit 9180279

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/jpm_tree
33
/tags*
44
/test/examples/*.bkp
5+
*.tested

src/commands/schedule_tasks.janet

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,25 @@
3636
(not (day/has-task? day task))))
3737
(plan/all-days-before plan date)))
3838

39+
(defn- older-than-30-days? [date today]
40+
(date/before? date (date/-days today 30)))
41+
3942
# Public
4043
(defn missed?
4144
```
4245
Checks if the task was missed in the plan up to the passed date.
4346
4447
Returns true or false.
48+
49+
plan - The plan.
50+
task - The scheduled task.
51+
date - A date. Typically today.
4552
```
4653
[plan task date]
4754
(def day (missed-on-day plan task date))
48-
(and day (not (plan/has-task-after? plan task (day :date)))))
55+
(and day
56+
(not (older-than-30-days? (day :date) date))
57+
(not (plan/has-task-after? plan task (day :date)))))
4958

5059
(defn- mark-tasks-as-missed [plan tasks date]
5160
(map (fn [task]

test/commands/schedule_tasks_test.janet

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
(day/build-day (d/date 2022 7 15))]))
110110
(test (missed? plan scheduled-task (d/date 2022 8 3)) true))
111111

112+
(deftest "returns false when the task is missed, but it's older than 30 days"
113+
(def plan (plan/build-plan
114+
:days @[(day/build-day (d/date 2022 9 11))
115+
(day/build-day (d/date 2022 8 1))]))
116+
(test (not (missed? plan scheduled-task (d/date 2022 9 11))) true))
117+
112118
(deftest "returns false when the task is scheduled for another day"
113119
(def plan (plan/build-plan
114120
:days @[(day/build-day (d/date 2022 8 2)

0 commit comments

Comments
 (0)