Module: OmniauthOpenidFederation::TimeHelpers
- Defined in:
- lib/omniauth_openid_federation/time_helpers.rb
Class Method Summary collapse
-
.at(timestamp) ⇒ Time
Convert a timestamp to Time, using Time.zone if available, otherwise Time.
-
.now ⇒ Time
Get current time, using Time.zone if available, otherwise Time.
-
.parse(time_string) ⇒ Time
Parse a time string, using Time.zone if available, otherwise Time.
-
.time_zone_available? ⇒ Boolean
Check if Time.zone is available and configured.
Class Method Details
.at(timestamp) ⇒ Time
Convert a timestamp to Time, using Time.zone if available, otherwise Time
22 23 24 25 26 27 28 29 30 |
# File 'lib/omniauth_openid_federation/time_helpers.rb', line 22 def self.at() if time_zone_available? Time.zone.at() else # rubocop:disable Rails/TimeZone Time.at() # rubocop:enable Rails/TimeZone end end |
.now ⇒ Time
Get current time, using Time.zone if available, otherwise Time
8 9 10 11 12 13 14 15 16 |
# File 'lib/omniauth_openid_federation/time_helpers.rb', line 8 def self.now if time_zone_available? Time.zone.now else # rubocop:disable Rails/TimeZone Time.now # rubocop:enable Rails/TimeZone end end |
.parse(time_string) ⇒ Time
Parse a time string, using Time.zone if available, otherwise Time
36 37 38 39 40 41 42 43 44 |
# File 'lib/omniauth_openid_federation/time_helpers.rb', line 36 def self.parse(time_string) if time_zone_available? Time.zone.parse(time_string) else # rubocop:disable Rails/TimeZone Time.parse(time_string) # rubocop:enable Rails/TimeZone end end |
.time_zone_available? ⇒ Boolean
Check if Time.zone is available and configured
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omniauth_openid_federation/time_helpers.rb', line 49 def self.time_zone_available? return false unless defined?(ActiveSupport) return false unless Time.respond_to?(:zone) begin !Time.zone.nil? rescue false end end |