Skip to content

Commit

Permalink
Fix the DST issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jun 10, 2019
1 parent 5e3e089 commit 03bbf4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/test/dst.sh
Expand Up @@ -11,3 +11,4 @@ export PATH="$(yarn bin):$PATH"
env TZ=America/Sao_Paulo babel-node ./test/dst/parseISO/basic.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
4 changes: 3 additions & 1 deletion src/addBusinessDays/index.js
@@ -1,6 +1,6 @@
import toInteger from '../_lib/toInteger/index.js'
import isWeekend from '../isWeekend/index.js'
import toDate from '../toDate/index.js'
import toInteger from '../_lib/toInteger/index.js'

/**
* @name addBusinessDays
Expand Down Expand Up @@ -32,9 +32,11 @@ export default function addBusinessDays(dirtyDate, dirtyAmount) {

if (isNaN(amount)) return new Date(NaN)

var hours = date.getHours()
var numWeekDays = 0
while (numWeekDays < amount) {
date.setDate(date.getDate() + 1)
date.setHours(hours)
if (!isWeekend(date)) numWeekDays++
}

Expand Down
18 changes: 18 additions & 0 deletions test/dst/addBusinessDays/basic.js
@@ -0,0 +1,18 @@
// This is basic DST test for addBusinessDays

import assert from 'assert'
import addBusinessDays from '../../../src/addBusinessDays'

if (process.env.TZ !== 'America/Santiago')
throw new Error('The test must be run with TZ=America/Santiago')

if (parseInt(process.version.match(/^v(\d+)\./)[1]) < 10)
throw new Error('The test must be run on Node.js version >= 10')

console.log(addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10).toString())

assert.deepEqual(
// new Date(2014, 8, 7) is the DST day
addBusinessDays(new Date(2014, 8 /* Sep */, 1), 10).toString(),
'Mon Sep 15 2014 00:00:00 GMT-0300 (Chile Summer Time)'
)

0 comments on commit 03bbf4d

Please sign in to comment.