Comments (4)
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.
Related antd bug report:
ant-design/ant-design#26045
from picker.
lol and all this time there were already two PRs open:
#115
#126
😞
from picker.
Fixed in #115
from picker.
Related Issues (20)
- 文档是否能加上相关浏览器的兼容性
- Picker with Luxon config raises "Error: Invalid DateTime: unparsable: the input "2023-1-01" can't be parsed as format yyyy-MM-dd"
- RangePicker inputRender prop HOT 1
- Can "format" take effect on the title attribute?
- crash on disabledSeconds is not a function
- Support `onClear`
- Deprecated event.which property HOT 1
- rangepicker不支持受控
- When using date-fns, all locales are imported HOT 2
- Add property to remain position after picking a value
- Jest issue TypeError: generateConfig[fn] is not a function HOT 4
- the parameter of `onChange` is wrong when I click cancel button in `RangePicker` HOT 2
- TypeScript error in SinglePickerPanelProps interface during build process HOT 4
- "version": "4.3.0" ref转发的blur方法需要调用
- onCalendarChange is called with wrong value if only one value set in RangePicker
- Why the locale ko-KR uses dayFormat 'Do' as other locales don't?
- When selecting values in panel with type different than the picker type dates are auto-selected.
- picker3.14.6版本 TS1005
- DatePicker 中的 disabledDate 属性在选择年的时候 有异常
- V4.4.2 版本 TimePicker.RangePicker 样式问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picker.