Objects are great! Their flexibility, combined with speed and elegance, make them a first choice for most developers. Using dates inside objects is now easier and more intuitive. From now on, dates can be set as dates – and not strings inside objects!
How does it work?
In order to use dates inside objects, just check the compatibility setting, “Use date type instead of ISO date format in objects”, in the Database Settings.
OB SET ($myObject;"myDate";$date)
$date:=OB Get ($myObject;"myDate")
Object Notation also works! Take a look:
Stringify and Parse
Compatibility is maintained
Prior to 4D v16 R6, when calling the JSON Stringify command, objects containing dates were systematically “stringified” according to the ISO 8601 normalization in the following format “YYYY-MM-DDThhmmss.sssZ” . The reverse operation, JSON Parse, did not interpret this format by default, and therefore produced a string.
If the compatibility option in the Database Settings is checked, dates will simply be formatted as “YYYY-MM-DD” (still following the ISO 8601 standard) when calling the JSON stringify command. When using JSON Parse, this string will then be set as a date (and not as a string) inside the object!
Change mode dynamically
If needed, this default setting can be changed by programming with the SET DATABASE PARAMETER command and the Dates inside object selector.
As a result, when you import JSON data into 4D, you now have a way to dynamically change the format for dates.