Skip to content

Instantly share code, notes, and snippets.

@leonid-shevtsov
Last active November 5, 2022 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonid-shevtsov/10267e2f210e3d8018055eb48cc65d1d to your computer and use it in GitHub Desktop.
Save leonid-shevtsov/10267e2f210e3d8018055eb48cc65d1d to your computer and use it in GitHub Desktop.
(defn build-schedule []
(let [start-date (t/zoned-date-time "2022-11-01T00:00:00+02:00[Europe/Kiev]")
days (range 1 30)
interval (t/new-duration 6 :hours)
duration (t/new-duration 2 :hours)
for-day (fn [day]
(let [day-offset (* 2 (nth [0 2 1] (mod day 3)))
offset-duration (t/+ (t/new-duration (- day 1) :days)
(t/new-duration day-offset :hours))
first-blackout (t/>> start-date offset-duration)]
(take 4 (iterate #(t/>> % interval) first-blackout))))
dates (mapcat for-day days)]
(map-indexed
(fn [index date]
{
:from (-> date t/instant i/to-epoch-milli)
:to (-> (t/>> date duration) t/instant i/to-epoch-milli)
:description "Відключення"
:uid (str "me.shevtsov.leonid.blackout-schedule.Nov." index)})
dates)))
BEGIN:VCALENDAR
PRODID:-//Leonid Shevtsov//Blackout-Schedule 0.0.1//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20221104T222050Z
DTSTART:20221101T040000
DTEND:20221101T060000
SUMMARY:Відключення
UID:me.shevtsov.leonid.blackout-schedule.Nov.0
END:VEVENT
END:VCALENDAR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment