From 0516d5950e3e16c5ad84f18ef7a143f6d02c9bf1 Mon Sep 17 00:00:00 2001 From: mdlufy Date: Tue, 12 Nov 2024 11:16:33 +0300 Subject: [PATCH] fix(cdk): `toLocalNativeDate` correct work with years less 1900 --- projects/cdk/date-time/date-time.ts | 2 +- projects/cdk/date-time/day.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/cdk/date-time/date-time.ts b/projects/cdk/date-time/date-time.ts index cb9ee143f11d..c9a5e85cc5ee 100644 --- a/projects/cdk/date-time/date-time.ts +++ b/projects/cdk/date-time/date-time.ts @@ -14,7 +14,7 @@ export const MIN_MONTH = 0; export const MAX_MONTH = 11; -export const MIN_YEAR = 100; +export const MIN_YEAR = 0; export const MAX_YEAR = 9999; diff --git a/projects/cdk/date-time/day.ts b/projects/cdk/date-time/day.ts index 833c1ea5d86c..8f8271e98062 100644 --- a/projects/cdk/date-time/day.ts +++ b/projects/cdk/date-time/day.ts @@ -377,7 +377,12 @@ export class TuiDay extends TuiMonth { * Returns native {@link Date} based on local time zone */ override toLocalNativeDate(): Date { - return new Date(this.year, this.month, this.day); + const date = new Date(this.year, this.month, this.day); + + // needed for years less than 1900 + date.setFullYear(Number(this.year ?? '0')); + + return date; } /**