Skip to content

Commit

Permalink
Added test for DateTz constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Blackbourn committed Mar 16, 2024
1 parent e46fb69 commit 6c940fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/DateTz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class DateTz {
constructor(value: number, tz?: Timezone)
constructor(dateString: string, tz?: Timezone)
constructor(dateObject: Date, tz?: Timezone)
constructor(year: number, month: number, tz?: Timezone)
constructor(year: number, month: number, day: number, tz?: Timezone)
constructor(
year: number,
Expand Down
28 changes: 25 additions & 3 deletions test/DateTz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,30 @@ describe('DateTz', () => {
})

it('should construct', () => {
const d1 = new DateTz(new Date(), tzUtc)
const d2 = new DateTz(0, tzUtc)
const d3 = new DateTz(1970, 1, 1, tzUtc)
const date = new DateTz(1970, 1, 1, tzLocal)
const time = date.getTime()

const dates = [
new DateTz(new Date(time)),
new DateTz(new Date(time), tzLocal),
new DateTz(time),
new DateTz(time, tzLocal),
new DateTz('1970-01-01T00:00:00'),
new DateTz('1970-01-01T00:00:00', tzLocal),
new DateTz(1970, 1),
new DateTz(1970, 1, tzLocal),
new DateTz(1970, 1, 1),
new DateTz(1970, 1, 1, tzLocal),
new DateTz(1970, 1, 1, 0),
new DateTz(1970, 1, 1, 0, tzLocal),
new DateTz(1970, 1, 1, 0, 0),
new DateTz(1970, 1, 1, 0, 0, tzLocal),
new DateTz(1970, 1, 1, 0, 0, 0),
new DateTz(1970, 1, 1, 0, 0, 0, tzLocal),
new DateTz(1970, 1, 1, 0, 0, 0, 0),
new DateTz(1970, 1, 1, 0, 0, 0, 0, tzLocal)
]

dates.forEach(actual => expect(actual.getTime()).toBe(date.getTime()))
})
})

0 comments on commit 6c940fe

Please sign in to comment.