class FrOData::Properties::DateTime
Public Instance Methods
json_value()
click to toggle source
Value to be used in JSON. @return [String]
# File lib/frodata/properties/date_time.rb, line 39 def json_value xml_value end
type()
click to toggle source
The FrOData
type name
# File lib/frodata/properties/date_time.rb, line 27 def type 'Edm.DateTime' end
url_value()
click to toggle source
Value to be used in URLs. @return [String]
# File lib/frodata/properties/date_time.rb, line 45 def url_value xml_value end
value()
click to toggle source
Returns the property value, properly typecast @return [DateTime, nil]
# File lib/frodata/properties/date_time.rb, line 7 def value if (@value.nil? || @value.empty?) && allows_nil? nil else begin date_class.strptime(@value, strptime_format) rescue ArgumentError date_class.parse(@value) end end end
value=(new_value)
click to toggle source
Sets the property value @params new_value [DateTime]
# File lib/frodata/properties/date_time.rb, line 21 def value=(new_value) validate(new_value) @value = parse_value(new_value) end
xml_value()
click to toggle source
Value to be used in JSON. @return [String]
# File lib/frodata/properties/date_time.rb, line 33 def xml_value @value.andand.sub(/[\+\-]00:00$/, 'Z') end
Protected Instance Methods
date_class()
click to toggle source
Specifies date/time implementation to use
# File lib/frodata/properties/date_time.rb, line 52 def date_class ::DateTime end
parse_value(value)
click to toggle source
# File lib/frodata/properties/date_time.rb, line 72 def parse_value(value) return value if value.nil? && allows_nil? if value.is_a?(date_class) parsed_value = value else parsed_value = date_class.parse(value) end parsed_value.strftime(strptime_format) end
strptime_format()
click to toggle source
Specifies the date/time format string used for `strptime`
# File lib/frodata/properties/date_time.rb, line 57 def strptime_format #'%Y-%m-%dT%H:%M:%S.%L' "%Y-%m-%dT%H:%M:%SZ" end
validate(value)
click to toggle source
# File lib/frodata/properties/date_time.rb, line 62 def validate(value) begin return if value.nil? && allows_nil? return if value.is_a?(date_class) date_class.parse(value) rescue validation_error "Value '#{value}' is not a date time format that can be parsed" end end