-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgen_dates.rb
37 lines (33 loc) · 1.05 KB
/
gen_dates.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'date'
require 'yaml'
start_date = Date.new(2024, 12, 2)
end_date = Date.new(2025, 2, 23)
vacation_start = Date.new(2024, 12, 21) #inclusive
vacation_end = Date.new(2025, 1, 5) # inclusive
allowed_days_of_week = [1,2,4,5] # monday is 1
generate_yaml = false #we either generate yaml or csv
day_list = []
current = start_date;
while(current <= end_date)
if(current < vacation_start or current > vacation_end)
day_list << current
end
current = current.next_day()
end
day_list = day_list.keep_if { |d| allowed_days_of_week.include?(d.cwday()) }
class_index = 0;
if generate_yaml then
string_list = day_list.map { |d|
class_index = class_index + 1
{ "type" => "class_session",
"class_num" => class_index,
"date" => d.to_time().strftime("%Y-%m-%d 08:00") }
}
puts string_list.to_yaml
else
day_list.each { |d|
class_index = class_index + 1
puts " Day #{class_index} , #{d.to_time().strftime("%Y-%m-%d 23:59")}"
}
end
$stderr.puts "#{day_list.length} days output as #{ generate_yaml ? 'YAML (not csv)' : 'CSV (not YAML)' } "