Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
feat: make formatTime and formatNumber handle undefined format (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw authored Mar 4, 2020
1 parent 8b95092 commit 768cfd5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class NumberFormatterRegistry extends RegistryWithDefaultKey<
return formatter;
}

format(formatterId: string, value: number | null | undefined): string {
format(formatterId: string | undefined, value: number | null | undefined): string {
return this.get(formatterId)(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ describe('NumberFormatterRegistry', () => {
expect(registry.format('.2f', 100)).toEqual('100.00');
expect(registry.format(',d', 100)).toEqual('100');
});
it('falls back to the default formatter if the format is undefined', () => {
expect(registry.format(undefined, 1000)).toEqual('1k');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class TimeFormatterRegistry extends RegistryWithDefaultKey<
return formatter;
}

format(format: string, value: Date | null | undefined): string {
format(format: string | undefined, value: Date | null | undefined): string {
return this.get(format)(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ describe('TimeFormatterRegistry', () => {
expect(registry.format(TimeFormats.US_DATE, PREVIEW_TIME)).toEqual('02/14/2017');
expect(registry.format(TimeFormats.TIME, PREVIEW_TIME)).toEqual('11:22:33');
});
it('falls back to the default formatter if the format is undefined', () => {
expect(registry.format(undefined, PREVIEW_TIME)).toEqual('2017-02-14 11:22:33');
});
});
});

0 comments on commit 768cfd5

Please sign in to comment.