# DateTimes get converted to Dates in XML-RPC?

**URL:** <https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865>\
**Category:** Rails\
**Created:** [June 20, 2006, 12:29am UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865 "2006-06-20T00:29:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [June 20, 2006, 12:29am UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865/1 "2006-06-20T00:29:33Z")

</div>

Hi all -

I have written an XML-RPC app using action-web-service. Mostly works  
well. Except I just noticed that my :datetime types are coming back as  
:date types.

That is, when in the console I query the record via Foo.find\_by\_id(123)  
I  
get back actual datetimes. If I then do it via XML-RPC, fetching that  
same record I get back dates (ie. hour/minute/second are set to  
00:00:00)

Any ideas? Tried google, and ruby-forum is down and am up against a  
deadline…

My api/model method looks like this:

```
     def find_by_id(id)
             Foo.find(id)
     end

```

thanks!

-philip

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [June 20, 2006, 12:48am UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865/2 "2006-06-20T00:48:20Z")

</div>

> deadline…
> 
> My api/model method looks like this:
> 
> ```
> def find_by_id(id)
> Foo.find(id)
> end
> 
> ```
> 
> thanks!

To followup, Foo.find\_by\_id(123).to\_xml spits back valid :datetimes…  
so  
it doesn’t appear to be some underlying xml thing. Seems it’s _in_  
AWS…

???

-philip

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [June 20, 2006, 11:31am UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865/3 "2006-06-20T11:31:27Z")

</div>

Hi Philip,

Philip H. wrote:

> I have written an XML-RPC app using action-web-service. Mostly works  
> well. Except I just noticed that my :datetime types are coming back as  
> :date types.
> 
> That is, when in the console I query the record via Foo.find\_by\_id(123) I  
> get back actual datetimes. If I then do it via XML-RPC, fetching that  
> same record I get back dates (ie. hour/minute/second are set to 00:00:00)
> 
> Any ideas? Tried google, and ruby-forum is down and am up against a  
> deadline…

I’m not sure I understand your question completely, but I’ll offer a  
couple  
of tidbits just in case one might help…

1. Time is more “reliable” than Date

2. You might take a look at Time.now.xmlschema

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [June 20, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865/4 "2006-06-20T19:00:41Z")

</div>

> I’m not sure I understand your question completely, but I’ll offer a couple  
> of tidbits just in case one might help…
> 
> 1. Time is more “reliable” than Date
> 
> 2. You might take a look at Time.now.xmlschema

That’s the thing… I’m not doing really utilizing any of those. The  
table has a :datetime field (created\_at/updated\_at). With AWS you set  
up  
your service, then simply make the calls to the model to fetch what you  
want and return it “as is”. AWS then converts that into xml-rpc or  
soap.

So, I’m “done” after doing Foo.find\_by\_id(123) and returning that.  
Meaning I’d never have a chance to manipulate the data itself. Putting  
in  
a breakpoint right there shows the data is right. Somewhere in AWS it  
is  
truncating it…

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [June 20, 2006, 11:48pm UTC](https://www.ruby-forum.com/t/datetimes-get-converted-to-dates-in-xml-rpc/63865/5 "2006-06-20T23:48:28Z")

</div>

> > 
> 
> return it “as is”. AWS then converts that into xml-rpc or soap.
> 
> So, I’m “done” after doing Foo.find\_by\_id(123) and returning that. Meaning  
> I’d never have a chance to manipulate the data itself. Putting in a  
> breakpoint right there shows the data is right. Somewhere in AWS it is  
> truncating it…

I spent all morning following the code and arrived at XMLRPC’s create.rb  
conv2value method.

It’s converting paramaters into strings, and even though my param is a  
DateTime it matches Date which then did this:

when Date  
t = param  
@writer.tag(“dateTime.iso8601”,  
format("%.4d%02d%02dT00:00:00", t.year, t.month, t.day))

I changed that to this:

when Date  
@writer.tag(“dateTime.iso8601”, param.strftime("%Y%m%dT%H:%M:%S"))

and it seems to work just as well…

Any gotchas I’m missing?
