Format of Json value

Posted by OctavioOlguin on 24-Oct-2015 10:56

Greetings.

I have the following code.

   DEFINE INPUT PARAMETER dateCashOut AS CHARACTER NO-UNDO.
    DEFINE OUTPUT PARAMETER jsonText AS LONGCHAR NO-UNDO.
  
    DEFINE VARIABLE jsonArray AS Progress.Json.ObjectModel.JsonArray NO-UNDO.
    
    EMPTY TEMP-TABLE ttdwCorteDeCaja.
    FOR EACH dwCorteDeCaja WHERE dwCorteDeCaja.Fecha = DATE(dateCashOut).
            CREATE ttdwCorteDeCaja.
            BUFFER-COPY dwCorteDeCaja TO ttdwCorteDeCaja.
    END.
    FIND FIRST  ttdwCorteDeCaja NO-ERROR.
    IF AVAILABLE(ttdwCorteDeCaja) THEN 
    DO:
        jsonArray = NEW Progress.Json.ObjectModel.JsonArray(). 
        jsonArray:Read(TEMP-TABLE ttdwCorteDeCaja:HANDLE).
        jsonText = jsonArray:GetJsonObject(1):GetJsonText().
    END.

And receive the data in no suitable format.

I would like to get date (one of the fields in dwCorteDeCaja)  in "dd/mm/yyyy" or "dd-mm-yyyyy" format, the separators are not the problem, Now, json field gets it formatted as "yyyy-mm-yy" when marshalling temp-table.

Is there a way to instruct Progress.Json.ObjectModel.JsonArray  to format that date field the other way (dd-mm-yyyy)?

Posted by Peter Judge on 24-Oct-2015 22:58

Dates aren't described by the JSON spec at json.org, so the ABL uses ISO dates.
If you want to have date information formatted 'your way' then do the formatting yourself and set/add as a character value.
 

All Replies

Posted by Peter Judge on 24-Oct-2015 22:58

Dates aren't described by the JSON spec at json.org, so the ABL uses ISO dates.
If you want to have date information formatted 'your way' then do the formatting yourself and set/add as a character value.
 

Posted by OctavioOlguin on 26-Oct-2015 14:26

Thanks Peter.  Done as you told....

BUT... this brought to my attention something that makes me wonder.

I have never realized before how I defined the date format for use on my system.  And now, making test with appserver -> angular, I found that never used the SESSION:DATE-FORMAT nor -d parameters, and yet, all my users found natural the "dmy" format that system used and showed on screen.  The only time they were defined was on database creation and client-networking instalation...

So I'm curious, where did AVL takes date format for using on UI at runtime?  As it has been allways "correct" .

Is it integrated or defaulted on installation?  It's taken from windows localisation?

It's interesting, 20 years later after my first FOR EACH CLIENTE: ...

Posted by Peter Judge on 27-Oct-2015 08:33

There are a couple of settings to look at, most are startup params and settable attributes on the SESSION handle.
DATE-FORMAT
TIME-SOURCE
YEAR-OFFSET
 
Once you have a date you can format it via the STRING(<date-value>, "<format-string>")  function, the ISO-DATE function or you can roll your own per the below snippet, which creates a format of 2015-10-26 .
                        when 'date' then
                            mhSaxWriter:write-characters(substitute('&1-&2-&3',
                                    string(year(hField:buffer-value), '9999'),
                                    string(month(hField:buffer-value), '99'),
                                    string(day(hField:buffer-value), '99'))).
 
If you use the built-in XML serializer it follows the XML spec, and if you use the JSON serializer, it uses ISO-DATE (as you discovered).
 
There are also NUMERIC-FORMAT and NUMERIC-DECIMAL-POINT attributes for working with numbers.
 
 

Posted by jamesmc on 27-Oct-2015 10:15

In your OpenEdge installation folder you will find a startup.pf file which contains default client startup parameters.  Date and number formats are a couple of the things that are defined in this file.  Parameters in this file are processed every time you start a client so they dont have to be specified each time but can be changed if you specify your own on the command line when starting up a client.

This thread is closed