Date obj and webix.ajax().stringify

Hello!
I’m new in Webix and today I try make http request with webix.ajax.
When I try to pass an Date object to webix.ajax.get('url', {date: new Date()}), my date param in request looks like using i18 preference.

Compare:

"{"date":"2017-06-05 12:56"}"```

```JSON.stringify({date: new Date()})
"{"date":"2017-06-05T09:59:11.010Z"}"

The second format with JSON.stringify is valid for most backend servers. What the reason using i18 preference for webix.ajax().stringify data?

Hello!

In short, as Webix Date parser does not process timezones at all, the best solution here is to modify the stringify method in the webix.ajax module to achieve the needed behaviour: http://webix.com/snippet/52ac168f

This method is used in the library only when issuing server requests, so such a global change will not affect other cases.


How it works by default:

Dates are converted according to the current parseFormatStr which depends on the current locale (parseFormat variable). You can change it manually with the following code:

webix.i18n.parseFormat = "%c.%S";  // setting new format
webix.i18n.setLocale("en-US");     // re-applying current locale

For example, webix.i18n.parseFormatStr(new Date)
will return here 2017-06-06T19:18:20.87

Date formats in server requests should be separate from the current locale, because these serve very different functions:

  • server requests are for machine-to-machine communication, which almost always follow the ISO8601 format for dates
  • locales are for humans and can have a wide variety of representation that are incompatible with API endpoints.

Another example of how using the locale format for server requests doesn’t work is with GraphQL.

Please fix, because I’ve wasted half an hour trying to figure out where along the stack the dates were mangled, and other shouldn’t waste this time too. If you’d like to preserve backwards (in)compatibility, then please document this non-standard behavior in the AJAX and GraphQL docs.

For now, default date formatting corresponds to MySQL format and doesn’t store the time zone. This logic is used widely in Webix and we do not plan to change it, but the corresponding information will be added to the docs, thank you.

As an option, instead of modifying ajax().stringify() method, it is also possible to set the date format as

webix.i18n.parseFormatStr = a => a.toISOString();  // or any date formatting

@Listopad

After migrating from 5.4 to 6.0.3 Date objects are not being parsed/stringified in ajax calls

Hello,

The functionality is restored in Webix 6.0.4, thank you for reporting.