Skip to content

Commit 9ba0ebd

Browse files
authored
Merge pull request #110 from hackberrydev/schedule-on-last-friday
Implement scheduling task on last Friday in month
2 parents c4f6557 + ed26c06 commit 9ba0ebd

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/commands/schedule_tasks.janet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
(index-of (date :month) [1 4 7 10]))
2929
(string "every year on " (remove-year formatted-date)) true
3030
(string "on " formatted-date) true
31-
"every last day" (date/last-day-of-month? date)))
31+
"every last day" (date/last-day-of-month? date)
32+
"every last Friday" (date/last-friday-of-month? date)))
3233

3334
(defn- missed-on-day [plan task date]
3435
(find (fn [day] (and (scheduled-for? task (day :date))

src/date.janet

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,17 @@
125125

126126
(defn last-day-of-month?
127127
```
128-
Returns true if date is the last day of a month.
128+
Returns true if the date is the last day of a month.
129129
```
130130
[date]
131131
(def tomorrow (+days date 1))
132132
(not= (date :month) (tomorrow :month)))
133+
134+
(defn last-friday-of-month?
135+
```
136+
Returns true if the date is the last friday of a month.
137+
```
138+
[date]
139+
(def next-week (+days date 7))
140+
(and (= (date :week-day) "Friday")
141+
(not= (date :month) (next-week :month))))

test/commands/schedule_tasks_test.janet

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@
8383
(is (scheduled-for? task (d/date 2023 1 31)))
8484
(is (not (scheduled-for? task (d/date 2022 1 30)))))
8585

86+
(deftest scheduled-for-last-Friday-of-month
87+
(def task (task/build-scheduled-task "Review logs" "every last Friday"))
88+
(is (scheduled-for? task (d/date 2022 1 28)))
89+
(is (scheduled-for? task (d/date 2022 2 25)))
90+
(is (scheduled-for? task (d/date 2022 3 25)))
91+
(is (scheduled-for? task (d/date 2022 4 29)))
92+
(is (scheduled-for? task (d/date 2022 5 27)))
93+
(is (not (scheduled-for? task (d/date 2022 1 31)))))
94+
8695
## —————————————————————————————————————————————————————————————————————————————————————————————————
8796
## Test missed?
8897

test/date_test.janet

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@
8787
(is (d/last-day-of-month? (d/date 2023 1 31)))
8888
(is (not (d/last-day-of-month? (d/date 2022 1 30)))))
8989

90+
## ————————————————————————————————————————————————————————————————————————————————————————————————
91+
## Test last-Friday-of-month?
92+
93+
(deftest last-friday-of-month?
94+
(is (d/last-friday-of-month? (d/date 2022 1 28)))
95+
(is (d/last-friday-of-month? (d/date 2022 2 25)))
96+
(is (d/last-friday-of-month? (d/date 2022 3 25)))
97+
(is (d/last-friday-of-month? (d/date 2022 4 29)))
98+
(is (d/last-friday-of-month? (d/date 2022 5 27)))
99+
(is (not (d/last-friday-of-month? (d/date 2022 1 31))))
100+
(is (not (d/last-friday-of-month? (d/date 2022 1 21))))
101+
(is (not (d/last-friday-of-month? (d/date 2022 2 11)))))
90102

91103
## ————————————————————————————————————————————————————————————————————————————————————————————————
92104
## Test +days

0 commit comments

Comments
 (0)