Skip to content

Commit

Permalink
feat(i18n): date method for convert date to active locale
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and alimd committed May 1, 2023
1 parent 51ac0b0 commit 8b51a97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/i18n/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,11 @@ export const replaceNumber = (str: string): string => {
if (activeUnicodeDigits === null) return str;
return activeUnicodeDigits.translate(str);
};

/**
* Format date to active locale string.
*/
export const date = (date: number | Date): string => {
if (activeLocaleContext === null) return loadingStr;
return new Intl.DateTimeFormat(activeLocaleContext.code).format(date);
};
1 change: 1 addition & 0 deletions core/i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
setL18eLoader,
message,
number,
date,
replaceNumber,
localeContextConsumer,
l18eContextConsumer,
Expand Down

0 comments on commit 8b51a97

Please sign in to comment.