Line data Source code
1 4 : (ns matchscore.telegram.daily-reminder
2 : (:import
3 : (java.time Instant LocalTime ZoneId ZonedDateTime)))
4 :
5 :
6 16 : (def ^:private reminder-zone (ZoneId/of "Europe/Kyiv"))
7 :
8 :
9 20 : (def ^:private reminder-time (LocalTime/of 9 0))
10 :
11 :
12 4 : (defn latest-boundary
13 : "Most recent 09:00 Europe/Kyiv at or before `now`. Resolved in the named zone, so
14 : daylight-saving changes need no special handling."
15 : [^Instant now]
16 6 : (let [local (.atZone now reminder-zone)
17 10 : today (ZonedDateTime/of (.toLocalDate local) reminder-time reminder-zone)]
18 12 : (.toInstant (if (.isBefore local today) (.minusDays today 1) today))))
19 :
20 :
21 4 : (defn due?
22 : "A main post is reposted once per boundary: only while it predates the boundary."
23 : [post boundary]
24 18 : (< (inst-ms (:created-datetime post)) (inst-ms boundary)))
|