Skip to content

Commit

Permalink
Merge pull request #2330 from XiaoMi/hotfix/#2328
Browse files Browse the repository at this point in the history
fix(date-picker): #2328
  • Loading branch information
solarjoker authored Nov 28, 2022
2 parents 07546fb + a77a6be commit c1500a6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
11 changes: 10 additions & 1 deletion components/date-picker/BasePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ const BasePicker = ({
const inputChangeEvent = (val, dir) => {
if (val.isValid()) {
const oData = _.cloneDeep(outDate)
oData[dir] = val

// 如果是范围的修改,则校准下时间范围的值
if (outDate.length === 2) {
if ((dir === 0 && moment(val) < moment(outDate[1])) || (dir === 1 && moment(val) > moment(outDate[0]))) {
oData[dir] = val
}
} else {
oData[dir] = val
}

changeOutDate(oData)
}
}
Expand Down
59 changes: 42 additions & 17 deletions components/date-picker/components/Time.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,51 @@ const Time = ({ date, onChange, timeRangePanelType, startDate, currentDate }) =>
if (timeRangePanelType === 'right') {
const { hour, minute, second } = deconstructDate(startDate)
const { hour: endHour, minute: endMinute } = date ? deconstructDate(date) : deconstructDate(new Date())
const dateDiff = moment(date).diff(moment(startDate), 'days')
const hourDiff = moment(date).diff(moment(startDate), 'hour')
const minuteDiff = moment(date).diff(moment(startDate), 'minutes')

isDisabled = type === 'hour' && hour > i
if (type === 'minute') {
if (endHour === hour) {
isDisabled = minute > i
}
if (endHour < hour) {
isDisabled = true
}
// 不在同一天
if (dateDiff !== 0) {
isDisabled = dateDiff < 0
}

if (type === 'second') {
if (endHour === hour) {
isDisabled = endMinute === minute && second > i
if (endMinute < minute) {
isDisabled = true
// 在同一天,则比较小时
else {
if (type === 'hour') {
isDisabled = hour > i
} else {
// 不在同一小时
if (hourDiff !== 0) {
isDisabled = hourDiff < 0
}
// 在同一小时,则比较分钟
else {
if (type === 'minute') {
if (endHour === hour) {
isDisabled = minute > i
}
if (endHour < hour) {
isDisabled = true
}
} else {
// 不在同一分
if (minuteDiff !== 0) {
isDisabled = minuteDiff < 0
}
// 在同一分钟,则比较秒
else {
if (endHour === hour) {
isDisabled = endMinute === minute && second > i
if (endMinute < minute) {
isDisabled = true
}
}
if (endHour < hour) {
isDisabled = true
}
}
}
}
}
if (endHour < hour) {
isDisabled = true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hi-ui/hiui",
"version": "3.9.4-beta.0",
"version": "3.9.4",
"description": "HIUI for React",
"scripts": {
"test": "node_modules/.bin/standard && node_modules/.bin/stylelint --config .stylelintrc 'components/**/*.scss'",
Expand Down Expand Up @@ -48,6 +48,9 @@
"es/lib/*",
"es/_util/*"
],
"engines": {
"node": "~11.0.0"
},
"peerDependencies": {
"react": ">=16.13.0",
"react-dom": ">=16.13.0"
Expand Down

0 comments on commit c1500a6

Please sign in to comment.