isDate doesn't parse correctly

To determine datatypes received via JSON, I'm using isDate. It returns false on perfectly valid data.


The problem seems to be in RTL\js.pas:

function isDate(const v: JSValue): boolean; assembler;
  return (v instanceof Date);

This works only with object instances. Type handling should be used

function isDate(value) {
    switch (typeof value) {
        case 'number':
            return true;
        case 'string':
            return !isNaN(Date.parse(value));
        case 'object':
            if (value instanceof Date) {
                return !isNaN(value.getTime());
            return false;

Since this is a pas2js RTL function, we are discussing this with the pas2js team if this is an acceptable extension and if so, to apply it.

1 Like