From 23be023170a3a78e2e3261654b499b858e9547df Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 5 Aug 2024 16:34:11 +0800 Subject: [PATCH 1/2] fix(abc:st): correct default value of `date` type --- packages/abc/st/st-data-source.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/abc/st/st-data-source.ts b/packages/abc/st/st-data-source.ts index e3fb81ad4..751c27175 100644 --- a/packages/abc/st/st-data-source.ts +++ b/packages/abc/st/st-data-source.ts @@ -239,7 +239,7 @@ export class STDataSource { text = this.currencySrv.format(value, col.currency?.format); break; case 'date': - text = value === col.default ? col.default : this.datePipe.transform(value, col.dateFormat); + text = value == null || value === col.default ? col.default : this.datePipe.transform(value, col.dateFormat); break; case 'yn': text = this.ynPipe.transform(value === col.yn!.truth, col.yn!.yes!, col.yn!.no!, col.yn!.mode!, false); From e1c133145aba42e63a6de8f646da16f0604dfddd Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 5 Aug 2024 16:54:23 +0800 Subject: [PATCH 2/2] chore: add test --- packages/abc/st/st-data-source.ts | 5 ++++- packages/abc/st/test/st-data-source.spec.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/abc/st/st-data-source.ts b/packages/abc/st/st-data-source.ts index 751c27175..196cd9b6e 100644 --- a/packages/abc/st/st-data-source.ts +++ b/packages/abc/st/st-data-source.ts @@ -239,7 +239,10 @@ export class STDataSource { text = this.currencySrv.format(value, col.currency?.format); break; case 'date': - text = value == null || value === col.default ? col.default : this.datePipe.transform(value, col.dateFormat); + text = + value == null || value === col.default || (typeof value === 'number' && value <= 0) + ? col.default + : this.datePipe.transform(value, col.dateFormat); break; case 'yn': text = this.ynPipe.transform(value === col.yn!.truth, col.yn!.yes!, col.yn!.no!, col.yn!.mode!, false); diff --git a/packages/abc/st/test/st-data-source.spec.ts b/packages/abc/st/test/st-data-source.spec.ts index 3eb926652..ecc15aea7 100644 --- a/packages/abc/st/test/st-data-source.spec.ts +++ b/packages/abc/st/test/st-data-source.spec.ts @@ -791,6 +791,14 @@ describe('abc: table: data-souce', () => { done(); }); }); + it('should be return default value when is 0 timestamp', done => { + options.columns[0] = { index: 'date', type: 'date', default: '-' } as _STColumn; + options.data = [{ date: 0 }, { date: new Date() }]; + srv.process(options).subscribe(res => { + expect(res.list[0]._values[0].text).toBe('-'); + done(); + }); + }); }); it('via yn', done => { options.columns[0].type = 'yn';