Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace assert with rspec matcher so we can see output. A few more Ti…

…me.zone fixes
  • Loading branch information...
commit d1c56566ef57fdb1449c4b301252e5de17b52b8f 1 parent 6326569
@porcupie porcupie authored
View
3  app/controllers/application_controller.rb
@@ -2,6 +2,7 @@ module ActiveSupport
class TimeWithZone
def zone=(new_zone = ::Time.zone)
# Reinitialize with the new zone and the local time
+ # FIXME: ::Time has no .get_zone ?
initialize(nil, ::Time.__send__(:get_zone, new_zone), time)
end
end
@@ -34,7 +35,7 @@ def force_ssl
def set_tz_offset(attr)
if params[attr] && params[attr][:starts_at]
- params[attr][:timezone_offset] = DateTime.parse(params[attr][:starts_at]).utc_offset
+ params[attr][:timezone_offset] = Time.zone.parse(params[attr][:starts_at]).utc_offset
end
end
end
View
4 app/models/call_list.rb
@@ -59,7 +59,7 @@ def notification_users
[owners, escalations].compact.flatten.uniq
end
- def in_business_hours?(now = Time.now)
+ def in_business_hours?(now = Time.zone.now)
return false if business_hours.nil? or business_hours.empty?
now = now.in_time_zone(business_time_zone)
@@ -122,7 +122,7 @@ def gen_oncall_assignments(start_date = nil, w = AppConfig.oncall_assignments_ge
raise "Need to enable automatic oncall assignments feature" unless oncall_assignments_gen && oncall_assignments_gen.enable == true
raise "No available oncall candidate" if oncall_candidates.blank?
- start_date ||= oncall_assignments_gen.last_gen || Time.now.utc
+ start_date ||= oncall_assignments_gen.last_gen || Time.zone.now.utc
end_date = Ringring::OncallAssignmentsGenerator::next_oncall_cycle(start_date, oncall_assignments_gen.cycle_day)
end_date = end_date.change(:hour => oncall_assignments_gen.cycle_time.hour, :min => oncall_assignments_gen.cycle_time.min)
#end_date -= oncall_assignments_gen.timezone_offset if end_date.utc_offset == 0
View
2  app/models/user.rb
@@ -61,7 +61,7 @@ def old_sms_email
end
def on_vacation?
- now = Time.now
+ now = Time.zone.now
vacations.each do |vacation|
return true if vacation.starts_at <= now && now <= vacation.ends_at
end
View
12 spec/models/call_list_spec.rb
@@ -167,18 +167,18 @@
it "correctly determines if in business hour for UTC time" do
call_list = CallList.make!(:business_time_zone => 'UTC', :twilio_list_id => (rand(2132)).to_i)
(0..6).each do |wday|
- call_list.business_hours.create(:wday => wday, :start_time => Time.parse("8:00 AM +0000"),
- :end_time => Time.parse("8:00 PM +0000"))
+ call_list.business_hours.create(:wday => wday, :start_time => Time.zone.parse("8:00 AM +0000"),
+ :end_time => Time.zone.parse("8:00 PM +0000"))
end
- call_list.in_business_hours?(Time.parse("9:00 AM +0000")).should be_true
+ call_list.in_business_hours?(Time.zone.parse("9:00 AM +0000")).should be_true
end
it "correctly determines if in business hour for non UTC time" do
call_list = CallList.make!(:business_time_zone => 'Arizona', :twilio_list_id => (rand(2132)).to_i)
(0..6).each do |wday|
- call_list.business_hours.create(:wday => wday, :start_time => Time.parse("8:00 AM -0700"),
- :end_time => Time.parse("8:00 PM -0700"))
+ call_list.business_hours.create(:wday => wday, :start_time => Time.zone.parse("8:00 AM -0700"),
+ :end_time => Time.zone.parse("8:00 PM -0700"))
end
- call_list.in_business_hours?(Time.parse("9:00 AM -0700")).should be_true
+ call_list.in_business_hours?(Time.zone.parse("9:00 AM -0700")).should be_true
end
end
View
4 spec/requests/call_lists_spec.rb
@@ -72,8 +72,8 @@
# No longer valid since business time has its own time zone now
actual_time = CallList.find(call_list_id).business_hours.first.start_time.in_time_zone('Mountain Time (US & Canada)')
- utc_time = Time.parse('9:15 UTC')
- assert actual_time == utc_time - actual_time.utc_offset
+ utc_time = Time.zone.parse('9:15 UTC')
+ actual_time.should == utc_time - actual_time.utc_offset
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.