please, basic question about rpc-date

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

please, basic question about rpc-date

rsantiagopaz
Hi (sorry the english)

Please, I need some little help about a absurd basic question.
I really really try understand the Qooxdoo 5.0 Date object converter around Rpc use.

For example I use rpc,

var rpc = new qx.io.remote.Rpc("services/", "comp.Prueba");
try {
        var r = rpc.callSync("traerDate");
} catch (ex) {
        alert("Sync exception: " + ex);
}


and from PHP response is like this

return "new Date(Date.UTC(1970,9,3,0,0,0,0))";
or
return "1970-09-03T00:00:00.000Z";

but in javascript var r never get a Date object, only strings.


I read documentation and try, API, old post here, the PHP JSONRPC contrib, qx.io.remote.Rpc.CONVERT_DATES, qx.lang.Json.parse, etc, etc, and I cant figure what is wrong, what I'm doing wrong. Surely I'm wrong understanding about how qooxdoo 5.0 work this.


I'm sorry the bad understanding, i love qooxdoo but my bad english not help with some topics.
I need some little help or some little example online, some tip.
Thank you in advance
Reply | Threaded
Open this post in threaded view
|

Re: please, basic question about rpc-date

fritz
I believe the problem is that there is no standard way for json-encoding a
date. In my applications I explicitly convert date strings received from the
server into a JS date object:

   var dateJS = new Date(dateStrFromServer);

Cheers,
Fritz

P.S.: You really shouldn't use rpc.callSync() as it blocks the browser, but
       use rpc.callAsync() with appropriate callbacks.

On Tue, 4 Aug 2015, rsantiagopaz wrote:

> Hi (sorry the english)
>
> Please, I need some little help about a absurd basic question.
> I really really try understand the Qooxdoo 5.0 Date object converter around
> Rpc use.
>
> For example I use rpc,
>
> var rpc = new qx.io.remote.Rpc("services/", "comp.Prueba");
> try {
> var r = rpc.callSync("traerDate");
> } catch (ex) {
> alert("Sync exception: " + ex);
> }
>
>
> and from PHP response is like this
>
> return "new Date(Date.UTC(1970,9,3,0,0,0,0))";
> or
> return "1970-09-03T00:00:00.000Z";
>
> but in javascript var r never get a Date object, only strings.
>
>
> I read documentation and try, API, old post here, the PHP JSONRPC contrib,
> qx.io.remote.Rpc.CONVERT_DATES, qx.lang.Json.parse, etc, etc, and I cant
> figure what is wrong, what I'm doing wrong. Surely I'm wrong understanding
> about how qooxdoo 5.0 work this.
>
>
> I'm sorry the bad understanding, i love qooxdoo but my bad english not help
> with some topics.
> I need some little help or some little example online, some tip.
> Thank you in advance
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/please-basic-question-about-rpc-date-tp7587409.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
Oetiker+Partner AG              tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: please, basic question about rpc-date

Petr Kobalíček
I would recommend to not use date object at all in your code, just use string and convert to date when you really need to manipulate it. I found this approach to be much safer. For date manipulation I use moment.

On Wed, Aug 5, 2015 at 8:00 AM, Fritz Zaucker <[hidden email]> wrote:
I believe the problem is that there is no standard way for json-encoding a
date. In my applications I explicitly convert date strings received from the
server into a JS date object:

   var dateJS = new Date(dateStrFromServer);

Cheers,
Fritz

P.S.: You really shouldn't use rpc.callSync() as it blocks the browser, but
       use rpc.callAsync() with appropriate callbacks.

On Tue, 4 Aug 2015, rsantiagopaz wrote:

