ant-design/components/date-picker/PickerMixin.jsx

47 lines
1.2 KiB
React
Raw Normal View History

2015-12-11 11:11:24 +08:00
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;
2015-12-11 11:11:24 +08:00
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') {
2016-01-05 14:42:06 +08:00
return this.getFormatter().parse(value, { locale: this.getLocale() });
2015-12-11 11:11:24 +08:00
} else if (value instanceof Date) {
let date = new GregorianCalendar(this.getLocale());
2015-12-28 11:43:43 +08:00
date.setTime(+value);
2015-12-11 11:11:24 +08:00
return date;
}
}
2016-01-14 19:15:21 +08:00
return value;
2015-12-11 11:11:24 +08:00
},
// remove input readonly warning
handleInputChange() {
},
2016-02-18 17:50:29 +08:00
2015-12-11 11:11:24 +08:00
toggleOpen(e) {
this.setState({
open: e.open
});
},
};