-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing getShortWeekdays and getShortMonths for date-fns #128
Comments
Related antd bug report: |
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 |
Fixed in #115 |
I just switched to date-fns and this is what my antd datepicker looks like:
This is what it looked like before the switch (was using Dayjs):
This is how I generate the picker:
And here's an example of how I render it:
Looks like the config for date-fns that's generated by rc-picker is missing the methods
getShortWeekdays
andgetShortMonths
.I am using date-fns 2.15.0. I tried both rc-picker 1.15.3 and 2.0.5 but both gave the same (broken) results.
The text was updated successfully, but these errors were encountered: