Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Pipe, PipeTransform } from '@angular/core';
import { isNil } from 'lodash-es';
import { DateCoercer } from '../../coercers/date-coercer';
import { DateFormatOptions, DateFormatter } from './date-formatter';

@Pipe({
name: 'htDisplayDate'
})
export class DisplayDatePipe implements PipeTransform {
public transform(value?: Date | number | null, options: DateFormatOptions = {}): string {
return value !== null ? new DateFormatter(options).format(value) : '-';
private readonly dateCoercer: DateCoercer = new DateCoercer();
public transform(value?: string | Date | number | null, options: DateFormatOptions = {}): string {
return isNil(value) ? '-' : new DateFormatter(options).format(this.dateCoercer.coerce(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if this.dateCoercer.coerce(value) returns undefined? Should we do this before the calling isNil so that we can assign '-'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the DateFormatter just depend on dateCoercer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DateCoercer } from '@hypertrace/common';
import { TableCellParser } from '../table-cell-parser';
import { TableCellParserBase } from '../table-cell-parser-base';
import { CoreTableCellParserType } from '../types/core-table-cell-parser-type';
Expand All @@ -6,14 +7,15 @@ import { CoreTableCellParserType } from '../types/core-table-cell-parser-type';
type: CoreTableCellParserType.Timestamp
})
export class TableCellTimestampParser extends TableCellParserBase<CellData, Value, Value> {
private readonly dateCoercer: DateCoercer = new DateCoercer();
public parseValue(cellData: CellData): Value {
switch (typeof cellData) {
case 'number':
return cellData;
case 'object':
return cellData instanceof Date ? cellData : cellData.value;
default:
return undefined;
return this.dateCoercer.coerce(cellData);
}
}

Expand Down