# All files / react/I18n format.jsx

12.5% Statements 1/8
0% Branches 0/5
0% Functions 0/2
14.29% Lines 1/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17

    2x

     import format from 'date-fns/format'
    import { DEFAULT_LANG } from '.'

    export const initFormat = (lang, defaultLang = DEFAULT_LANG) => {
      const locales = {
        [defaultLang]: require(`date-fns/locale/${defaultLang}/index`)
      }
      if (lang && lang !== defaultLang) {
        try {
          locales[lang] = require(`date-fns/locale/${lang}/index`)
        } catch (e) {
          console.warn(`The "${lang}" locale isn't supported by date-fns`)
        }
      }
      return (date, formatStr) => format(date, formatStr, { locale: locales[lang] })
    }