diff --git a/scripts/test/regression.sh b/scripts/test/regression.sh new file mode 100755 index 0000000000..182f92f5db --- /dev/null +++ b/scripts/test/regression.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# The script runs the regression tests. +# +# It's a part of the test process. + +set -ex + +export PATH="$(yarn bin):$PATH" + +env TZ=America/Sao_Paulo babel-node ./test/regression/972.js \ No newline at end of file diff --git a/src/toDate/index.js b/src/toDate/index.js index 06a443e8ec..512ae86f88 100644 --- a/src/toDate/index.js +++ b/src/toDate/index.js @@ -188,9 +188,6 @@ export default function toDate(argument, dirtyOptions) { } else { // get offset accurate to hour in timezones that change offset offset = getTimezoneOffsetInMilliseconds(new Date(timestamp + time)) - offset = getTimezoneOffsetInMilliseconds( - new Date(timestamp + time + offset) - ) } return new Date(timestamp + time + offset) diff --git a/test/regression/972.js b/test/regression/972.js new file mode 100644 index 0000000000..9473097e6d --- /dev/null +++ b/test/regression/972.js @@ -0,0 +1,14 @@ +// This is a regression test for issue #972: https://github.com/date-fns/date-fns/issues/972 + +import format from '../../src/format' +import assert from 'assert' + +if (process.env.TZ !== 'America/Sao_Paulo') + throw new Error('The test must be run with TZ=America/Sao_Paulo') + +const result = format('2018-11-04', 'yyyy-MM-dd HH:mm') +const expectation = '2018-11-04 01:00' +assert( + result === expectation, + `The result should be equal ${expectation} but got ${result}` +)