Class: Wukong::Elasticsearch::Timestamp
- Inherits:
-
Time
- Object
- Time
- Wukong::Elasticsearch::Timestamp
- Defined in:
- lib/wonderdog/timestamp.rb
Overview
A class that makes Ruby's Time class serialize the way Elasticsearch expects.
Elasticsearch's date parsing engine expects to receive a date formatted according to the Java library Joda's ISODateTimeFormat.dateOptionalTimeParser class.
This format looks like this: 2012-11-30T01:15:23
.
Class Method Summary collapse
-
.receive(string) ⇒ Timestamp
Parses the given
string
into a Timestamp instance.
Instance Method Summary collapse
-
#to_wire(options = {}) ⇒ String
Formats the Timestamp according to ISO 8601 rules.
Class Method Details
.receive(string) ⇒ Timestamp
Parses the given string
into a Timestamp instance.
24 25 26 27 28 29 30 31 32 |
# File 'lib/wonderdog/timestamp.rb', line 24 def self.receive string return if string.nil? || string.empty? begin t = Time.parse(string) rescue ArgumentError => e return end new(t.year, t.month, t.day, t.hour, t.min, t.sec, t.utc_offset) end |
Instance Method Details
#to_wire(options = {}) ⇒ String
Formats the Timestamp according to ISO 8601 rules.
38 39 40 |
# File 'lib/wonderdog/timestamp.rb', line 38 def to_wire(={}) utc.iso8601 end |