class Elastic::Datatypes::Date

Public Instance Methods

date_histogram_aggregation_defaults() click to toggle source
# File lib/elastic/datatypes/date.rb, line 28
def date_histogram_aggregation_defaults
  { interval: '1w', time_zone: time_zone }
end
prepare_for_index(_value) click to toggle source
# File lib/elastic/datatypes/date.rb, line 3
def prepare_for_index(_value)
  if !_value.nil? && !_value.is_a?(::Date)
    raise ArgumentError, "expected a date for field #{name}"
  end

  # date is stored as the corresponding utc timestamp in elastic search,
  # no need to convert it here
  _value
end
prepare_value_for_result(_value) click to toggle source
# File lib/elastic/datatypes/date.rb, line 13
def prepare_value_for_result(_value)
  case _value
  when ::String
    time_zone.parse(_value).to_date
  when ::Integer
    time_zone.at(_value / 1000).to_date
  else
    _value
  end
end
supported_aggregations() click to toggle source
Calls superclass method
# File lib/elastic/datatypes/date.rb, line 24
def supported_aggregations
  [:date_histogram] + super
end

Private Instance Methods

time_zone() click to toggle source
# File lib/elastic/datatypes/date.rb, line 34
def time_zone
  @time_zone ||= ActiveSupport::TimeZone.new('UTC') # dates are always UTC
end