WEB-693: Implement Date and Datetime Global Variables (#3123)
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import { Pipe, PipeTransform, inject, OnDestroy } from '@angular/core';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { Subscription } from 'rxjs';
|
||||
import moment from 'moment';
|
||||
|
||||
@@ -29,6 +30,7 @@ import 'moment/locale/cs'; // Czech
|
||||
export class DateFormatPipe implements PipeTransform, OnDestroy {
|
||||
private settingsService = inject(SettingsService);
|
||||
private translateService = inject(TranslateService);
|
||||
private dateUtils = inject(Dates);
|
||||
private onLangChange: Subscription;
|
||||
|
||||
constructor() {
|
||||
@@ -45,24 +47,12 @@ export class DateFormatPipe implements PipeTransform, OnDestroy {
|
||||
}
|
||||
|
||||
transform(value: any, dateFormat?: string): any {
|
||||
const defaultDateFormat = this.settingsService.dateFormat.replace('dd', 'DD');
|
||||
const defaultDateFormat = this.dateUtils.angularToMomentFormat(this.settingsService.dateFormat);
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Map SettingsService language code to a moment.js locale identifier
|
||||
const langCode = this.settingsService.language.code;
|
||||
let momentLocale: string;
|
||||
|
||||
if (!langCode) {
|
||||
momentLocale = 'en';
|
||||
} else if (langCode.includes('-')) {
|
||||
// Convert codes like 'ne-NE' or 'es-MX' to base language 'ne', 'es'
|
||||
momentLocale = langCode.split('-')[0];
|
||||
} else {
|
||||
momentLocale = langCode;
|
||||
}
|
||||
|
||||
const momentLocale = this.dateUtils.getMomentLocale(this.settingsService.language);
|
||||
moment.locale(momentLocale);
|
||||
|
||||
let dateVal;
|
||||
|
||||
Reference in New Issue
Block a user