Module: Greenwich::Utilities
- Defined in:
- lib/greenwich/utilities.rb
Class Method Summary collapse
- .coerce_to_time_without_zone(value) ⇒ Object
- .coerce_to_time_zone(value) ⇒ Object
- .coerce_to_time_zone_name(value) ⇒ Object
- .get_time_zone(object, time_zone_field_name) ⇒ Object
- .get_time_zone_field(name, columns) ⇒ Object
Class Method Details
.coerce_to_time_without_zone(value) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/greenwich/utilities.rb', line 30 def self.coerce_to_time_without_zone(value) return value if value.is_a?(Time) value.gsub! /\s[-+]\d{4}$/, '' if value.respond_to? :gsub! value.to_time if value.respond_to? :to_time rescue ArgumentError nil end |
.coerce_to_time_zone(value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/greenwich/utilities.rb', line 19 def self.coerce_to_time_zone(value) return nil if value.nil? return value if value.is_a? ActiveSupport::TimeZone ActiveSupport::TimeZone.new(value) end |
.coerce_to_time_zone_name(value) ⇒ Object
26 27 28 |
# File 'lib/greenwich/utilities.rb', line 26 def self.coerce_to_time_zone_name(value) coerce_to_time_zone(value).try(:name) end |
.get_time_zone(object, time_zone_field_name) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/greenwich/utilities.rb', line 9 def self.get_time_zone(object, time_zone_field_name) begin time_zone_name = object.send(time_zone_field_name.to_sym) rescue time_zone_name = '' end Greenwich::Utilities.coerce_to_time_zone(time_zone_name) end |
.get_time_zone_field(name, columns) ⇒ Object
3 4 5 6 7 |
# File 'lib/greenwich/utilities.rb', line 3 def self.get_time_zone_field(name, columns) target_columns = ["#{name}_time_zone", "time_zone"] get_target_column(target_columns, columns) end |