Browse Source

refactoring

pull/22619/head
erdemcaygor 1 year ago
parent
commit
8633edb650
  1. 3
      npm/ng-packs/packages/core/src/lib/interceptors/timezone.interceptor.ts
  2. 8
      npm/ng-packs/packages/core/src/lib/services/timezone.service.ts

3
npm/ng-packs/packages/core/src/lib/interceptors/timezone.interceptor.ts

@ -10,6 +10,9 @@ export class TimezoneInterceptor implements HttpInterceptor {
protected readonly timezoneService = inject(TimezoneService); protected readonly timezoneService = inject(TimezoneService);
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!this.timezoneService.isUtcClockEnabled) {
return next.handle(req);
}
const timezone = this.timezoneService.getTimezone(); const timezone = this.timezoneService.getTimezone();
if (timezone) { if (timezone) {
req = req.clone({ req = req.clone({

8
npm/ng-packs/packages/core/src/lib/services/timezone.service.ts

@ -10,11 +10,15 @@ export class TimezoneService {
protected readonly document = inject(DOCUMENT); protected readonly document = inject(DOCUMENT);
private readonly cookieKey = '__timezone'; private readonly cookieKey = '__timezone';
private timeZoneNameFromSettings: string | null | undefined; private timeZoneNameFromSettings: string | null | undefined;
public isUtcClockEnabled: boolean | undefined;
constructor() { constructor() {
this.configState.getOne$('timing').subscribe(timezoneSettings => { this.configState.getOne$('timing').subscribe(timezoneSettings => {
this.timeZoneNameFromSettings = timezoneSettings?.timeZone?.iana?.timeZoneName; this.timeZoneNameFromSettings = timezoneSettings?.timeZone?.iana?.timeZoneName;
}); });
this.configState.getOne$('clock').subscribe(clock => {
this.isUtcClockEnabled = clock?.kind === 'Utc';
});
} }
getBrowserTimezone(): string { getBrowserTimezone(): string {
@ -27,7 +31,9 @@ export class TimezoneService {
} }
setTimezone(timezone: string): void { setTimezone(timezone: string): void {
this.document.cookie = `${this.cookieKey}=${timezone}; path=/`; if (this.isUtcClockEnabled) {
this.document.cookie = `${this.cookieKey}=${timezone}; path=/`;
}
} }
convertUtcToLocal(date: string | Date): Date { convertUtcToLocal(date: string | Date): Date {

Loading…
Cancel
Save