Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
refactor(date-adapter): Add more information to thrown error
Browse files Browse the repository at this point in the history
Signed-off-by: Bartosz Bobin <bartosz.bobin@dynatrace.com>
  • Loading branch information
bartoszbobin authored and tomheller committed Aug 29, 2023
1 parent ad0aff9 commit b9c3d13
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libs/barista-components/core/src/date/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export class DtNativeDateAdapter implements DtDateAdapter<Date> {
const result = createDateWithOverflow(year, month, date);

if (result.getMonth() !== month) {
throw Error(`Invalid date "${date}" for month with index "${month}".`);
throw Error(
`Invalid date "${result.toString()}" for given params y:${year}, m:${month}, d:${date}, received y:${result.getFullYear()}, m:${result.getMonth()}, d:${result.getDate()}, h:${result.getHours()}, i:${result.getMinutes()}`,
);
}

return result;
Expand Down Expand Up @@ -290,7 +292,7 @@ function formatDate(dateFormat: Intl.DateTimeFormat, date: Date): string {
}

/** Creates a date but allows the month and date to overflow. */
function createDateWithOverflow(
export function createDateWithOverflow(
year: number,
month: number,
date: number,
Expand All @@ -300,7 +302,7 @@ function createDateWithOverflow(
// We need to correct for the fact that JS native Date treats years in range [0, 99] as
// abbreviations for 19xx.
if (year >= 0 && year < 100) {
result.setFullYear(this.getYear(result) - 1900);
result.setFullYear(result.getFullYear() - 1900);
}
return result;
}
Expand Down

0 comments on commit b9c3d13

Please sign in to comment.