diff --git a/src/index.js b/src/index.js index 8c8841a81..347c08de2 100644 --- a/src/index.js +++ b/src/index.js @@ -243,7 +243,7 @@ class Dayjs { const unit = Utils.p(units) const instanceFactorySet = (n) => { const date = new Date(this.$d) - date.setDate(date.getDate() + (n * number)) + date.setDate(date.getDate() + Math.round(n * number)) return Utils.w(date, this) } if (unit === C.M) { diff --git a/test/manipulate.test.js b/test/manipulate.test.js index eb83f5d92..5fe28cb4f 100644 --- a/test/manipulate.test.js +++ b/test/manipulate.test.js @@ -64,6 +64,13 @@ it('Add Time days', () => { expect(dayjs().add('2', 'years').valueOf()).toBe(moment().add('2', 'years').valueOf()) }) +it('Add Time with decimal', () => { + expect(dayjs().add(0.4, 'day').valueOf()).toBe(moment().add(0.4, 'day').valueOf()) + expect(dayjs().add(0.5, 'day').valueOf()).toBe(moment().add(0.5, 'day').valueOf()) + expect(dayjs().add(0.4, 'week').valueOf()).toBe(moment().add(0.4, 'week').valueOf()) + expect(dayjs().add(0.5, 'week').valueOf()).toBe(moment().add(0.5, 'week').valueOf()) +}) + it('Subtract Time days', () => { expect(dayjs().subtract(1, 'days').valueOf()).toBe(moment().subtract(1, 'days').valueOf()) })