Created
December 26, 2014 23:40
-
-
Save trcook/2353c9df4f8b4c8a6e9d to your computer and use it in GitHub Desktop.
an easy script to generate a list of dates for a course schedule. This prints out the dates of specified week days (in this example, monday wednesday and friday) for each week day between a start and end date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'date' | |
dates=Array.new() | |
#end date is 'c' | |
c = Date.new(2015,05,07) | |
# start date is 'b' | |
b= Date.new(2015,01,12) | |
days_of_week=["Monday","Wednesday","Friday"] | |
max_weeks= ((c-b)/7).to_int | |
max_weeks=max_weeks.ceil+1 | |
course_day=0 | |
(c-b).to_int.times do |t| | |
w_day= Date::DAYNAMES[(b+t).wday] | |
date_day=(b+t).day | |
date_month=(b+t).month | |
week=(t/7)+1 | |
if days_of_week.member?(w_day) | |
course_day+=1 | |
dates<<{"course_day"=>course_day,"weekday"=>w_day,"month"=>date_month,"date_day"=>date_day,"week"=>week} | |
end | |
end | |
File::open( 'my_dates'+ '.txt', 'w' ) do |f| | |
dates.each do |t| | |
f<< %{## Week: #{t["week"]} Day: #{t["course_day"]}\nDate: #{t["month"]}-#{t["date_day"]} \ | |
Weekday: #{t["weekday"]} | |
Weeks Remining:#{max_weeks-t["week"]} Days Remaining: #{max_weeks*days_of_week.length-(t["course_day"]+1)} | |
\n\n} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment