generateConfig for date-fns throws error for some locales
See original GitHub issueThe generateConfig
methods use dealLocal()
function to get date-fns
specific locale data for the provided language, but the implementation fails in some cases because rc-picker
locales names do not exactly match with date-fns
ones.
For example Italian:
rc-picker
useit_IT
as locale name;dealLocal()
converts it intoitIT
;generateConfig.getWeekFirstDay()
method tries to loaddate-fns
locale data with anitIT
key, but it does not exists and this leads toclone
constant to beundefined
.
The only solution is to replace the current dealLocal()
implementation with a static map of locales names and prevent errors with a default value:
const DEFAULT_LOCALE = 'enUS';
const LOCALES_MAP = {
'en_US': 'enUS',
'it_IT': 'it',
'es_ES': 'es',
// and so on...
}
const dealLocal = (str: string): string => LOCALES_MAP[str] || DEFAULT_LOCALE;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Failing to "dynamically" import date-fns/locale libs
Here's the code I am using for doing dynamic lookups using Expo's Localization object. import * as Localization from 'expo-localization'; ...
Read more >How to use the date-fns.isValid function in date-fns - Snyk
To help you get started, we've selected a few date-fns. ... what to return if not valid? throw new Error(`Please use format MM${separator}yyyy`);...
Read more >datefns locale string incompatibility with antd #26699 - Issuehunt
Resolution is to correctly map supported locales, which works for some languages using the current function but not for all as is the...
Read more >the date-fns Docs
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >date-fns | Yarn - Package Manager
date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same problem with ru_RU locale
@zombieJ are there any issues regarding spawnia’s PR?