Skip to content

Commit

Permalink
Add method addDays to ValidDate
Browse files Browse the repository at this point in the history
  • Loading branch information
buresmi7 committed Apr 16, 2019
1 parent 0c6e49a commit 7d13c8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "valid-objects-ts",
"version": "1.0.6",
"version": "1.0.7",
"main": ".dist/index.js",
"types": ".dist/index.d.ts",
"repository": "[email protected]:Travelport-Czech/valid-objects-ts.git",
Expand Down
14 changes: 14 additions & 0 deletions src/validObjects/ValidDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ describe('ValidDate', () => {
const date4 = new ValidDate('2017-12-24')
expect(date.diffInDays(date4)).to.equal(365)
})

it('subtract days', () => {
const date = new ValidDate('2018-12-24')
expect(date.subtractDays(0).toString()).to.equal('2018-12-24')
expect(date.subtractDays(1).toString()).to.equal('2018-12-23')
expect(date.subtractDays(100).toString()).to.equal('2018-09-15')
})

it('add days', () => {
const date = new ValidDate('2018-12-24')
expect(date.addDays(0).toString()).to.equal('2018-12-24')
expect(date.addDays(1).toString()).to.equal('2018-12-25')
expect(date.addDays(100).toString()).to.equal('2019-04-03')
})
})
8 changes: 8 additions & 0 deletions src/validObjects/ValidDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export class ValidDate {
)
}

public readonly addDays = (days: number): ValidDate => {
return new ValidDate(
this.moment()
.add(days, 'days')
.format(formatSystemDate)
)
}

public readonly diffInDays = (date: ValidDate): number => {
return this.moment().diff(date.moment(), 'days')
}
Expand Down

0 comments on commit 7d13c8d

Please sign in to comment.