Class: FreightKit::DateTime
- Defined in:
- lib/freight_kit/models/date_time.rb
Overview
Represent dates and times in varous formats.
Instance Attribute Summary collapse
-
#date_time_with_zone ⇒ ActiveSupport::TimeWithZone
Date and time with time zone.
-
#local_date ⇒ Date
Local date.
-
#local_date_time ⇒ String
Local date and time in the format ‘“YYYY-MM-DD HH:MM:SS”` (zero-padded 24 hour clock) aka `DateTime#to_fs(:db)` format.
-
#location ⇒ Object
Returns the value of attribute location.
Instance Method Summary collapse
-
#initialize ⇒ DateTime
constructor
A new instance of DateTime.
Methods inherited from Model
Constructor Details
#initialize ⇒ DateTime
Returns a new instance of DateTime.
22 23 24 25 26 |
# File 'lib/freight_kit/models/date_time.rb', line 22 def initialize(*) super attempt_upgrade_using_location(location) if location.present? end |
Instance Attribute Details
#date_time_with_zone ⇒ ActiveSupport::TimeWithZone
Date and time with time zone.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/freight_kit/models/date_time.rb', line 19 class DateTime < Model attr_accessor :local_date, :local_date_time, :location, :date_time_with_zone def initialize(*) super attempt_upgrade_using_location(location) if location.present? end private def attempt_upgrade_using_location(location) return if @date_time_with_zone.present? || @local_date_time.blank? || location.time_zone.blank? @date_time_with_zone = location.time_zone.parse(@local_date_time) @local_date_time = nil end end |
#local_date ⇒ Date
Local date.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/freight_kit/models/date_time.rb', line 19 class DateTime < Model attr_accessor :local_date, :local_date_time, :location, :date_time_with_zone def initialize(*) super attempt_upgrade_using_location(location) if location.present? end private def attempt_upgrade_using_location(location) return if @date_time_with_zone.present? || @local_date_time.blank? || location.time_zone.blank? @date_time_with_zone = location.time_zone.parse(@local_date_time) @local_date_time = nil end end |
#local_date_time ⇒ String
Local date and time in the format ‘“YYYY-MM-DD HH:MM:SS”` (zero-padded 24 hour clock) aka `DateTime#to_fs(:db)` format.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/freight_kit/models/date_time.rb', line 19 class DateTime < Model attr_accessor :local_date, :local_date_time, :location, :date_time_with_zone def initialize(*) super attempt_upgrade_using_location(location) if location.present? end private def attempt_upgrade_using_location(location) return if @date_time_with_zone.present? || @local_date_time.blank? || location.time_zone.blank? @date_time_with_zone = location.time_zone.parse(@local_date_time) @local_date_time = nil end end |
#location ⇒ Object
Returns the value of attribute location.
20 21 22 |
# File 'lib/freight_kit/models/date_time.rb', line 20 def location @location end |