diff --git a/scripts/test/dst.sh b/scripts/test/dst.sh index 5c756d2bf5..2c8b198168 100755 --- a/scripts/test/dst.sh +++ b/scripts/test/dst.sh @@ -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 diff --git a/src/addBusinessDays/index.js b/src/addBusinessDays/index.js index 1adf49e8b9..55caf3e3e6 100644 --- a/src/addBusinessDays/index.js +++ b/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 @@ -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++ } diff --git a/test/dst/addBusinessDays/basic.js b/test/dst/addBusinessDays/basic.js new file mode 100644 index 0000000000..c55a6860e6 --- /dev/null +++ b/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)' +)