Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -66,6 +66,14 @@ describe('Localization', () => {
expect(i18nFormatter.formatDate('2025-01-25T14:15:00', 'ex: HH:mm GGG', 'en-US')).toEqual('ex: 14:15 AD');
});

it('should return an empty string when the format is missing', () => {
const value = '2025-01-25T14:15:00';

expect(i18nFormatter.formatDate(value, undefined, 'en-US')).toEqual('');
expect(i18nFormatter.formatDate(value, null, 'en-US')).toEqual('');
expect(i18nFormatter.formatDate(value, '', 'en-US')).toEqual('');
});

it('should return correct date format per locale', () => {
// Defaults to Angular's one because they are registered in tests
expect(i18nFormatter.getLocaleDateTimeFormat('en', false)).toEqual('M/d/yyyy');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export class BaseFormatter {
/**
* Format provided date to reflect locales format. Similar to Angular's formatDate.
*/
public formatDate(value: Date | string | number | null | undefined, format: string, locale: string, timezone?: string): string {
// Mirror Angular's DatePipe, which defaults to 'mediumDate' when no format is supplied.
// A null/empty format would otherwise reach ngFormatDate and throw on `format.length`.
return value != null ? ngFormatDate(value, format || 'mediumDate', locale, timezone) : '';
public formatDate(value: Date | string | number | null | undefined, format: string | null | undefined, locale: string, timezone?: string): string {
return value != null && format ? ngFormatDate(value, format, locale, timezone) : '';
Comment thread
viktorkombov marked this conversation as resolved.
}

/** Format number value based on locale */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class IntlFormatter extends BaseFormatter {
}
}

public override formatDate(value: Date | string | number | null | undefined, format: string, locale: string, timezone?: string): string {
public override formatDate(value: Date | string | number | null | undefined, format: string | null | undefined, locale: string, timezone?: string): string {
if (value === null || value === undefined || value === '') {
return '';
}
Expand Down
Loading