Class: Sunspot::Type::TimeType

Inherits:
AbstractType show all
Defined in:
sunspot/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

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

Instance Method Summary (collapse)

Methods inherited from AbstractType

#accepts_dynamic?, #accepts_more_like_this?

Instance Method Details

- (Object) cast(string)

:nodoc:



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

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

- (Object) indexed_name(name)

:nodoc:



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

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

- (Object) to_indexed(value)

:nodoc:



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

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

- (Object) to_literal(value)



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

def to_literal(value)
  to_indexed(value)
end