Class: LocalDateTimeAttributes::LocalDateTime

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/local_date_time_attributes/local_date_time.rb

Instance Method Summary collapse

Constructor Details

#initialize(date_time) ⇒ LocalDateTime



7
8
9
# File 'lib/local_date_time_attributes/local_date_time.rb', line 7

def initialize(date_time)
  super(from_local(date_time))
end

Instance Method Details

#to_local(time_zone = Time.zone.try(:name)) ⇒ Object

Returns a datetime in the timezone specified without changing the time



12
13
14
15
16
# File 'lib/local_date_time_attributes/local_date_time.rb', line 12

def to_local(time_zone = Time.zone.try(:name))
  return if __getobj__.nil? || time_zone.nil?
  converted_timestamp = ActiveSupport::TimeZone.new(time_zone).local_to_utc(__getobj__)
  converted_timestamp.in_time_zone(time_zone) if converted_timestamp.respond_to? :in_time_zone
end