Skip to content

Selection of date types with undefined values #219

@murphy85

Description

@murphy85

It is not possible to select values with type date, if the value is undefined.

On selection the mutateRowTypes function is called. In this function columns with type date will be converter to ISOString on selection: new Date(useObj[m.key]).toISOString();

If useObj[m.key] returns undefined, an error is thrown: RangeError: Invalid Date

See:

useObj[m.key] = new Date(useObj[m.key]).toISOString();

Is there a reason why an ISODate is returned instead of Date type? I think there should be a conversion to ISODate on insert and a conversion to Date on select.

If I'm wrong, please insert an undefined check before using new Date()

Meanwhile I will try to use a "custom type" handling

            types: {
                "date": {
                    onInsert: (colValue) => colValue ? new Date(colValue).toISOString() : undefined,
                    onSelect: (colValue) => colValue ? new Date(colValue) : undefined
                }
            }

(Btw: The interface describes onInsert and onSelect, but I cannot find any use of onInsert?)

Im using nanosql with IndexedDB
"@nano-sql/core": "^2.3.7",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions