XML Serialization is not including milliseconds in datetime field from Rails model
- by revgum
By default, the datetime field from the database is being converted and stripping off the milliseconds:
some_datetime = "2009-11-11T02:19:36Z"
attribute_before_type_cast('some_datetime') = "2009-11-11 02:19:36.145"
If I try to overrride the accessor for this attribute like;
def some_datetime
attribute_before_type_cast('some_datetime')
end
when I try "to_xml" for that model, I get the following error:
NoMethodError (undefined method
`xmlschema' for "2009-11-11
02:19:36.145":String):
I have tried to parse the String to a Time object but can't get one to include the milliseconds;
def some_datetime
Time.parse(attribute_before_type_cast('some_datetime').sub(/\s/,"T").sub(/$/,"Z"))
end
Can anyone help get get a datetime with milliseconds rendered by to_xml?