import {OrgService} from '@eg/core/org.service';
import {LocaleService} from '@eg/core/locale.service';
import * as moment from 'moment-timezone';
+import {DateUtil} from '@eg/share/util/date';
/**
* Format IDL vield values for display.
orgField?: string; // 'shortname' || 'name'
datePlusTime?: boolean;
timezoneContextOrg?: number;
+ dateOnlyInterval?: string;
}
@Injectable({providedIn: 'root'})
console.error('Invalid date in format service', value);
return '';
}
+
let fmt = this.dateFormat || 'shortDate';
+
if (params.datePlusTime) {
+ // Time component directly requested
fmt = this.dateTimeFormat || 'short';
+
+ } else if (params.dateOnlyInterval) {
+ // Time component displays for non-day-granular intervals.
+ const secs = DateUtil.intervalToSeconds(params.dateOnlyInterval);
+ if (secs !== null && secs % 86400 !== 0) {
+ fmt = this.dateTimeFormat || 'short';
+ }
}
+
return this.datePipe.transform(date.toISOString(true), fmt, date.format('ZZ'));
case 'money':
// Display using a specific OU's timestamp when datatype = timestamp
@Input() timezoneContextOrg: number;
+ @Input() dateOnlyIntervalField: string;
+
// Used in conjunction with cellTemplate
@Input() cellContext: any;
@Input() cellTemplate: TemplateRef<any>;
col.datePlusTime = this.datePlusTime;
col.ternaryBool = this.ternaryBool;
col.timezoneContextOrg = this.timezoneContextOrg;
+ col.dateOnlyIntervalField = this.dateOnlyIntervalField;
col.idlClass = this.idlClass;
col.isAuto = false;
ternaryBool: boolean;
timezoneContextOrg: number;
cellTemplate: TemplateRef<any>;
+ dateOnlyIntervalField: string;
cellContext: any;
isIndex: boolean;
col.datePlusTime = this.datePlusTime;
col.ternaryBool = this.ternaryBool;
col.timezoneContextOrg = this.timezoneContextOrg;
+ col.dateOnlyIntervalField = this.dateOnlyIntervalField;
col.idlClass = this.idlClass;
col.isAuto = this.isAuto;
return val;
}
+ // Get the value of
+ let interval;
+ const intField = col.dateOnlyIntervalField;
+ if (intField) {
+ if (intField in row) {
+ interval = this.getObjectFieldValue(row, intField);
+ } else {
+ // find the referenced column
+ const intCol = this.columnSet.columns.filter(c => c.path === intField)[0];
+ if (intCol) {
+ interval = this.nestedItemFieldValue(row, intCol);
+ }
+ }
+ }
+
return this.format.transform({
value: val,
idlClass: col.idlClass,
idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
datatype: col.datatype,
datePlusTime: Boolean(col.datePlusTime),
- timezoneContextOrg: Number(col.timezoneContextOrg)
+ timezoneContextOrg: Number(col.timezoneContextOrg),
+ dateOnlyInterval: interval
});
}