> Hi (sorry the english)
>
> Please, I need some little help about a absurd basic question.
> I really really try understand the Qooxdoo 5.0 Date object converter around
> Rpc use.
>
> For example I use rpc,
>
> var rpc = new qx.io.remote.Rpc("services/", "comp.Prueba");
> try {
>       var r = rpc.callSync("traerDate");
> } catch (ex) {
>       alert("Sync exception: " + ex);
> }
>
>
> and from PHP response is like this
>
> return "new Date(Date.UTC(1970,9,3,0,0,0,0))";
> or
> return "1970-09-03T00:00:00.000Z";
>
> but in javascript var r never get a Date object, only strings.
>
>
> I read documentation and try, API, old post here, the PHP JSONRPC contrib,
> qx.io.remote.Rpc.CONVERT_DATES, qx.lang.Json.parse, etc, etc, and I cant
> figure what is wrong, what I'm doing wrong. Surely I'm wrong understanding
> about how qooxdoo 5.0 work this.
>
>
> I'm sorry the bad understanding, i love qooxdoo but my bad english not help
> with some topics.
> I need some little help or some little example online, some tip.
> Thank you in advance
>
>
>
> --
> View this message in context: http://qooxdoo.678.n2.nabble.com/please-basic-question-about-rpc-date-tp7587409.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
Oetiker+Partner AG              tel: <a href="tel:%2B41%2062%20775%209903" value="+41627759903">+41 62 775 9903 (direct)
Fritz Zaucker                        <a href="tel:%2B41%2062%20775%209900" value="+41627759900">+41 62 775 9900 (switch board)
Aarweg 15                            <a href="tel:%2B41%2079%20675%200630" value="+41796750630">+41 79 675 0630 (mobile)
CH-4600 Olten                   fax: <a href="tel:%2B41%2062%20775%209905" value="+41627759905">+41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: please, basic question about rpc-date

rsantiagopaz
In reply to this post by fritz
fritz wrote
P.S.: You really shouldn't use rpc.callSync()

of course, is only a ad-hoc example. Thanks for your time Fritz.
Finally I get de Date object.
Some like this send, and receive, all Date objects with the proper convertions:


qx.io.remote.Rpc.CONVERT_DATES = true;
qx.io.remote.Rpc.RESPONSE_JSON = true;
var rpc = new qx.io.remote.Rpc("services/", "comp.Prueba");
try {
    var r = rpc.callSync("traerDate");
} catch (ex) {
    alert("Sync exception: " + ex);
}


and from PHP:

return "new Date(Date.UTC(1970,9,3,0,0,0,0))";


I asume this is the "official standard qoxdoo 5.0 hack" for send/receive Date objects. And works for me.
But if this is not the standard hack or is something wrong or inapropiate tell me what is the correct procedure, please.
thanks
Reply | Threaded
Open this post in threaded view
|

Re: please, basic question about rpc-date

Derrell Lipman
I believe it was a serious oversight in the JavaScript design, carried over to the JSON design, that there is no literal form for a Date object. Every native type in JavaScript other than Date has a literal form.

I was one of the people who worked on that date hack, nearly 10 years ago. It is not JSON-RPC compliant to make any assumptions about the format of a date. As others have said and even though I was a creator of that hack, I no longer endorse that hack, and recommend that dates be passed as strings, in some format that you choose and use consistently, and convert the string to a date at a higher layer of your application.

Derrell


On Wed, Aug 5, 2015 at 3:50 AM rsantiagopaz <[hidden email]> wrote:
fritz wrote
> P.S.: You really shouldn't use rpc.callSync()


of course, is only a ad-hoc example. Thanks for your time Fritz.
Finally I get de Date object.
Some like this send, and receive, all Date objects with the proper
convertions:


qx.io.remote.Rpc.CONVERT_DATES = true;
qx.io.remote.Rpc.RESPONSE_JSON = true;
var rpc = new qx.io.remote.Rpc("services/", "comp.Prueba");
try {
    var r = rpc.callSync("traerDate");
} catch (ex) {
    alert("Sync exception: " + ex);
}


and from PHP:

return "new Date(Date.UTC(1970,9,3,0,0,0,0))";


I asume this is the "official standard qoxdoo 5.0 hack" for send/receive
Date objects. And works for me.
But if this is not the standard hack or is something wrong or inapropiate
tell me what is the correct procedure, please.
thanks



--
View this message in context: http://qooxdoo.678.n2.nabble.com/please-basic-question-about-rpc-date-tp7587409p7587413.html
Sent from the qooxdoo mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel