diff --git a/packages/zarm/package.json b/packages/zarm/package.json index 37a88acb7..e0e08a3b3 100644 --- a/packages/zarm/package.json +++ b/packages/zarm/package.json @@ -72,6 +72,7 @@ "better-scroll": "2.3.1", "classnames": "2.2.6", "color": "^3.1.3", + "dayjs": "^1.11.3", "hoist-non-react-statics": "^3.3.0", "lodash": "^4.17.15", "normalize.css": "8.0.1", diff --git a/packages/zarm/src/date-picker-view/__tests__/__snapshots__/index.test.tsx.snap b/packages/zarm/src/date-picker-view/__tests__/__snapshots__/index.test.tsx.snap index 010f7929f..b1cb0e536 100644 --- a/packages/zarm/src/date-picker-view/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/zarm/src/date-picker-view/__tests__/__snapshots__/index.test.tsx.snap @@ -195,3 +195,1132 @@ exports[`DatePickerView DatePickerView time 2 1`] = ` `; + +exports[`DatePickerView DatePickerView time 3 1`] = ` + + + + +
+
+ +
+
+
+ 11时 +
+
+ 12时 +
+
+ 13时 +
+
+ 14时 +
+
+ 15时 +
+
+ 16时 +
+
+ 17时 +
+
+ 18时 +
+
+ 19时 +
+
+ 20时 +
+
+ 21时 +
+
+
+
+ +
+
+
+ 0分 +
+
+ 1分 +
+
+ 2分 +
+
+ 3分 +
+
+ 4分 +
+
+ 5分 +
+
+ 6分 +
+
+ 7分 +
+
+ 8分 +
+
+ 9分 +
+
+ 10分 +
+
+ 11分 +
+
+ 12分 +
+
+ 13分 +
+
+ 14分 +
+
+ 15分 +
+
+ 16分 +
+
+ 17分 +
+
+ 18分 +
+
+ 19分 +
+
+ 20分 +
+
+ 21分 +
+
+ 22分 +
+
+ 23分 +
+
+ 24分 +
+
+ 25分 +
+
+ 26分 +
+
+ 27分 +
+
+ 28分 +
+
+ 29分 +
+
+ 30分 +
+
+ 31分 +
+
+ 32分 +
+
+ 33分 +
+
+ 34分 +
+
+ 35分 +
+
+ 36分 +
+
+ 37分 +
+
+ 38分 +
+
+ 39分 +
+
+ 40分 +
+
+ 41分 +
+
+ 42分 +
+
+ 43分 +
+
+ 44分 +
+
+ 45分 +
+
+ 46分 +
+
+ 47分 +
+
+ 48分 +
+
+ 49分 +
+
+ 50分 +
+
+ 51分 +
+
+ 52分 +
+
+ 53分 +
+
+ 54分 +
+
+ 55分 +
+
+ 56分 +
+
+ 57分 +
+
+ 58分 +
+
+ 59分 +
+
+
+
+
+
+
+
+ + + + +`; diff --git a/packages/zarm/src/date-picker-view/__tests__/index.test.tsx b/packages/zarm/src/date-picker-view/__tests__/index.test.tsx index 63fb40492..f1838a29a 100644 --- a/packages/zarm/src/date-picker-view/__tests__/index.test.tsx +++ b/packages/zarm/src/date-picker-view/__tests__/index.test.tsx @@ -27,4 +27,9 @@ describe('DatePickerView', () => { ); expect(toJson(wrapper)).toMatchSnapshot(); }); + + it('DatePickerView time 3', () => { + const wrapper = mount(); + expect(toJson(wrapper)).toMatchSnapshot(); + }); }); diff --git a/packages/zarm/src/date-picker-view/utils/parseState.tsx b/packages/zarm/src/date-picker-view/utils/parseState.tsx index ce3b8ddec..f1e12c46f 100644 --- a/packages/zarm/src/date-picker-view/utils/parseState.tsx +++ b/packages/zarm/src/date-picker-view/utils/parseState.tsx @@ -1,3 +1,4 @@ +import dayjs from 'dayjs'; import BaseDatePickerViewProps, { DateValue } from '../PropsType'; const isExtendDate = (date?: DateValue): Date | '' => { @@ -9,12 +10,18 @@ const isExtendDate = (date?: DateValue): Date | '' => { return ''; } - const isTime = /^\d{2}:\d{2}$/.test(date); + const isTime = /^\d{1,2}:\d{1,2}$/.test(date); + if (isTime) { - return new Date(`${new Date().getFullYear()} ${date}`); + const [hour, minute] = date.split(':'); + const today = new Date(); + today.setHours(+hour); + today.setMinutes(+minute); + + return today; } - return new Date(date.toString().replace(/-/g, '/')); + return new Date(dayjs(date).format()); }; const parseState = (props: BaseDatePickerViewProps) => { diff --git a/packages/zarm/src/date-picker/demo.md b/packages/zarm/src/date-picker/demo.md index f36526be7..557304d42 100644 --- a/packages/zarm/src/date-picker/demo.md +++ b/packages/zarm/src/date-picker/demo.md @@ -260,4 +260,4 @@ ReactDOM.render(, mountNode); | :---------- | :------ | :------- | :--------------------------------------------------------------------------------------------------- | | placeholder | string | '请选择' | 输入提示信息 | | hasArrow | boolean | true | 是否显示箭头 | -| format | string | - | 格式化显示值。例:format="yyyy 年 MM 月 dd 日"
年:`yyyy`, 月:`MM`, 日:`dd`, 时:`hh`, 分:`mm`。 | +| format | string | - | 格式化显示值。例:format="yyyy 年 MM 月 dd 日"
年:`yyyy`, 月:`MM`, 日:`dd`, 时:`HH`, 分:`mm`。 | diff --git a/yarn.lock b/yarn.lock index 8b02bbc96..323b724f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6230,6 +6230,11 @@ dateformat@^3.0.0: resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae" integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q== +dayjs@^1.11.3: + version "1.11.3" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.3.tgz#4754eb694a624057b9ad2224b67b15d552589258" + integrity sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A== + dayjs@^1.8.15: version "1.10.4" resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"