mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 20:20:00 +08:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import objectAssign from 'object-assign';
|
|
import defaultLocale from './locale/zh_CN';
|
|
import DateTimeFormat from 'gregorian-calendar-format';
|
|
import GregorianCalendar from 'gregorian-calendar';
|
|
|
|
export default {
|
|
getLocale() {
|
|
// 统一合并为完整的 Locale
|
|
let locale = objectAssign({}, defaultLocale, this.props.locale);
|
|
locale.lang = objectAssign({}, defaultLocale.lang, this.props.locale.lang);
|
|
return locale;
|
|
},
|
|
|
|
getFormatter() {
|
|
const formats = this.formats = this.formats || {};
|
|
let format = this.props.format;
|
|
// Remove time format text when has time-picker in calendar
|
|
if (this.props.showTime) {
|
|
format = format.replace('HH:mm:ss', '');
|
|
}
|
|
if (formats[format]) {
|
|
return formats[format];
|
|
}
|
|
formats[format] = new DateTimeFormat(format, this.getLocale().lang.format);
|
|
return formats[format];
|
|
},
|
|
|
|
parseDateFromValue(value) {
|
|
if (value) {
|
|
if (typeof value === 'string') {
|
|
return this.getFormatter().parse(value, { locale: this.getLocale() });
|
|
} else if (value instanceof Date) {
|
|
let date = new GregorianCalendar(this.getLocale());
|
|
date.setTime(+value);
|
|
return date;
|
|
}
|
|
}
|
|
return value;
|
|
},
|
|
|
|
// remove input readonly warning
|
|
handleInputChange() {
|
|
},
|
|
toggleOpen(e) {
|
|
this.setState({
|
|
open: e.open
|
|
});
|
|
},
|
|
};
|