Git Product home page Git Product logo

Comments (4)

fgblomqvist avatar fgblomqvist commented on July 21, 2024 1

This is the solution I went with:

import generatePicker from 'antd/es/date-picker/generatePicker';
import { enUS } from 'date-fns/locale';
import dateFnsGenerateConfig from 'rc-picker/lib/generate/dateFns';

const locales: Record<string, Locale> = { en_US: enUS };

const originFormat = dateFnsGenerateConfig.locale.format;
Object.assign(dateFnsGenerateConfig.locale, {
  format: (local: string, date: Date, format: string) => {
    if (/\[.+]/.test(format)) {
      const f = format.replace(/[[\]]/g, "'");
      return originFormat(local, date, f);
    }
    return originFormat(local, date, format);
  },

  getShortMonths: (locale: string) => {
    const loc = locales[locale];
    if (!loc || !loc.localize) return [];

    return Array.from(Array(12).keys()).map(i =>
      loc.localize!.month(i, { width: 'abbreviated' }),
    );
  },

  getShortWeekDays: (locale: string) => {
    const loc = locales[locale];
    if (!loc || !loc.localize) return [];

    return Array.from(Array(7).keys()).map(i =>
      loc.localize!.day(i, { width: 'short' }),
    );
  },
});

export default generatePicker<Date>(dateFnsGenerateConfig);

It replicates the Dayjs behavior. That code should be good enough to add to rc-picker I think. The way it would be incorporated is that generatePicker would take a second argument, a map from ISO639-1_ISO3166 (e.g. en_US) to a locale. Any locale you want to support in your app, you will need to import and add to that map (this is to optimize bundle size). Let me know if you'd accept a PR with this.

from picker.

fgblomqvist avatar fgblomqvist commented on July 21, 2024

Related antd bug report:
ant-design/ant-design#26045

from picker.

fgblomqvist avatar fgblomqvist commented on July 21, 2024

lol and all this time there were already two PRs open:
#115
#126
😞

from picker.

afc163 avatar afc163 commented on July 21, 2024

Fixed in #115

from picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.