Skip to content

ISO DateTime parsing returning wrong Date value #9941

@jclx

Description

@jclx

In recent release it looks like Date-FNS package was removed and TypeOrm is doing it's own parsing but the calculation for calculation is problematic.
In src/util/DateUtils.ts this method was added to replace date-fns.parseISO

 private static parseDateAsISO(dateString: string): Date {
        const date = new Date(dateString)
        const offset = date.getTimezoneOffset() * 60 * 1000
        const utc = date.getTime() + offset

        return new Date(utc)
    }

However the above code returns the datetime with wrong values.
Example:
Given this string: '2023-04-11T16:56:57.572Z'
The above function returns: '2023-04-11T23:56:57.572Z' depending on what timezone your environment is configured for, this example it is -07:00.
Where as date-fns.parseISO() returns: '2023-04-11T16:56:57.572Z' which seems correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions