Skip to content

Commit

Permalink
fix(antd): improve week type moment parse regex (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzw918 authored and janryWang committed Aug 13, 2019
1 parent b19abe2 commit 88654b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/Examples/antd/International.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ ReactDOM.render(
name="daterange"
/>
<Field type="year" title="年份" name="year" />
<Field type="week" title="" name="week" />
<Field
type="week"
title="周(自定义显示格式)"
name="week1"
style={{ format: 'gggg年 第w周' }}
/>
<Field type="time" title="时间" name="time" />
<Field
type="upload"
Expand Down
6 changes: 6 additions & 0 deletions docs/Examples/antd/Sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ ReactDOM.render(
/>
<Field type="year" title="年份" name="year" />
<Field type="week" title="" name="week" />
<Field
type="week"
title="周(自定义显示格式)"
name="week1"
style={{ format: 'gggg年 第w周' }}
/>
<Field type="time" title="时间" name="time" />
<Field
type="upload"
Expand Down
4 changes: 2 additions & 2 deletions packages/antd/src/fields/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ registerFormField(
mapStyledProps,
props => {
if (isStr(props.value) && props.value) {
const parsed = props.value.match(/(\d+)\s*-\s*(\d+)/) || ['', '', '']
props.value = moment(parsed[1], 'YYYY').add(parsed[2], 'weeks')
const parsed = props.value.match(/\D*(\d+)\D*(\d+)\D*/) || ['', '', '']
props.value = moment(parsed[1], 'YYYY').add(parsed[2] - 1, 'weeks')
}
return props
}
Expand Down

0 comments on commit 88654b8

Please sign in to comment.