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.
Once this is done, OB SET and OB Get work without requiring the is date constant.
OB SET ($myObject;"myDate";$date)
$date:=OB Get ($myObject;"myDate")
Object Notation also works! Take a look:
$myObject.myDate:=$date
$date:=$myObject.myDate
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.
What’s new?
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.
Reminder: SET DATABASE PARAMETER(Dates inside object;option) is local to the current process.
The three possible values for this option are now:
- String type without time zone (previously known as ignore local time zone)
- String type with time zone (previously known as take time zone into account)
- Date type (new!)
As a result, when you import JSON data into 4D, you now have a way to dynamically change the format for dates.