Skip to content

Commit

Permalink
Don't apply DST offset in parseISO when parsing date, fixes #1449
Browse files Browse the repository at this point in the history
  • Loading branch information
kalekseev committed Sep 26, 2019
1 parent 812c340 commit 4b3caed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/test/dst.sh
Expand Up @@ -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
6 changes: 5 additions & 1 deletion src/parseISO/index.js
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions 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)

0 comments on commit 4b3caed

Please sign in to comment.