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 ...@@ -227,14 +227,16 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
if params[:recurring_type] == 'weekly' || params[:recurring_type] == 'biweeekly' if params[:recurring_type] == 'weekly' || params[:recurring_type] == 'biweeekly'
inc = 7.days inc = 7.days
inc = 14.days if params[:recurring_type] == 'biweeekly' 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 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 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 day_of_week = start_time.wday
new_start = start_time new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day) while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month # calculate when this is next month
year = new_start.year year = new_start.year
...@@ -246,7 +248,16 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -246,7 +248,16 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
end end
# now add weeks # 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 # and set the start time
start_day += start_time.hour.hours + start_time.min.minutes start_day += start_time.hour.hours + start_time.min.minutes
...@@ -257,13 +268,14 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -257,13 +268,14 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
end end
elsif params[:recurring_type] == 'last' elsif params[:recurring_type] == 'last'
day_of_week = start_time.wday day_of_week = start_time.wday
new_start = start_time new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day) while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month # calculate when this is next month
year = new_start.year year = new_start.year
month = new_start.month + 1 month = new_start.month + 1
month = 1 and year += 1 if month == 13 month = 1 and year += 1 if month == 13
start_day = Time.new(year, month, 1).midnight.in_time_zone start_day = Time.new(year, month, 1).midnight.in_time_zone
while (start_day.wday != day_of_week) while (start_day.wday != day_of_week)
start_day = start_day + 1.day start_day = start_day + 1.day
end end
...@@ -272,6 +284,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -272,6 +284,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
while (start_day + 1.week).month == month while (start_day + 1.week).month == month
start_day += 1.week start_day += 1.week
end 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 # and set the start time
start_day += start_time.hour.hours + start_time.min.minutes start_day += start_time.hour.hours + start_time.min.minutes
...@@ -281,7 +296,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -281,7 +296,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
new_start = start_day new_start = start_day
end end
elsif params[:recurring_type] == 'day' elsif params[:recurring_type] == 'day'
new_start = start_time new_start = start_time.dup
while (new_start <= recurs_until_date + 1.day) while (new_start <= recurs_until_date + 1.day)
# calculate when this is next month # calculate when this is next month
year = new_start.year year = new_start.year
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment