Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Bugfix/fix date conversion of two digit year (#1529)
Thomas Kaul16118d635c25
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex da0c08822f..a845c22d06 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Removed the data source type `RAKUTEN`+### Fixed++- Fixed the date conversion for years with only two digits+## 1.220.0 - 2022-12-23### Addeddiff --git a/apps/client/src/app/adapter/custom-date-adapter.ts b/apps/client/src/app/adapter/custom-date-adapter.tsindex af57c567a3..663c91b720 100644--- a/apps/client/src/app/adapter/custom-date-adapter.ts+++ b/apps/client/src/app/adapter/custom-date-adapter.ts@@ -2,7 +2,7 @@ import { Platform } from '@angular/cdk/platform';import { Inject, forwardRef } from '@angular/core';import { MAT_DATE_LOCALE, NativeDateAdapter } from '@angular/material/core';import { getDateFormatString } from '@ghostfolio/common/helper';-import { format, parse } from 'date-fns';+import { addYears, format, getYear, parse } from 'date-fns';export class CustomDateAdapter extends NativeDateAdapter {public constructor(@@ -31,6 +31,16 @@ export class CustomDateAdapter extends NativeDateAdapter {* Parses a date from a provided value*/public parse(aValue: string): Date {- return parse(aValue, getDateFormatString(this.locale), new Date());+ let date = parse(aValue, getDateFormatString(this.locale), new Date());++ if (getYear(date) < 1900) {+ if (getYear(date) > Number(format(new Date(), 'yy')) + 1) {+ date = addYears(date, 1900);+ } else {+ date = addYears(date, 2000);+ }+ }++ return date;}}