Class: FreightKit::DateTime

Inherits:
Model
  • Object
show all
Defined in:
lib/freight_kit/models/date_time.rb

Overview

Represent dates and times in varous formats.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#attributes

Constructor Details

#initializeDateTime

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_zoneActiveSupport::TimeWithZone

Date and time with time zone.

Returns:

  • (ActiveSupport::TimeWithZone)


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_dateDate

Local date.

Returns:

  • (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_timeString

Local date and time in the format ‘“YYYY-MM-DD HH:MM:SS”` (zero-padded 24 hour clock) aka `DateTime#to_fs(:db)` format.

Returns:

  • (String)


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

#locationObject

Returns the value of attribute location.



20
21
22
# File 'lib/freight_kit/models/date_time.rb', line 20

def location
  @location
end