Class: OData::Properties::DateTime

Inherits:
OData::Property show all
Defined in:
lib/odata/properties/date_time.rb

Overview

Defines the DateTime OData type.

Instance Attribute Summary

Attributes inherited from OData::Property

#name

Instance Method Summary collapse

Methods inherited from OData::Property

#==, #allows_nil?, #concurrency_mode, #initialize, #to_xml, #xml_value

Constructor Details

This class inherits a constructor from OData::Property

Instance Method Details

#typeObject

The OData type name



27
28
29
# File 'lib/odata/properties/date_time.rb', line 27

def type
  'Edm.DateTime'
end

#url_valueString

Value to be used in URLs.

Returns:



33
34
35
# File 'lib/odata/properties/date_time.rb', line 33

def url_value
  "datetime'#{value}'"
end

#valueDateTime?

Returns the property value, properly typecast

Returns:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/odata/properties/date_time.rb', line 7

def value
  if (@value.nil? || @value.empty?) && allows_nil?
    nil
  else
    begin
      ::DateTime.strptime(@value, '%Y-%m-%dT%H:%M:%S.%L')
    rescue ArgumentError
      ::DateTime.parse(@value)
    end
  end
end

#value=(new_value) ⇒ Object

Sets the property value



21
22
23
24
# File 'lib/odata/properties/date_time.rb', line 21

def value=(new_value)
  validate(new_value)
  @value = parse_value(new_value)
end