Skip to content

Commit

Permalink
fix: add removed toDate method again and mark as deprecated (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
co-sic authored Jul 15, 2024
1 parent d0ff9a2 commit cf487e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/CalendarDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ export class CalendarDate {
return new Date(this.unixTimestampInSeconds * 1000);
}

/**
* @deprecated use toDateUTC instead. This method will be removed in the next major version.
*/
toDate(): Date {
return this.toDateUTC();
}

toDateLocal(): Date {
return new Date(this.year, this.month - 1, this.day);
}
Expand Down
21 changes: 21 additions & 0 deletions test/CalendarDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,27 @@ describe('CalendarDate', () => {
});
});

describe('Test of toDate', () => {
test('The returned date object represents the start of the day of the calendarDate in UTC timezone', () => {
fc.assert(
fc.property(
fc.integer({ min: 200, max: 9900 }),
fc.integer({ min: 1, max: 12 }),
fc.integer({ min: 1, max: 31 }),
(year, month, day) => {
// Arrange
day = ensureValidDay(year, month, day);
const calendarDate = new CalendarDate(year, month, day);
const date = calendarDate.toDate();

// Assert
expect(date.toISOString()).toEqual(`${calendarDate.toString()}T00:00:00.000Z`);
},
),
);
});
});

describe('Test of toDateLocal', () => {
test('The returned date object represents the start of the day in the local timezone', () => {
fc.assert(
Expand Down

0 comments on commit cf487e7

Please sign in to comment.