Class: Sunspot::Type::TimeType

Inherits:
AbstractType show all
Defined in:
lib/sunspot/type.rb

Overview

The time type represents times. Note that times are always converted to UTC before indexing, and facets of Time fields always return times in UTC.

Direct Known Subclasses

DateType, TrieTimeType

Constant Summary collapse

XMLSCHEMA =
"%Y-%m-%dT%H:%M:%SZ"

Instance Method Summary collapse

Methods inherited from AbstractType

#accepts_dynamic?, #accepts_more_like_this?, instance

Instance Method Details

#cast(string) ⇒ Object

:nodoc:



215
216
217
218
219
220
221
# File 'lib/sunspot/type.rb', line 215

def cast(string) #:nodoc:
  begin
    Time.xmlschema(string)
  rescue ArgumentError
    DateTime.strptime(string, XMLSCHEMA)
  end
end

#indexed_name(name) ⇒ Object

:nodoc:



201
202
203
# File 'lib/sunspot/type.rb', line 201

def indexed_name(name) #:nodoc:
  "#{name}_d"
end

#to_indexed(value) ⇒ Object

:nodoc:



205
206
207
208
209
# File 'lib/sunspot/type.rb', line 205

def to_indexed(value) #:nodoc:
  if value
    value_to_utc_time(value).strftime(XMLSCHEMA)
  end
end

#to_literal(value) ⇒ Object



211
212
213
# File 'lib/sunspot/type.rb', line 211

def to_literal(value)
  to_indexed(value)
end