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 Method Details

#cast(string) ⇒ Object

:nodoc:



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

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

#indexed_name(name) ⇒ Object

:nodoc:



203
204
205
# File 'lib/sunspot/type.rb', line 203

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

#to_indexed(value) ⇒ Object

:nodoc:



207
208
209
210
211
# File 'lib/sunspot/type.rb', line 207

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

#to_literal(value) ⇒ Object



213
214
215
# File 'lib/sunspot/type.rb', line 213

def to_literal(value)
  to_indexed(value)
end