question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

generateConfig for date-fns throws error for some locales

See original GitHub issue

The 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 use it_IT as locale name;
  • dealLocal() converts it into itIT;
  • generateConfig.getWeekFirstDay() method tries to load date-fns locale data with an itIT key, but it does not exists and this leads to clone constant to be undefined.

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:open
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
stepanzincommented, Sep 25, 2020

Same problem with ru_RU locale

0reactions
Saarnakicommented, Dec 29, 2021

@zombieJ are there any issues regarding spawnia’s PR?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found