Module: TimecopHarness

Defined in:
lib/cucumber/sammies/step_definitions/time_steps.rb

Instance Method Summary collapse

Instance Method Details

#current_timeObject



24
25
26
27
28
29
30
# File 'lib/cucumber/sammies/step_definitions/time_steps.rb', line 24

def current_time
  if use_timezones?
    Time.current
  else
    Time.now
  end
end

#parse_time(str) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cucumber/sammies/step_definitions/time_steps.rb', line 16

def parse_time(str)
  if use_timezones?
    Time.zone.parse(str)
  else
    Time.parse(str)
  end
end

#use_timezones?Boolean

When you have to make your rails app time zone aware you have to go 100% otherwise you are better off ignoring time zones at all. makandracards.com/makandra/8723-guide-to-localizing-a-rails-application

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/cucumber/sammies/step_definitions/time_steps.rb', line 11

def use_timezones?
  active_record_loaded = defined?(ActiveRecord::Base)
  (!active_record_loaded || ActiveRecord::Base.default_timezone != :local) && Time.zone
end