Skip to content

Commit

Permalink
Merge pull request #710 from XiaoMi/hotfix/#709
Browse files Browse the repository at this point in the history
fix:#709
  • Loading branch information
solarjoker authored Oct 9, 2019
2 parents ff655a9 + 69504b0 commit e52b023
Show file tree
Hide file tree
Showing 3 changed files with 4,090 additions and 4,114 deletions.
15 changes: 8 additions & 7 deletions components/date-picker/BasePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {formatterDate, FORMATS} from './constants'
import PropTypes from 'prop-types'
import DatePickerType from './Type'

import { dateFormat, isValid, startOfWeek, endOfWeek, toDate, parse } from './dateUtil'
import { dateFormat, isValid, startOfWeek, endOfWeek, parse, compatibleToDate } from './dateUtil'
class BasePicker extends Component {
constructor (props) {
super(props)
Expand Down Expand Up @@ -85,6 +85,7 @@ class BasePicker extends Component {
return word.toLowerCase()
})
}

_parseProps (props) {
let {value, defaultValue, showTime, type, format, localeDatas, weekOffset, timeInterval = 240} = props
format = this.compatibleFormatString(format || FORMATS[type])
Expand All @@ -96,12 +97,12 @@ class BasePicker extends Component {
let rightText = ''
if (_value) {
if (Object.prototype.toString.call(_value) === '[object Object]') {
start = toDate(_value.start) || null
end = toDate(_value.end) || new Date()
start = compatibleToDate(_value.start) || null
end = compatibleToDate(_value.end) || new Date()
} else {
start = toDate(_value)
start = compatibleToDate(_value)
if (type.includes('range')) {
end = toDate(start)
end = compatibleToDate(start)
if (type === 'weekrange') {
start = startOfWeek(start)
end = endOfWeek(end)
Expand All @@ -116,8 +117,8 @@ class BasePicker extends Component {
}
}
date = {
startDate: toDate(start),
endDate: toDate(end)
startDate: compatibleToDate(start),
endDate: compatibleToDate(end)
}
leftText = isValid(date.startDate) ? formatterDate(type, date.startDate, format, showTime, localeDatas, weekOffset) : ''
rightText = isValid(date.endDate) ? formatterDate(type, date.endDate, format, showTime, localeDatas, weekOffset) : ''
Expand Down
10 changes: 8 additions & 2 deletions components/date-picker/dateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ const getStartDate = (dateObj) => {
const getEndDate = (dateObj) => {
return getValidDate(dateObj.endDate)
}

const compatibleToDate = (value) => {
if (typeof value === 'string') {
return parseISO(value)
}
return toDate(value)
}
export {
getDaysInMonth, // 获取当月的天数
subMonths, // 月份减法
Expand Down Expand Up @@ -79,5 +84,6 @@ export {
getEndDate, // 封装 - 获取结果时间
getValidDate, // 获取有效的时间
toDate,
parseISO
parseISO,
compatibleToDate
}
Loading

0 comments on commit e52b023

Please sign in to comment.