Skip to content

Standart Time to Daylight Saving Time Tests Result Unexpected #74

@n-ae

Description

@n-ae

I'm trying to test my function:

import { tzDate } from '@formkit/tempo'

export function convertToUTCISO(localTimestamp: string): string {
    const timezone = 'Europe/Berlin'
    const timestamp = tzDate(localTimestamp, timezone)
    const formattedTimestamp = timestamp.toISOString()

    return formattedTimestamp
}

with:

describe('convertToUTCISO', () => {
    it.each([
        ['2024-03-31T03:01', '2024-03-31T01:01:00.000Z'], // invalid, result: 2024-03-31T02:01:00.000Z
        ['2024-03-31T03:59', '2024-03-31T01:59:00.000Z'], // invalid, result: 2024-03-31T02:59:00.000Z

        ['2024-03-31T04:00', '2024-03-31T02:00:00.000Z'], // valid
        ['2024-03-31T04:01', '2024-03-31T02:01:00.000Z'], // valid
    ])('should get the correct value for given input %s: [%s]', (value: string, expected: string) => {
        // Act
        const result = convertToUTCISO(value)
        // Assert
        expect(result).toBe(expected)
    })
})

However the first couple of value & expected pairs of it won't work. To me it acts as if the ST -> DST happens on 4 AM local time as opposed to 3 AM. What's my mistake?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions