isDate doesn't parse correctly

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

"2008-01-09T00:00:00.000+01:00"

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

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

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

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());
            }
        default:
            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