Skip to content

Commit

Permalink
fix(bs-moment): fix postformat for empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Nov 22, 2017
1 parent 7ec97f8 commit d3bb3fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bs-moment/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function formatDate(date: Date, format: string, locale = 'en'): string {
}
const output = formatMoment(date, format, _locale);

if (!output) {
return output;
}

return _locale.postformat(output);

This comment has been minimized.

Copy link
@FrancescoBorzi

FrancescoBorzi Nov 23, 2017

Member

lines 23-27 can be made more compact:

return output ? _locale.postformat(output) : output;

This comment has been minimized.

Copy link
@valorkin

valorkin Nov 23, 2017

Author Member

they have +- same perf, so it's just a matter of style, of personal preference
https://jsperf.com/if-return-vs-ternary/1

}

Expand Down
4 changes: 4 additions & 0 deletions src/bs-moment/i18n/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export const ar: LocaleData = {
.replace(/،/g, ',');
},
postformat(str: string): string {
if (!str) {
return str;
}

return str
.replace(/\d/g, function(match) {
return symbolMap[match];
Expand Down
4 changes: 4 additions & 0 deletions src/bs-moment/i18n/hi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export const hi: LocaleData = {
});
},
postformat(str: string): string {
if (!str) {
return str;
}

return str.replace(/\d/g, function (match) {
return symbolMap[match];
});
Expand Down

0 comments on commit d3bb3fd

Please sign in to comment.