File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717(defn- remove-year [formatted-date ]
1818 (string/join (drop 1 (string/split " -" formatted-date )) " -" ))
1919
20- (defn- last-day-of-month? [date ]
21- (def tomorrow (date/ +days date 1 ))
22- (not= (date :month ) (tomorrow :month )))
23-
2420# Public
2521(defn scheduled-for? [task date ]
2622 (def formatted-date (date/format date true ))
3228 (index-of (date :month ) [1 4 7 10 ]))
3329 (string " every year on " (remove-year formatted-date )) true
3430 (string " on " formatted-date ) true
35- " every last day" (last-day-of-month? date )))
31+ " every last day" (date/ last-day-of-month? date )))
3632
3733(defn- missed-on-day [plan task date ]
3834 (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 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
You can’t perform that action at this time.
0 commit comments