diff --git a/scripts/test/dst.sh b/scripts/test/dst.sh index e75446bde7..dbdcd8201e 100755 --- a/scripts/test/dst.sh +++ b/scripts/test/dst.sh @@ -10,6 +10,7 @@ export PATH="$(yarn bin):$PATH" export NODE_ENV=test env TZ=America/Sao_Paulo babel-node ./test/dst/parseISO/basic.js +env TZ=Australia/Sydney babel-node ./test/dst/parseISO/sydney.js env TZ=Pacific/Apia babel-node ./test/dst/parseISO/samoa.js env TZ=Asia/Damascus babel-node ./test/dst/eachDayOfInterval/basic.js env TZ=America/Santiago babel-node ./test/dst/addBusinessDays/basic.js diff --git a/src/parseISO/index.js b/src/parseISO/index.js index 4dc11edafa..cf9a6421bd 100644 --- a/src/parseISO/index.js +++ b/src/parseISO/index.js @@ -138,7 +138,11 @@ export default function parseISO(argument, dirtyOptions) { // Adjust time when it's coming from DST var fullTimeDateNextDay = new Date(fullTime) - fullTimeDateNextDay.setDate(fullTimeDate.getDate() + 1) + if (offset > 0) { + fullTimeDateNextDay.setDate(fullTimeDate.getDate() + 1) + } else { + fullTimeDateNextDay.setDate(fullTimeDate.getDate() - 1) + } var offsetDiff = getTimezoneOffsetInMilliseconds(fullTimeDateNextDay) - offset if (offsetDiff > 0) { diff --git a/test/dst/parseISO/sydney.js b/test/dst/parseISO/sydney.js new file mode 100644 index 0000000000..d5be2faad2 --- /dev/null +++ b/test/dst/parseISO/sydney.js @@ -0,0 +1,12 @@ +// This is basic DST test for parseISO + +import parseISO from '../../../src/parseISO' +import assert from 'assert' + +if (process.env.TZ !== 'Australia/Sydney') + throw new Error('The test must be run with TZ=Australia/Sydney') + +if (parseInt(process.version.match(/^v(\d+)\./)[1]) < 10) + throw new Error('The test must be run on Node.js version >= 10') + +assert.equal(parseISO('2019-10-06').getDate(), 6)