Permalink
Browse files

Use gem american_date to get ruby-1.8.7 date parsing in ruby-1.9.x. A…

… few more Date -> Time.zone fixes in controllers
  • Loading branch information...
1 parent d1c5656 commit 79a9d4d7a0acde7654874870a67f84d7c9d86a14 @porcupie porcupie committed Dec 20, 2012
Showing with 14 additions and 8 deletions.
  1. +4 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +3 −3 app/controllers/call_lists_controller.rb
  4. +5 −5 app/controllers/oncall_assignments_controller.rb
View
4 Gemfile
@@ -5,6 +5,10 @@ gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
+# https://github.com/jeremyevans/ruby-american_date exists to make ruby
+# versions greater than 1.8 parse american-style month/day/year dates
+# correctly. It can also be used on ruby 1.8, but it is basically a noop there.
+gem 'american_date'
gem 'json'
View
2 Gemfile.lock
@@ -31,6 +31,7 @@ GEM
acts_as_ecv (0.0.3)
acts_as_list (0.1.6)
addressable (2.3.2)
+ american_date (1.0.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.0)
@@ -186,6 +187,7 @@ PLATFORMS
DEPENDENCIES
acts_as_ecv
acts_as_list
+ american_date
cancan
capybara
coffee-rails (~> 3.2.1)
View
6 app/controllers/call_lists_controller.rb
@@ -67,7 +67,7 @@ def create
def update
@call_list = CallList.find(params[:id])
params[:call_list][:oncall_assignments_gen_attributes][:enable] = false if params[:call_list][:oncall_assignments_gen_attributes][:enable] == 0
- params[:call_list][:oncall_assignments_gen_attributes][:timezone_offset] = DateTime.parse(params[:call_list][:oncall_assignments_gen_attributes][:cycle_time]).utc_offset
+ params[:call_list][:oncall_assignments_gen_attributes][:timezone_offset] = Time.zone.parse(params[:call_list][:oncall_assignments_gen_attributes][:cycle_time]).utc_offset
params[:call_list][:oncall_assignments_gen_attributes][:cycle_time] = Time.zone.parse(params[:call_list][:oncall_assignments_gen_attributes][:cycle_time])
old_zone = Time.zone
@@ -186,8 +186,8 @@ def download_calendar
cal = RiCal.Calendar do
event do
description "ops oncall"
- dtstart DateTime.parse("3/20/2012 14:47:39")
- dtend DateTime.parse("3/21/2012 19:43:02")
+ dtstart Time.zone.parse("3/20/2012 14:47:39")
+ dtend Time.zone.parse("3/21/2012 19:43:02")
end
end
render :text => cal
View
10 app/controllers/oncall_assignments_controller.rb
@@ -18,7 +18,7 @@ def index
end
def create
- @gotodate = params[:oncall_assignment][:starts_at].to_time.to_i * 1000
+ @gotodate = Time.zone.parse(params[:oncall_assignment][:starts_at]).to_time.to_i * 1000
set_tz_offset
@call_list = CallList.find(params[:call_list_id])
@@ -63,7 +63,7 @@ def show
# it on the week or day view), this method will be called to update the values.
# viv la REST!
def update
- @gotodate = params[:oncall_assignment][:starts_at].to_time.to_i * 1000
+ @gotodate = Time.zone.parse(params[:oncall_assignment][:starts_at]).to_time.to_i * 1000
set_tz_offset
@oncall_assignment = OncallAssignment.find(params[:id])
@@ -73,8 +73,8 @@ def update
params[:oncall_assignment][:user_id] = user_id.id if user_id
params[:oncall_assignment].delete(:oncall)
end
- params[:oncall_assignment][:starts_at] = DateTime.parse(params[:oncall_assignment][:starts_at].to_s) if params[:oncall_assignment][:starts_at]
- params[:oncall_assignment][:ends_at] = DateTime.parse(params[:oncall_assignment][:ends_at].to_s) if params[:oncall_assignment][:ends_at]
+ params[:oncall_assignment][:starts_at] = Time.zone.parse(params[:oncall_assignment][:starts_at].to_s) if params[:oncall_assignment][:starts_at]
+ params[:oncall_assignment][:ends_at] = Time.zone.parse(params[:oncall_assignment][:ends_at].to_s) if params[:oncall_assignment][:ends_at]
end
params[:oncall_assignment][:assigned_by] = current_user.username
@@ -103,7 +103,7 @@ def deprecated_refresh_listing
private
def set_tz_offset
if params[:oncall_assignment] && params[:oncall_assignment][:starts_at]
- params[:oncall_assignment][:timezone_offset] = DateTime.parse(params[:oncall_assignment][:starts_at]).utc_offset
+ params[:oncall_assignment][:timezone_offset] = Time.zone.parse(params[:oncall_assignment][:starts_at]).utc_offset
end
end
end

0 comments on commit 79a9d4d

Please sign in to comment.