From e7b21110d080fbf6163793721d65a674fbef19dc Mon Sep 17 00:00:00 2001 From: erdemcaygor Date: Wed, 9 Apr 2025 12:16:57 +0300 Subject: [PATCH] refactoring --- .../core/src/lib/pipes/utc-to-local.pipe.ts | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/pipes/utc-to-local.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/utc-to-local.pipe.ts index 3c878cef22..aaa26eb873 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/utc-to-local.pipe.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/utc-to-local.pipe.ts @@ -1,5 +1,5 @@ import { Pipe, PipeTransform, Injectable, inject } from '@angular/core'; -import { LocalizationService, TimezoneService } from '../services'; +import { ConfigStateService, LocalizationService, TimezoneService } from '../services'; @Injectable() @Pipe({ @@ -7,13 +7,10 @@ import { LocalizationService, TimezoneService } from '../services'; }) export class UtcToLocalPipe implements PipeTransform { protected readonly timezoneService = inject(TimezoneService); + protected readonly configState = inject(ConfigStateService); protected readonly localizationService = inject(LocalizationService); - transform( - value: string | Date | null | undefined, - apply: boolean, - options?: Intl.DateTimeFormatOptions, - ): string | Date { + transform(value: string | Date | null | undefined, apply: boolean): string | Date { if (!apply) return value; if (!value) return ''; @@ -24,21 +21,10 @@ export class UtcToLocalPipe implements PipeTransform { // Invalid date return ''; } - - const formatOptions: Intl.DateTimeFormatOptions = options || { - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit', - }; - console.log(this.timezoneService.getTimezone()); - const formatter = new Intl.DateTimeFormat('en-US', { - ...formatOptions, + const localization = this.configState.getOne('localization'); + return dateInput.toLocaleString(localization?.currentCulture?.cultureName ?? 'en-US', { timeZone: this.timezoneService.getTimezone(), }); - - return formatter.format(dateInput); } catch (err) { return value; }