Browse Source

refactoring

pull/22619/head
erdemcaygor 1 year ago
parent
commit
e7b21110d0
  1. 24
      npm/ng-packs/packages/core/src/lib/pipes/utc-to-local.pipe.ts

24
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 { Pipe, PipeTransform, Injectable, inject } from '@angular/core';
import { LocalizationService, TimezoneService } from '../services'; import { ConfigStateService, LocalizationService, TimezoneService } from '../services';
@Injectable() @Injectable()
@Pipe({ @Pipe({
@ -7,13 +7,10 @@ import { LocalizationService, TimezoneService } from '../services';
}) })
export class UtcToLocalPipe implements PipeTransform { export class UtcToLocalPipe implements PipeTransform {
protected readonly timezoneService = inject(TimezoneService); protected readonly timezoneService = inject(TimezoneService);
protected readonly configState = inject(ConfigStateService);
protected readonly localizationService = inject(LocalizationService); protected readonly localizationService = inject(LocalizationService);
transform( transform(value: string | Date | null | undefined, apply: boolean): string | Date {
value: string | Date | null | undefined,
apply: boolean,
options?: Intl.DateTimeFormatOptions,
): string | Date {
if (!apply) return value; if (!apply) return value;
if (!value) return ''; if (!value) return '';
@ -24,21 +21,10 @@ export class UtcToLocalPipe implements PipeTransform {
// Invalid date // Invalid date
return ''; return '';
} }
const localization = this.configState.getOne('localization');
const formatOptions: Intl.DateTimeFormatOptions = options || { return dateInput.toLocaleString(localization?.currentCulture?.cultureName ?? 'en-US', {
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,
timeZone: this.timezoneService.getTimezone(), timeZone: this.timezoneService.getTimezone(),
}); });
return formatter.format(dateInput);
} catch (err) { } catch (err) {
return value; return value;
} }

Loading…
Cancel
Save