WEB-185 Made on date and checked on date should show full datetime with timezone information or explicitly convert the epoch time to UTC!

This commit is contained in:
JaySoni1
2025-10-23 09:29:56 +05:30
parent f7633655b2
commit 94e929abf4
6 changed files with 196 additions and 68 deletions
+25 -18
View File
@@ -1,25 +1,32 @@
import { Pipe, PipeTransform } from '@angular/core';
import { SettingsService } from 'app/settings/settings.service';
import moment from 'moment';
import moment, { Moment } from 'moment';
@Pipe({ name: 'datetimeFormat' })
@Pipe({ name: 'datetimeFormat', standalone: true })
export class DatetimeFormatPipe implements PipeTransform {
constructor(private settingsService: SettingsService) {}
transform(value: any, datetimeFormat?: string): any {
const defaultDateFormat = this.settingsService.dateFormat.replace('dd', 'DD');
if (typeof value === 'undefined') {
return '';
}
let dateVal;
if (value instanceof Array) {
dateVal = moment(value.join('-'), 'YYYY-MM-DD HH:mm:ss');
transform(value: unknown, datetimeFormat?: string): string {
if (value == null || value === '') return '';
let dateVal: Moment;
if (Array.isArray(value)) {
const [
y,
m,
d,
hh,
mm,
ss
] = value as number[];
if (hh != null) {
dateVal = moment({ year: y, month: (m ?? 1) - 1, date: d, hour: hh, minute: mm ?? 0, second: ss ?? 0 });
} else {
dateVal = moment({ year: y, month: (m ?? 1) - 1, date: d });
}
} else if (typeof value === 'number' && value < 1e12) {
// epoch seconds
dateVal = moment.unix(value);
} else {
dateVal = moment(value);
dateVal = moment(value as any);
}
if (datetimeFormat == null) {
return dateVal.format(defaultDateFormat + ' HH:mm:ss');
}
return dateVal.format(datetimeFormat);
const fmt = datetimeFormat ?? 'YYYY-MM-DDTHH:mm:ssZ';
return dateVal.format(fmt);
}
}