Skip to content
Snippets Groups Projects
Commit eb174670 authored by Tyler Lemburg's avatar Tyler Lemburg
Browse files

DST Fixes

parent ef21b88a
No related branches found
No related tags found
No related merge requests found
......@@ -227,14 +227,16 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
if params[:recurring_type] == 'weekly' || params[:recurring_type] == 'biweeekly'
inc = 7.days
inc = 14.days if params[:recurring_type] == 'biweeekly'
new_start = start_time
new_start = start_time.dup
while (new_start = new_start + inc) <= recurs_until_date + 1.day
starts << new_start
# reset in case we moved past DST change
new_start = (new_start + 1.hour).midnight.in_time_zone
starts << new_start + start_time.minutes_after_midnight.minutes
end
elsif %w(1st 2nd 3rd 4th).include?(params[:recurring_type])
elsif %w(first second third fourth).include?(params[:recurring_type])
day_of_week = start_time.wday
new_start = start_time
new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month
year = new_start.year
......@@ -246,7 +248,16 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
end
# now add weeks
start_day += (params[:recurring_type][0].to_i - 1).weeks
weeks = {
"first" => 1,
"second" => 2,
"third" => 3,
"fourth" => 4
}
start_day += (weeks[params[:recurring_type]] - 1).weeks
# reset this to midnight in case of DST change
start_day = (start_day + 1.hour).midnight.in_time_zone
# and set the start time
start_day += start_time.hour.hours + start_time.min.minutes
......@@ -257,13 +268,14 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
end
elsif params[:recurring_type] == 'last'
day_of_week = start_time.wday
new_start = start_time
new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month
year = new_start.year
month = new_start.month + 1
month = 1 and year += 1 if month == 13
start_day = Time.new(year, month, 1).midnight.in_time_zone
while (start_day.wday != day_of_week)
start_day = start_day + 1.day
end
......@@ -272,6 +284,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
while (start_day + 1.week).month == month
start_day += 1.week
end
# reset this to midnight in case of DST change
start_day = (start_day + 1.hour).midnight.in_time_zone
# and set the start time
start_day += start_time.hour.hours + start_time.min.minutes
......@@ -281,7 +296,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
new_start = start_day
end
elsif params[:recurring_type] == 'day'
new_start = start_time
new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month
year = new_start.year
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment