Skip to content

toDate returns unexpected date in America/Sao_Paolo timezone. #992

Closed
@inytar

Description

@inytar

On daylight switching (2018-11-04) in Sao Paolo Brazil the toDate function returns a different date object then expected:

const toDate = require('date-fns/toDate');
const getDay = require('date-fns/getDay');

const nativeSunday = new Date(2018, 10, 4)
console.log(nativeSunday)
// 2018-11-04T03:00:00.000Z
console.log(getDay(nativeSunday))
// 0
const dateFnsSunday = toDate('2018-11-04')
console.log(dateFnsSunday)
// 2018-11-04T02:00:00.000Z
console.log(getDay(dateFnsSunday))
// 6

This problem only manifests itself if running in the Sao Paolo timezone. This can be tested by running:

env TZ='America/Sao_Paolo' node testScript.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions