#1 2014-03-31 06:59:30

mingda
Member
Registered: 2013-01-04
Posts: 121

Javascript DateTime

I'm assess using Ewb as a front-end web development tool, since it's dataset json format a date/time column request a integer value, [http://www.elevatesoft.com/manual?actio … _Reference],

for it's 'rows' prefix, I think can manual add it to the responseText, but for date/time column, since it use Javascript Date Object,  "Specify any valid integer value (positive or negative) for non-null values. If not null, the incoming value represents the number of milliseconds since midnight on January 1, 1970, and can be negative for time values", but in mORMot, we have TDateTime(a UTC string), TCreateTime/TModTime(a property int64), when use REST interface, such as root/test/1 or root/test?select=*&where=XX, where can we do this conversion is appropriate, any suggest is greatly appreciated!

Offline

#2 2014-03-31 07:26:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Javascript DateTime

For this purpose, you have UnixMSTimeToDateTime/DateTimeToUnixMSTime() functions in SynCommons.pas.
Those expect milliseconds values.
Take a look at UnixTimeToDateTime/DateTimeToUnixTime() for seconds values.

I've also just added TTimeLogBits.FromUnixTime/FromUnixMSTime/ToUnixTime/ToUnixMSTime methods.
See http://synopse.info/fossil/info/58d6fdcc44

Offline

#3 2014-03-31 09:02:31

mingda
Member
Registered: 2013-01-04
Posts: 121

Re: Javascript DateTime

I still have a question about the JSON generate in mORMot, I prefer use the default REST API, use root/test/1, we can auto quick get the response, where can I hook to transform the date/time value to this milliseconds values, thank you ab!

Later I think, if there has some uniform control how the date store(txt, TimeLogBits, UnixTime), how the date transfer(txt, TimeLogBits, UnixTime), only make TDateTime, TCreateTime, TModTime different at ORM level(the Middle tier), then will ideal.

Last edited by mingda (2014-03-31 10:26:36)

Offline

#4 2014-04-07 09:02:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Javascript DateTime

You can not directly hook the transformation with the default ORM implementation.

One principle of mORMot's ORM is that it returns directly the JSON from the database engine.
It is one of the reasons why it is so fast and efficient.

In order to return the TDateTime directly, or UnixTime, you will have to define a custom method-based service, which will map directly the default REST API, i.e. root/test/1, and:
- Either to change the SQL executed and add a custom SQlite3 conversion function;
- Or retrieve the class instance, then do the conversion before sending back the result to the client.
For all this, you have every information you need in the SAD pdf: see mainly method-based services.

Offline

#5 2014-04-08 00:28:45

mingda
Member
Registered: 2013-01-04
Posts: 121

Re: Javascript DateTime

thank your reply ab, I now convert the value in front, I prefer use the default backend, this is so fast, thank you!

Offline

Board footer

Powered by FluxBB