class XapianDb::TypeCodec::DateTimeCodec

Public Class Methods

decode(datetime_as_string) click to toggle source

Decode a string to a datetime @param [String] datetime_as_string a string representing a datetime @return [DateTime] the parsed datetime

    # File lib/type_codec.rb
132 def self.decode(datetime_as_string)
133   return nil if datetime_as_string.nil? || datetime_as_string.strip == ""
134   begin
135     DateTime.parse datetime_as_string
136   rescue ArgumentError
137     raise ArgumentError.new "'#{datetime_as_string}' cannot be converted to a datetime"
138   end
139 end
encode(datetime) click to toggle source

Encode a datetime to a string in the format ‘yyyymmdd h:m:s+l’ @param [DateTime] datetime a datetime object to encode @return [String] the encoded datetime

    # File lib/type_codec.rb
120 def self.encode(datetime)
121   return nil unless datetime
122   begin
123     datetime.strftime "%Y%m%d %H:%M:%S+%L"
124   rescue NoMethodError
125     raise ArgumentError.new "#{datetime} was expected to be a datetime"
126   end
127 end