diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f96f7878..2ff7f6342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Supported enter key press to submit the form of the create or edit transaction dialog +### Fixed + +- Fixed the date format of the date picker and support manual changes +- Fixed the state of the account delete button (disable if account contains activities) +- Fixed an issue in the activities filter component (typing a search term) + ## 1.147.0 - 10.05.2022 ### Changed diff --git a/apps/client/src/app/adapter/custom-date-adapter.ts b/apps/client/src/app/adapter/custom-date-adapter.ts index 5c5be28f9..74bf7dd7a 100644 --- a/apps/client/src/app/adapter/custom-date-adapter.ts +++ b/apps/client/src/app/adapter/custom-date-adapter.ts @@ -1,14 +1,15 @@ import { Platform } from '@angular/cdk/platform'; import { Inject, forwardRef } from '@angular/core'; import { MAT_DATE_LOCALE, NativeDateAdapter } from '@angular/material/core'; -import { format, isValid } from 'date-fns'; -import * as deDateFnsLocale from 'date-fns/locale/de/index'; +import { getDateFormatString } from '@ghostfolio/common/helper'; +import { format, parse } from 'date-fns'; export class CustomDateAdapter extends NativeDateAdapter { /** * @constructor */ public constructor( + @Inject(MAT_DATE_LOCALE) public locale: string, @Inject(forwardRef(() => MAT_DATE_LOCALE)) matDateLocale: string, platform: Platform ) { @@ -16,50 +17,23 @@ export class CustomDateAdapter extends NativeDateAdapter { } /** - * Sets the first day of the week to Monday + * Formats a date as a string */ - public getFirstDayOfWeek(): number { - return 1; + public format(aDate: Date, aParseFormat: string): string { + return format(aDate, getDateFormatString(this.locale)); } /** - * Formats a date as a string according to the given format + * Sets the first day of the week to Monday */ - public format(aDate: Date, aParseFormat: string): string { - return format(aDate, aParseFormat, { - locale: deDateFnsLocale - }); + public getFirstDayOfWeek(): number { + return 1; } /** * Parses a date from a provided value */ - public parse(aValue: any): Date { - let date: Date; - - try { - // TODO - // Native date parser from the following formats: - // - 'd.M.yyyy' - // - 'dd.MM.yyyy' - // https://github.com/you-dont-need/You-Dont-Need-Momentjs#string--date-format - const datePattern = /^(\d{1,2}).(\d{1,2}).(\d{4})$/; - const [, day, month, year] = datePattern.exec(aValue); - - date = new Date( - parseInt(year, 10), - parseInt(month, 10) - 1, // monthIndex - parseInt(day, 10) - ); - } catch (error) { - } finally { - const isDateValid = date && isValid(date); - - if (isDateValid) { - return date; - } - - return null; - } + public parse(aValue: string): Date { + return parse(aValue, getDateFormatString(this.locale), new Date()); } } diff --git a/apps/client/src/app/components/accounts-table/accounts-table.component.html b/apps/client/src/app/components/accounts-table/accounts-table.component.html index cf8446e42..08c6c3de9 100644 --- a/apps/client/src/app/components/accounts-table/accounts-table.component.html +++ b/apps/client/src/app/components/accounts-table/accounts-table.component.html @@ -200,7 +200,7 @@