Class: LocalDateTimeAttributes::LocalDateTime
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- LocalDateTimeAttributes::LocalDateTime
- Defined in:
- lib/local_date_time_attributes/local_date_time.rb
Instance Method Summary collapse
-
#initialize(date_time) ⇒ LocalDateTime
constructor
A new instance of LocalDateTime.
- #nil? ⇒ Boolean
-
#to_local(time_zone = Time.zone.try(:name)) ⇒ Object
Returns a datetime in the timezone specified without changing the time.
Constructor Details
#initialize(date_time) ⇒ LocalDateTime
Returns a new instance of 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
#nil? ⇒ Boolean
18 19 20 |
# File 'lib/local_date_time_attributes/local_date_time.rb', line 18 def nil? __getobj__.nil? end |
#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? = ActiveSupport::TimeZone.new(time_zone).local_to_utc(__getobj__) .in_time_zone(time_zone) if .respond_to? :in_time_zone end |