Class: SoapyCake::TimeConverter
- Inherits:
-
Object
- Object
- SoapyCake::TimeConverter
- Defined in:
- lib/soapy_cake/time_converter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #from_cake(value) ⇒ Object
-
#initialize(time_zone, time_offset = nil) ⇒ TimeConverter
constructor
A new instance of TimeConverter.
- #to_cake(date) ⇒ Object
Constructor Details
#initialize(time_zone, time_offset = nil) ⇒ TimeConverter
Returns a new instance of TimeConverter.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/soapy_cake/time_converter.rb', line 5 def initialize(time_zone, time_offset = nil) if time_offset self.class.print_deprecation_warning # Etc/GMT time zones have their sign reversed time_zone = format('Etc/GMT%+d', -time_offset.to_i) end raise Error, 'Cake time zone missing' if time_zone.blank? @zone = ActiveSupport::TimeZone[time_zone] end |
Class Method Details
.print_deprecation_warning ⇒ Object
26 27 28 29 30 31 |
# File 'lib/soapy_cake/time_converter.rb', line 26 def self.print_deprecation_warning return if @deprecation_warning_printed @deprecation_warning_printed = true STDERR.puts 'SoapyCake - DEPRECATED: Please use time_zone instead of time_offset.' end |
Instance Method Details
#from_cake(value) ⇒ Object
22 23 24 |
# File 'lib/soapy_cake/time_converter.rb', line 22 def from_cake(value) zone.parse(value).utc end |
#to_cake(date) ⇒ Object
17 18 19 20 |
# File 'lib/soapy_cake/time_converter.rb', line 17 def to_cake(date) date = date.to_datetime if date.is_a?(Date) date.in_time_zone(zone).strftime('%Y-%m-%dT%H:%M:%S') end |