Class: Wukong::Elasticsearch::Timestamp

Inherits:
Time
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.receive(string) ⇒ Timestamp

Parses the given string into a Timestamp instance.

Parameters:

  • string (String)

Returns:



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.

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (String)


38
39
40
# File 'lib/wonderdog/timestamp.rb', line 38

def to_wire(options={})
  utc.iso8601
end