Skip to content

Commit

Permalink
fix(next): fix date time picker value format (#3044)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyeric authored Apr 15, 2022
1 parent 7aba484 commit cee9722
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/next/src/date-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,29 @@ const mapDateFormat = function (type?: 'month' | 'year' | 'week') {
} else if (_type === 'week') {
return 'YYYY-wo'
}
return props['showTime'] ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'
return 'YYYY-MM-DD'
}

return (props: any) => {
const format = props['format'] || getDefaultFormat(props)
const dateFormat = props['format'] || getDefaultFormat(props)

let valueFormat = dateFormat
if (props.showTime) {
const timeFormat = props.showTime.format || 'HH:mm:ss'
valueFormat = `${valueFormat} ${timeFormat}`
}

const onChange = props.onChange
return {
...props,
format,
value: momentable(props.value, format === 'YYYY-wo' ? 'YYYY-w' : format),
format: dateFormat,
value: momentable(
props.value,
valueFormat === 'YYYY-wo' ? 'YYYY-w' : valueFormat
),
onChange: (value: moment.Moment | moment.Moment[]) => {
if (onChange) {
onChange(formatMomentValue(value, format))
onChange(formatMomentValue(value, valueFormat))
}
},
}
Expand Down

0 comments on commit cee9722

Please sign in to comment.