File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727 " every 3 months" (and (= (date :day ) 1 )
2828 (index-of (date :month ) [1 4 7 10 ]))
2929 (string " every year on " (remove-year formatted-date )) true
30- (string " on " formatted-date ) true ))
30+ (string " on " formatted-date ) true
31+ " every last day" (date/last-day-of-month? date )))
3132
3233(defn- missed-on-day [plan task date ]
3334 (find (fn [day ] (and (scheduled-for? task (day :date ))
Original file line number Diff line number Diff line change 8686 :day (+ (today :month-day ) 1 )
8787 :week-day (week-day-string (today :week-day ))}))
8888
89+ (defn +days [date n ]
90+ (def new-date-time (+ (to-time date ) (* n seconds-in-day )))
91+ (from-os-date-struct (os/date new-date-time )))
92+
93+ (defn -days [date n ]
94+ (def new-date-time (- (to-time date ) (* n seconds-in-day )))
95+ (from-os-date-struct (os/date new-date-time )))
96+
97+ (defn days-from-now [n ]
98+ (+days (today ) n ))
99+
89100(defn equal?
90101 [d1 d2 ]
91102 (= (to-time d1 ) (to-time d2 )))
112123 [d1 d2 ]
113124 (>= (to-time d1 ) (to-time d2 )))
114125
115- (defn +days [date n ]
116- (def new-date-time (+ (to-time date ) (* n seconds-in-day )))
117- (from-os-date-struct (os/date new-date-time )))
118-
119- (defn -days [date n ]
120- (def new-date-time (- (to-time date ) (* n seconds-in-day )))
121- (from-os-date-struct (os/date new-date-time )))
122-
123- (defn days-from-now [n ]
124- (+days (today ) n ))
126+ (defn last-day-of-month?
127+ ```
128+ Returns true if date is the last day of a month.
129+ ```
130+ [date ]
131+ (def tomorrow (+days date 1 ))
132+ (not= (date :month ) (tomorrow :month )))
Original file line number Diff line number Diff line change 6666 (is (not (scheduled-for? task (d/date 2022 2 1 ))))
6767 (is (not (scheduled-for? task (d/date 2023 1 27 )))))
6868
69+ (deftest scheduled-for-last-day-of-month
70+ (def task (task/build-scheduled-task " Review logs" " every last day" ))
71+ (is (scheduled-for? task (d/date 2022 1 31 )))
72+ (is (scheduled-for? task (d/date 2022 2 28 )))
73+ (is (scheduled-for? task (d/date 2022 3 31 )))
74+ (is (scheduled-for? task (d/date 2022 4 30 )))
75+ (is (scheduled-for? task (d/date 2022 5 31 )))
76+ (is (scheduled-for? task (d/date 2022 6 30 )))
77+ (is (scheduled-for? task (d/date 2022 7 31 )))
78+ (is (scheduled-for? task (d/date 2022 8 31 )))
79+ (is (scheduled-for? task (d/date 2022 9 30 )))
80+ (is (scheduled-for? task (d/date 2022 10 31 )))
81+ (is (scheduled-for? task (d/date 2022 11 30 )))
82+ (is (scheduled-for? task (d/date 2022 12 31 )))
83+ (is (scheduled-for? task (d/date 2023 1 31 )))
84+ (is (not (scheduled-for? task (d/date 2022 1 30 )))))
85+
6986# # —————————————————————————————————————————————————————————————————————————————————————————————————
7087# # Test missed?
7188
Original file line number Diff line number Diff line change 6868 (is (d/after-or-eq? (d/date 2021 7 1 ) (d/date 2021 7 1 )))
6969 (is (not (d/after-or-eq? (d/date 2021 7 1 ) (d/date 2021 7 15 )))))
7070
71+ # # ————————————————————————————————————————————————————————————————————————————————————————————————
72+ # # Test last-day-of-month?
73+
74+ (deftest last-day-of-month?
75+ (is (d/last-day-of-month? (d/date 2022 1 31 )))
76+ (is (d/last-day-of-month? (d/date 2022 2 28 )))
77+ (is (d/last-day-of-month? (d/date 2022 3 31 )))
78+ (is (d/last-day-of-month? (d/date 2022 4 30 )))
79+ (is (d/last-day-of-month? (d/date 2022 5 31 )))
80+ (is (d/last-day-of-month? (d/date 2022 6 30 )))
81+ (is (d/last-day-of-month? (d/date 2022 7 31 )))
82+ (is (d/last-day-of-month? (d/date 2022 8 31 )))
83+ (is (d/last-day-of-month? (d/date 2022 9 30 )))
84+ (is (d/last-day-of-month? (d/date 2022 10 31 )))
85+ (is (d/last-day-of-month? (d/date 2022 11 30 )))
86+ (is (d/last-day-of-month? (d/date 2022 12 31 )))
87+ (is (d/last-day-of-month? (d/date 2023 1 31 )))
88+ (is (not (d/last-day-of-month? (d/date 2022 1 30 )))))
89+
90+
7191# # ————————————————————————————————————————————————————————————————————————————————————————————————
7292# # Test +days
7393
Original file line number Diff line number Diff line change 1616 - Pay football practice (every month)
1717 - Martha's birthday (every 05-24)
1818 - Meeting with Jack (on 2022-05-03)
19+ - Review logs (every last day)
1920 ``` )
2021 (def result (schedule_parser/parse schedule-string ))
2122 (def scheduled-tasks (result :tasks ))
22- (is (= 6 (length scheduled-tasks )))
23+ (is (= 7 (length scheduled-tasks )))
2324 (let [task (scheduled-tasks 0 )]
2425 (is (= " Weekly Meeting" (task :title )))
2526 (is (= false (task :done )))
2627 (is (= " every Tuesday" (task :schedule ))))
2728 (let [task (scheduled-tasks 1 )]
2829 (is (= " Puzzle Storm on Lichess" (task :title )))
29- (is (= false (task :done )))
3030 (is (= " every day" (task :schedule ))))
3131 (let [task (scheduled-tasks 5 )]
3232 (is (= " Meeting with Jack" (task :title )))
33- (is (= false (task :done )))
34- (is (= " on 2022-05-03" (task :schedule )))))
33+ (is (= " on 2022-05-03" (task :schedule ))))
34+ (let [task (scheduled-tasks 6 )]
35+ (is (= " Review logs" (task :title )))
36+ (is (= " every last day" (task :schedule )))))
3537
3638(deftest parse-schedule-when-schedule-can-not-be-parsed
3739 (def schedule-string
You can’t perform that action at this time.
0 commit comments