Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset for Eastern Hemisphere in parseISO, fixes #1449, fixes #1119 #1450

Merged
merged 1 commit into from Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
10 changes: 7 additions & 3 deletions src/parseISO/index.js
Expand Up @@ -137,10 +137,14 @@ export default function parseISO(argument, dirtyOptions) {
offset = getTimezoneOffsetInMilliseconds(fullTimeDate)

// Adjust time when it's coming from DST
var fullTimeDateNextDay = new Date(fullTime)
fullTimeDateNextDay.setDate(fullTimeDate.getDate() + 1)
var fullTimeDateDiffDay = new Date(fullTime)
if (offset > 0) {
fullTimeDateDiffDay.setDate(fullTimeDate.getDate() + 1)
} else {
fullTimeDateDiffDay.setDate(fullTimeDate.getDate() - 1)
}
var offsetDiff =
getTimezoneOffsetInMilliseconds(fullTimeDateNextDay) - offset
getTimezoneOffsetInMilliseconds(fullTimeDateDiffDay) - offset
if (offsetDiff > 0) {
offset += offsetDiff
}
Expand Down
34 changes: 34 additions & 0 deletions test/dst/parseISO/sydney.js
@@ -0,0 +1,34 @@
// 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')

// Test DST start edge
assert.equal(parseISO('2019-10-06').getDate(), 6) // DST start
assert.equal(parseISO('2019-10-07').getDate(), 7)
assert.equal(
parseISO('2019-10-06T01:00:00').toString(),
'Sun Oct 06 2019 01:00:00 GMT+1000 (Australian Eastern Standard Time)'
)
assert.equal(
parseISO('2019-10-06T02:00:00').toString(),
'Sun Oct 06 2019 03:00:00 GMT+1100 (Australian Eastern Daylight Time)'
)

// Test DST end edge
assert.equal(parseISO('2019-04-06').getDate(), 6)
assert.equal(parseISO('2019-04-07').getDate(), 7) // DST end
assert.equal(
parseISO('2019-04-06T11:00:00').toString(),
'Sat Apr 06 2019 11:00:00 GMT+1100 (Australian Eastern Daylight Time)'
)
assert.equal(
parseISO('2019-04-07T11:00:00').toString(),
'Sun Apr 07 2019 11:00:00 GMT+1000 (Australian Eastern Standard Time)'
)