Skip to content

Instantly share code, notes, and snippets.

@danott
Created January 28, 2022 21:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danott/c9f94e0d2edbb1f5cd62de83d8e76ec1 to your computer and use it in GitHub Desktop.
Save danott/c9f94e0d2edbb1f5cd62de83d8e76ec1 to your computer and use it in GitHub Desktop.
A WIP of codifying the Planning Center company calendar
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'repeatable', "= 1.0.0"
end
weekdays = Repeatable::Expression::Union.new(
Repeatable::Expression::Weekday.new(weekday: 1),
Repeatable::Expression::Weekday.new(weekday: 2),
Repeatable::Expression::Weekday.new(weekday: 3),
Repeatable::Expression::Weekday.new(weekday: 4),
Repeatable::Expression::Weekday.new(weekday: 5),
)
every_other_friday = Repeatable::Expression::Biweekly.new(weekday: 5, start_after: Date.new(2022, 2, 3))
summer_fridays = Repeatable::Expression::Intersection.new(
Repeatable::Expression::RangeInYear.new(start_month: 6, end_month: 8),
Repeatable::Expression::Weekday.new(weekday: 5),
)
christmas_break = Repeatable::Expression::RangeInYear.new(start_month: 12, start_day: 24, end_month: 1, end_day: 1),
# TODO: all the holidays
holidays = Repeatable::Expression::Union.new(
Repeatable::Expression::Intersection.new([
Repeatable::Expression::WeekdayInMonth.new(weekday: 1, count: 3),
Repeatable::Expression::RangeInYear.new(start_month: 1),
]), # MLK
)
planning_center_workdays = Repeatable::Schedule.new(
Repeatable::Expression::Difference.new(
included: weekdays,
excluded: Repeatable::Expression::Union.new(
every_other_friday,
summer_fridays,
christmas_break,
holidays,
)
)
)
date = Date.today
365.times do
verdict = planning_center_workdays.include?(date) ? "✅" : "❌"
puts "Is #{date} (#{date.strftime('%a')}) a work day? #{verdict}"
date = date.next
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment