Skip to content

Commit

Permalink
Add diff in days
Browse files Browse the repository at this point in the history
  • Loading branch information
buresmi7 committed Apr 16, 2019
1 parent 80b0b3e commit 0c6e49a
Show file tree
Hide file tree
Showing 3 changed files with 21 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.5",
"version": "1.0.6",
"main": ".dist/index.js",
"types": ".dist/index.d.ts",
"repository": "[email protected]:Travelport-Czech/valid-objects-ts.git",
Expand Down
16 changes: 16 additions & 0 deletions src/validObjects/ValidDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ describe('ValidDate', () => {

expect(JSON.stringify(data)).to.eq('{"date":"2018-12-24"}')
})

it('Diff in days', () => {
const date = new ValidDate('2018-12-24')

const date1 = new ValidDate('2018-12-24')
expect(date.diffInDays(date1)).to.equal(0)

const date2 = new ValidDate('2018-12-23')
expect(date.diffInDays(date2)).to.equal(1)

const date3 = new ValidDate('2018-12-25')
expect(date.diffInDays(date3)).to.equal(-1)

const date4 = new ValidDate('2017-12-24')
expect(date.diffInDays(date4)).to.equal(365)
})
})
4 changes: 4 additions & 0 deletions src/validObjects/ValidDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export class ValidDate {
)
}

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

public readonly formatToSystem = (): string => {
return this.moment().format(formatSystemDate)
}
Expand Down

0 comments on commit 0c6e49a

Please sign in to comment.