File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 11import getUserLocale from 'get-user-locale' ;
22
3+ const formatterCache = new Map ( ) ;
4+
35export function getFormatter ( options ) {
4- return ( locale , date ) => date . toLocaleString ( locale || getUserLocale ( ) , options ) ;
6+ return ( locale , date ) => {
7+ const localeWithDefault = locale || getUserLocale ( ) ;
8+
9+ if ( ! formatterCache . has ( localeWithDefault ) ) {
10+ formatterCache . set ( localeWithDefault , new Map ( ) ) ;
11+ }
12+
13+ const formatterCacheLocale = formatterCache . get ( localeWithDefault ) ;
14+
15+ if ( ! formatterCacheLocale . has ( options ) ) {
16+ formatterCacheLocale . set (
17+ options ,
18+ new Intl . DateTimeFormat ( localeWithDefault , options ) . format ,
19+ ) ;
20+ }
21+
22+ return formatterCacheLocale . get ( options ) ( date ) ;
23+ } ;
524}
625
726const formatDateOptions = { day : 'numeric' , month : 'numeric' , year : 'numeric' } ;
You can’t perform that action at this time.
0 commit comments